void test_simple_pointers() {
  printf("\n===== test_simple_pointers\n");
  int i = 42;
  int *p = &i;
  assert(p);
  printf("Set void pointer to the address of an int: `int *p = &i`\n");
  assert(*p == 42);
  printf("Dereferencing int pointer: `*p`. Returns %d\n", *p);
}


x86 assembly (clang, -O0):
<test_simple_pointers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2a,-0x4(%rbp)
lea    -0x4(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <assert@plt>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x2a,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_simple_pointers>:
push   %rax
lea    0xef5(%rip),%rdi
call   1030 <puts@plt>
movl   $0x2a,0x4(%rsp)
lea    0x4(%rsp),%rdi
xor    %eax,%eax
call   1050 <assert@plt>
lea    0xef1(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
cmpl   $0x2a,0x4(%rsp)
sete   %dil
xor    %eax,%eax
call   1050 <assert@plt>
mov    0x4(%rsp),%esi
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [29 x i8] c"\0A===== test_simple_pointers\0A\00"
@.str.1 = [58 x i8] c"Set void pointer to the address of an int: `int *p = &i`\0A\00"
@.str.2 = [45 x i8] c"Dereferencing int pointer: `*p`. Returns %d\0A\00"
define void @test_simple_pointers() {
%1 = alloca i32
%2 = alloca i32*
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 42, i32* %1
store i32* %1, i32** %2
%4 = load i32*, i32** %2
%5 = call i32 (i32*, ...) bitcast (i32 (...)* @assert to i32 (i32*, ...)*)(i32* %4)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32*, i32** %2
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 42
%10 = zext i1 %9 to i32
%11 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %10)
%12 = load i32*, i32** %2
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %13)
ret void
}

LLVM IR (-O2):
@.str.2 = [45 x i8] c"Dereferencing int pointer: `*p`. Returns %d\0A\00"
@str = [28 x i8] c"\0A===== test_simple_pointers\00"
@str.3 = [57 x i8] c"Set void pointer to the address of an int: `int *p = &i`\00"
define void @test_simple_pointers() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
store i32 42, i32* %1
%4 = call i32 (i32*, ...) bitcast (i32 (...)* @assert to i32 (i32*, ...)*)(i32* %1)
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.3, i64 0, i64 0))
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 42
%8 = zext i1 %7 to i32
%9 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %8)
%10 = load i32, i32* %1
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %10)
ret void
}