int main() {
  int int_var = 5;
  int *int_ptr;
  int_ptr = &int_var;
  printf(" int_ptr = %p\n", (void *)int_ptr);
  printf("&int_ptr = %p\n", (void *)&int_ptr);
  printf("*int_ptr = %d\n\n", *int_ptr);
  printf("int_var is located at %p and contains %d\n", (void *)&int_var,
         int_var);
  printf("int_ptr is located at %p, contains %p, and points to %d\n\n",
         (void *)&int_ptr, (void *)int_ptr, *int_ptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rsi
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x5,0xc(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,0x10(%rsp)
lea    0xed0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%esi
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%rdx
mov    (%rdx),%ecx
lea    0xed0(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [15 x i8] c" int_ptr = %p\0A\00"
@.str.1 = [15 x i8] c"&int_ptr = %p\0A\00"
@.str.2 = [16 x i8] c"*int_ptr = %d\0A\0A\00"
@.str.3 = [42 x i8] c"int_var is located at %p and contains %d\0A\00"
@.str.4 = [58 x i8] c"int_ptr is located at %p, contains %p, and points to %d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
store i32 0, i32* %1
store i32 5, i32* %2
store i32* %2, i32** %3
%4 = load i32*, i32** %3
%5 = bitcast i32* %4 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = bitcast i32** %3 to i8*
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i32*, i32** %3
%10 = load i32, i32* %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = bitcast i32* %2 to i8*
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %12, i32 %13)
%15 = bitcast i32** %3 to i8*
%16 = load i32*, i32** %3
%17 = bitcast i32* %16 to i8*
%18 = load i32*, i32** %3
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i8* %15, i8* %17, i32 %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c" int_ptr = %p\0A\00"
@.str.1 = [15 x i8] c"&int_ptr = %p\0A\00"
@.str.2 = [16 x i8] c"*int_ptr = %d\0A\0A\00"
@.str.3 = [42 x i8] c"int_var is located at %p and contains %d\0A\00"
@.str.4 = [58 x i8] c"int_ptr is located at %p, contains %p, and points to %d\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = bitcast i32* %1 to i8*
store i32 5, i32* %1
%4 = bitcast i32** %2 to i8*
store i32* %1, i32** %2
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32** %2)
%7 = load i32*, i32** %2
%8 = load i32, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %1
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32 %10)
%12 = load i32*, i32** %2
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0), i32** %2, i32* %12, i32 %13)
ret i32 0
}