#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 */
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int arrayPointer() {
  printf("testing pointers understanding! ==arrayPointer start== \n\n");
  int a[10];
  printf("size of a is %lu", sizeof(a));
  printf("size of int is %lu", sizeof(int));
  for (int i = 0; i < (sizeof(a) / sizeof(int)); i++) {
    a[i] = i;
  };
  printf("\n-- after init --\n\n");
  printf("a[0]   %i and a[0]  address is %p \n", a[0], (void *)&a[0]);
  printf("a[9]   %i and a[9]  address is %p \n", a[9], (void *)&a[9]);
  printf("***\n");
  printf("testing pointers understanding! ==arrayPointer end== \n\n");
  printf("****\n");
  return 0;
}


x86 assembly (clang, -O0):
<arrayPointer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0d(%rip),%rdi
mov    $0x28,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf0b(%rip),%rdi
mov    $0x4,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0xa,%rax
jae    117a <arrayPointer+0x6a>
mov    -0x34(%rbp),%ecx
movslq -0x34(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1153 <arrayPointer+0x43>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%esi
lea    -0x30(%rbp),%rdx
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdx
add    $0x24,%rdx
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrayPointer>:
push   %rbx
sub    $0x30,%rsp
lea    0xf60(%rip),%rdi
call   1030 <puts@plt>
lea    0xee8(%rip),%rdi
mov    $0x28,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee6(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movaps 0xea2(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xea7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x900000008,%rax
mov    %rax,0x20(%rsp)
lea    0x24(%rsp),%rbx
lea    0xf3c(%rip),%rdi
call   1030 <puts@plt>
lea    0xeaf(%rip),%rdi
mov    %rsp,%rdx
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rsp),%esi
lea    0xebc(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf53(%rip),%rdi
call   1030 <puts@plt>
lea    0xf0f(%rip),%rdi
call   1030 <puts@plt>
lea    0xf3a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [58 x i8] c"testing pointers understanding! ==arrayPointer start== \0A\0A\00"
@.str.1 = [17 x i8] c"size of a is %lu\00"
@.str.2 = [19 x i8] c"size of int is %lu\00"
@.str.3 = [20 x i8] c"\0A-- after init --\0A\0A\00"
@.str.4 = [36 x i8] c"a[0] %i and a[0] address is %p \0A\00"
@.str.5 = [36 x i8] c"a[9] %i and a[9] address is %p \0A\00"
@.str.6 = [5 x i8] c"***\0A\00"
@.str.7 = [56 x i8] c"testing pointers understanding! ==arrayPointer end== \0A\0A\00"
@.str.8 = [6 x i8] c"****\0A\00"
define i32 @arrayPointer() {
%1 = alloca [10 x i32]
%2 = alloca i32
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 40)
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 4)
store i32 0, i32* %2
br label %6
6: ; preds = %15, %0
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = icmp ult i64 %8, 10
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = load i32, i32* %2
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %13
store i32 %11, i32* %14
br label %15
15: ; preds = %10
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %6
18: ; preds = %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%23 = bitcast i32* %22 to i8*
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %21, i8* %23)
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%26 = load i32, i32* %25
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%28 = bitcast i32* %27 to i8*
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %26, i8* %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"size of a is %lu\00"
@.str.2 = [19 x i8] c"size of int is %lu\00"
@.str.4 = [36 x i8] c"a[0] %i and a[0] address is %p \0A\00"
@.str.5 = [36 x i8] c"a[9] %i and a[9] address is %p \0A\00"
@str = [57 x i8] c"testing pointers understanding! ==arrayPointer start== \0A\00"
@str.9 = [19 x i8] c"\0A-- after init --\0A\00"
@str.10 = [4 x i8] c"***\00"
@str.11 = [55 x i8] c"testing pointers understanding! ==arrayPointer end== \0A\00"
@str.12 = [5 x i8] c"****\00"
define i32 @arrayPointer() {
%1 = alloca [10 x i32]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
%3 = bitcast [10 x i32]* %1 to i8*
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 40)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 4)
%6 = bitcast [10 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %6
%7 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%8 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %8
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
store i32 8, i32* %9
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
store i32 9, i32* %10
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 0, [10 x i32]* %1)
%13 = load i32, i32* %10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %13, i32* %10)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.10, i64 0, i64 0))
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.11, i64 0, i64 0))
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.12, i64 0, i64 0))
ret i32 0
}