My current setup is a m1 MacBook Air.
I am reading a low level programming book.
I want the the C code that I write to compile to x86_64 assembly.
With clang I can do that pretty easily:
clang -target x86_64 -masm=intel -S add_two_numbers.c
But it does not work when I include a library (eg. stdio).
❯ clang -target x86_64 -masm=intel -S hello.c
hello.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
As clang docs says I can manually install x86_64 libraries and do:
clang -target x86_64 -masm=intel -I path/to/Include -L path/to/Library -S hello.c
But I can't find prebuilt packages to download on MacOS. I tried cross compilation, it takes too much effort.
So I ditched and went for something simpler. I found a solution to this problem that I shall share as an answer below.