#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*/ free(int *);
int /*<<< orphan*/ printf(char *, int *, ...);
void test_array() {
  int array[] = {21, 33, 35};
  printf("\n array address:\n%p\n%p\n%p\n", array, &array, &array[0]);
  int *array_ptr = array;
  printf(" 1st element:%p = %d \n", array_ptr, *array_ptr);
  array_ptr++;
  printf(" 2d element:%p = %d \n", array_ptr, *array_ptr);
  array_ptr++;
  printf(" 3rd element:%p = %d \n", array_ptr, *array_ptr);
  int *arr_ptr = &array[1];
  printf("\n 1st elem for arr_ptr: %p = %d\n", arr_ptr, arr_ptr[0]);
  printf("\n 2d elem for arr_ptr: %p = %d\n", (arr_ptr + 1), arr_ptr[1]);
  free(array_ptr);
}


x86 assembly (clang, -O0):
<test_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xecf(%rip),%eax
mov    %eax,-0x4(%rbp)
lea    -0xc(%rbp),%rsi
lea    -0xc(%rbp),%rcx
lea    0xec1(%rip),%rdi
lea    -0xc(%rbp),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_array>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0xedb(%rip),%eax
mov    %eax,0x10(%rsp)
mov    0xec8(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%r14
lea    0xec3(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
mov    %rbx,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%edx
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rbx
mov    0xc(%rsp),%edx
lea    0xebb(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%edx
lea    0xebc(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edx
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%edx
lea    0xeca(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.test_array.array = [3 x i32] [i32 21, i32 33, i32 35]
@.str = [27 x i8] c"\0A array address:\0A%p\0A%p\0A%p\0A\00"
@.str.1 = [23 x i8] c" 1st element:%p = %d \0A\00"
@.str.2 = [22 x i8] c" 2d element:%p = %d \0A\00"
@.str.3 = [23 x i8] c" 3rd element:%p = %d \0A\00"
@.str.4 = [33 x i8] c"\0A 1st elem for arr_ptr: %p = %d\0A\00"
@.str.5 = [32 x i8] c"\0A 2d elem for arr_ptr: %p = %d\0A\00"
define void @test_array() {
%1 = alloca [3 x i32]
%2 = alloca i32*
%3 = alloca i32*
%4 = bitcast [3 x i32]* %1 to i8*
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%6 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%7 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32* %5, [3 x i32]* %1, i32* %6)
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = load i32*, i32** %2
%11 = load i32, i32* %10
%12 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32* %9, i32 %11)
%13 = load i32*, i32** %2
%14 = getelementptr inbounds i32, i32* %13, i32 1
store i32* %14, i32** %2
%15 = load i32*, i32** %2
%16 = load i32*, i32** %2
%17 = load i32, i32* %16
%18 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32* %15, i32 %17)
%19 = load i32*, i32** %2
%20 = getelementptr inbounds i32, i32* %19, i32 1
store i32* %20, i32** %2
%21 = load i32*, i32** %2
%22 = load i32*, i32** %2
%23 = load i32, i32* %22
%24 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32* %21, i32 %23)
%25 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
store i32* %25, i32** %3
%26 = load i32*, i32** %3
%27 = load i32*, i32** %3
%28 = getelementptr inbounds i32, i32* %27, i64 0
%29 = load i32, i32* %28
%30 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32* %26, i32 %29)
%31 = load i32*, i32** %3
%32 = getelementptr inbounds i32, i32* %31, i64 1
%33 = load i32*, i32** %3
%34 = getelementptr inbounds i32, i32* %33, i64 1
%35 = load i32, i32* %34
%36 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32* %32, i32 %35)
%37 = load i32*, i32** %2
%38 = call i32 @free(i32* %37)
ret void
}

LLVM IR (-O2):
@__const.test_array.array = [3 x i32] [i32 21, i32 33, i32 35]
@.str = [27 x i8] c"\0A array address:\0A%p\0A%p\0A%p\0A\00"
@.str.1 = [23 x i8] c" 1st element:%p = %d \0A\00"
@.str.2 = [22 x i8] c" 2d element:%p = %d \0A\00"
@.str.3 = [23 x i8] c" 3rd element:%p = %d \0A\00"
@.str.4 = [33 x i8] c"\0A 1st elem for arr_ptr: %p = %d\0A\00"
@.str.5 = [32 x i8] c"\0A 2d elem for arr_ptr: %p = %d\0A\00"
define void @test_array() {
%1 = alloca [3 x i32]
%2 = bitcast [3 x i32]* %1 to i8*
%3 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%4 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32* %3, [3 x i32]* %1, i32* %3)
%5 = load i32, i32* %3
%6 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32 %5)
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%8 = load i32, i32* %7
%9 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32* %7, i32 %8)
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%11 = load i32, i32* %10
%12 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32* %10, i32 %11)
%13 = load i32, i32* %7
%14 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32* %7, i32 %13)
%15 = load i32, i32* %10
%16 = call i32 (i8*, i32*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32* %10, i32 %15)
%17 = call i32 @free(i32* %10)
ret void
}