#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*/ assert(int);
int /*<<< orphan*/ printf(char *, ...);
void test_arrays_and_pointers() {
  printf("\n===== test_arrays_and_pointers\n");
  int i[2] = {42, 43};
  assert(i[0] == 42);
  assert(i[1] == 43);
  printf("Initializing a static array of int: `int i[2] = {%d, %d}`\n", i[0],
         i[1]);
  int *p = i;
  assert(p == i);
  printf("Set int pointer equal to the array variable (implicitly a pointer): "
         "`int *p = i`. Address: %p\n",
         p);
  assert(p[0] == 42);
  assert(p[1] == 43);
  printf("Dereferencing int pointer by index: `p[0]`, `p[1]`. Returns %d, %d\n",
         p[0], p[1]);
  assert(*p == 42);
  assert(*(p + 1) == 43);
  printf("Dereferencing int pointer: `*p`, `*(p + 1)`. Returns %d, %d\n", *p,
         *(p + 1));
  assert(*i == 42);
  assert(*(i + 1) == 43);
  printf("Dereferencing array variable as a pointer: `*i`, `*(i + 1)`. Returns "
         "%d, %d\n",
         *i, *(i + 1));
}


x86 assembly (clang, -O0):
<test_arrays_and_pointers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x104f(%rip),%rax
mov    %rax,-0x8(%rbp)
cmpl   $0x2a,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x2b,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
lea    -0x8(%rbp),%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rsi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x2a,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x2b,0x4(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x2a,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x2b,0x4(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2a,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x2b,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xedc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_arrays_and_pointers>:
push   %rax
lea    0x1030(%rip),%rdi
call   1030 <puts@plt>
movabs $0x2b0000002a,%rax
mov    %rax,(%rsp)
mov    $0x1,%edi
call   1050 <assert@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
lea    0xe9a(%rip),%rdi
mov    $0x2a,%esi
mov    $0x2b,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
lea    0xeb3(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x2a,(%rsp)
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x2b,0x4(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xedb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x2a,(%rsp)
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x2b,0x4(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xeeb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
cmpl   $0x2a,(%rsp)
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x2b,0x4(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xef4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [33 x i8] c"\0A===== test_arrays_and_pointers\0A\00"
@__const.test_arrays_and_pointers.i = [2 x i32] [i32 42, i32 43]
@.str.1 = [59 x i8] c"Initializing a static array of int: `int i[2] = {%d, %d}`\0A\00"
@.str.2 = [95 x i8] c"Set int pointer equal to the array variable (implicitly a pointer): `int *p = i`. Address: %p\0A\00"
@.str.3 = [68 x i8] c"Dereferencing int pointer by index: `p[0]`, `p[1]`. Returns %d, %d\0A\00"
@.str.4 = [61 x i8] c"Dereferencing int pointer: `*p`, `*(p + 1)`. Returns %d, %d\0A\00"
@.str.5 = [77 x i8] c"Dereferencing array variable as a pointer: `*i`, `*(i + 1)`. Returns %d, %d\0A\00"
define void @test_arrays_and_pointers() {
%1 = alloca [2 x i32]
%2 = alloca i32*
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 42
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 43
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %18)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
store i32* %20, i32** %2
%21 = load i32*, i32** %2
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%23 = icmp eq i32* %21, %22
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32*, i32** %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.2, i64 0, i64 0), i32* %26)
%28 = load i32*, i32** %2
%29 = getelementptr inbounds i32, i32* %28, i64 0
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, 42
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32*, i32** %2
%35 = getelementptr inbounds i32, i32* %34, i64 1
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, 43
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i32*, i32** %2
%41 = getelementptr inbounds i32, i32* %40, i64 0
%42 = load i32, i32* %41
%43 = load i32*, i32** %2
%44 = getelementptr inbounds i32, i32* %43, i64 1
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0), i32 %42, i32 %45)
%47 = load i32*, i32** %2
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, 42
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = load i32*, i32** %2
%53 = getelementptr inbounds i32, i32* %52, i64 1
%54 = load i32, i32* %53
%55 = icmp eq i32 %54, 43
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = load i32*, i32** %2
%59 = load i32, i32* %58
%60 = load i32*, i32** %2
%61 = getelementptr inbounds i32, i32* %60, i64 1
%62 = load i32, i32* %61
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %59, i32 %62)
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%65 = load i32, i32* %64
%66 = icmp eq i32 %65, 42
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%70 = getelementptr inbounds i32, i32* %69, i64 1
%71 = load i32, i32* %70
%72 = icmp eq i32 %71, 43
%73 = zext i1 %72 to i32
%74 = call i32 @assert(i32 %73)
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%76 = load i32, i32* %75
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%78 = getelementptr inbounds i32, i32* %77, i64 1
%79 = load i32, i32* %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.5, i64 0, i64 0), i32 %76, i32 %79)
ret void
}

LLVM IR (-O2):
@.str.1 = [59 x i8] c"Initializing a static array of int: `int i[2] = {%d, %d}`\0A\00"
@.str.2 = [95 x i8] c"Set int pointer equal to the array variable (implicitly a pointer): `int *p = i`. Address: %p\0A\00"
@.str.3 = [68 x i8] c"Dereferencing int pointer by index: `p[0]`, `p[1]`. Returns %d, %d\0A\00"
@.str.4 = [61 x i8] c"Dereferencing int pointer: `*p`, `*(p + 1)`. Returns %d, %d\0A\00"
@.str.5 = [77 x i8] c"Dereferencing array variable as a pointer: `*i`, `*(i + 1)`. Returns %d, %d\0A\00"
@str = [32 x i8] c"\0A===== test_arrays_and_pointers\00"
define void @test_arrays_and_pointers() {
%1 = alloca i64
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%3 = bitcast i64* %1 to i8*
store i64 184683593770, i64* %1
%4 = bitcast i64* %1 to i32*
%5 = tail call i32 @assert(i32 1)
%6 = tail call i32 @assert(i32 1)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 42, i32 43)
%8 = tail call i32 @assert(i32 1)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([95 x i8], [95 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 42
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = getelementptr inbounds i32, i32* %4, i64 1
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 43
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load i32, i32* %4
%20 = load i32, i32* %14
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32 %20)
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 42
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %14
%27 = icmp eq i32 %26, 43
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %4
%31 = load i32, i32* %14
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %31)
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 42
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i32, i32* %14
%38 = icmp eq i32 %37, 43
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i32, i32* %4
%42 = load i32, i32* %14
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.5, i64 0, i64 0), i32 %41, i32 %42)
ret void
}