#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int *malloc(int);
int /*<<< orphan*/ printPointerToArray(int **);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int *a = malloc(sizeof(int) * 3);
  a[0] = 42;
  a[1] = 43;
  a[2] = 44;
  fprintf(stderr, "Sulong: a[0] = %i\n", a[0]);
  fprintf(stderr, "Sulong: a[1] = %i\n", a[1]);
  fprintf(stderr, "Sulong: a[2] = %i\n", a[2]);
  fprintf(stderr, "Sulong: a = %p\n", a);
  fprintf(stderr, "Sulong: &a = %p\n", &a);
  int **b = &a;
  fprintf(stderr, "Sulong: b = %p\n", b);
  fprintf(stderr, "Sulong: *b = %p\n", *b);
  fprintf(stderr, "Sulong: *b[0] = %i\n", (*b)[0]);
  fprintf(stderr, "Sulong: *b[1] = %i\n", (*b)[1]);
  fprintf(stderr, "Sulong: *b[2] = %i\n", (*b)[2]);
  printPointerToArray(&a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xc,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x2a,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x2b,0x4(%rax)
mov    -0x18(%rbp),%rax
movl   $0x2c,0x8(%rax)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x4(%rax),%edx
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x8(%rax),%edx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x18(%rbp),%rdi
call   1030 <printPointerToArray@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0xc,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%rsp)
movabs $0x2b0000002a,%rax
mov    %rax,(%rbx)
movl   $0x2c,0x8(%rbx)
mov    0x2e80(%rip),%r14
mov    (%r14),%edi
lea    0xe96(%rip),%rsi
mov    $0x2a,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x4(%rbx),%edx
lea    0xe90(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    0x8(%rbx),%edx
lea    0xe8f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xe91(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xe8d(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xe87(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    (%rsp),%rdx
lea    0xe7f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    (%rsp),%rax
mov    (%rax),%edx
lea    0xe79(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    (%rsp),%rax
mov    0x4(%rax),%edx
lea    0xe75(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
mov    (%rsp),%rax
mov    0x8(%rax),%edx
lea    0xe71(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <printPointerToArray@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"Sulong: a[0] = %i\0A\00"
@.str.1 = [19 x i8] c"Sulong: a[1] = %i\0A\00"
@.str.2 = [19 x i8] c"Sulong: a[2] = %i\0A\00"
@.str.3 = [16 x i8] c"Sulong: a = %p\0A\00"
@.str.4 = [17 x i8] c"Sulong: &a = %p\0A\00"
@.str.5 = [16 x i8] c"Sulong: b = %p\0A\00"
@.str.6 = [17 x i8] c"Sulong: *b = %p\0A\00"
@.str.7 = [20 x i8] c"Sulong: *b[0] = %i\0A\00"
@.str.8 = [20 x i8] c"Sulong: *b[1] = %i\0A\00"
@.str.9 = [20 x i8] c"Sulong: *b[2] = %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @malloc(i32 12)
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = getelementptr inbounds i32, i32* %9, i64 0
store i32 42, i32* %10
%11 = load i32*, i32** %6
%12 = getelementptr inbounds i32, i32* %11, i64 1
store i32 43, i32* %12
%13 = load i32*, i32** %6
%14 = getelementptr inbounds i32, i32* %13, i64 2
store i32 44, i32* %14
%15 = load i32, i32* @stderr
%16 = load i32*, i32** %6
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = load i32, i32* %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @stderr
%21 = load i32*, i32** %6
%22 = getelementptr inbounds i32, i32* %21, i64 1
%23 = load i32, i32* %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @stderr
%26 = load i32*, i32** %6
%27 = getelementptr inbounds i32, i32* %26, i64 2
%28 = load i32, i32* %27
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @stderr
%31 = load i32*, i32** %6
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32* %31)
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32** %6)
store i32** %6, i32*** %7
%35 = load i32, i32* @stderr
%36 = load i32**, i32*** %7
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32** %36)
%38 = load i32, i32* @stderr
%39 = load i32**, i32*** %7
%40 = load i32*, i32** %39
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32* %40)
%42 = load i32, i32* @stderr
%43 = load i32**, i32*** %7
%44 = load i32*, i32** %43
%45 = getelementptr inbounds i32, i32* %44, i64 0
%46 = load i32, i32* %45
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %46)
%48 = load i32, i32* @stderr
%49 = load i32**, i32*** %7
%50 = load i32*, i32** %49
%51 = getelementptr inbounds i32, i32* %50, i64 1
%52 = load i32, i32* %51
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 %52)
%54 = load i32, i32* @stderr
%55 = load i32**, i32*** %7
%56 = load i32*, i32** %55
%57 = getelementptr inbounds i32, i32* %56, i64 2
%58 = load i32, i32* %57
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i32 %58)
%60 = call i32 @printPointerToArray(i32** %6)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"Sulong: a[0] = %i\0A\00"
@.str.1 = [19 x i8] c"Sulong: a[1] = %i\0A\00"
@.str.2 = [19 x i8] c"Sulong: a[2] = %i\0A\00"
@.str.3 = [16 x i8] c"Sulong: a = %p\0A\00"
@.str.4 = [17 x i8] c"Sulong: &a = %p\0A\00"
@.str.5 = [16 x i8] c"Sulong: b = %p\0A\00"
@.str.6 = [17 x i8] c"Sulong: *b = %p\0A\00"
@.str.7 = [20 x i8] c"Sulong: *b[0] = %i\0A\00"
@.str.8 = [20 x i8] c"Sulong: *b[1] = %i\0A\00"
@.str.9 = [20 x i8] c"Sulong: *b[2] = %i\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = tail call i32* @malloc(i32 12)
store i32* %5, i32** %3
store i32 42, i32* %5
%6 = getelementptr inbounds i32, i32* %5, i64 1
store i32 43, i32* %6
%7 = getelementptr inbounds i32, i32* %5, i64 2
store i32 44, i32* %7
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 42)
%10 = load i32, i32* @stderr
%11 = load i32, i32* %6
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @stderr
%14 = load i32, i32* %7
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32** %3)
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32** %3)
%22 = load i32, i32* @stderr
%23 = load i32*, i32** %3
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32* %23)
%25 = load i32, i32* @stderr
%26 = load i32*, i32** %3
%27 = load i32, i32* %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @stderr
%30 = load i32*, i32** %3
%31 = getelementptr inbounds i32, i32* %30, i64 1
%32 = load i32, i32* %31
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i32 %32)
%34 = load i32, i32* @stderr
%35 = load i32*, i32** %3
%36 = getelementptr inbounds i32, i32* %35, i64 2
%37 = load i32, i32* %36
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0), i32 %37)
%39 = call i32 @printPointerToArray(i32** %3)
ret i32 0
}