#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*/ printf(char *, int, int, int, int *, int);
void trick1() {
  int arr[] = {1, 2, 3};
  int *ptr;
  ptr = arr;
  printf("arr[0] = %d, arr[1] = %d, arr[2] = %d, ptr = %p, *ptr = %d\n", arr[0],
         arr[1], arr[2], ptr, *ptr);
  *ptr++ = -1;
  printf("arr[0] = %d, arr[1] = %d, arr[2] = %d, ptr = %p, *ptr = %d\n", arr[0],
         arr[1], arr[2], ptr, *ptr);
  *++ptr = -2;
  printf("arr[0] = %d, arr[1] = %d, arr[2] = %d, ptr = %p, *ptr = %d\n", arr[0],
         arr[1], arr[2], ptr, *ptr);
  (*ptr)++;
  printf("arr[0] = %d, arr[1] = %d, arr[2] = %d, ptr = %p, *ptr = %d\n", arr[0],
         arr[1], arr[2], ptr, *ptr);
}


x86 assembly (clang, -O0):
<trick1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xee1(%rip),%rax
mov    %rax,-0xc(%rbp)
mov    0xedf(%rip),%eax
mov    %eax,-0x4(%rbp)
lea    -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x18(%rbp),%rax
mov    (%rax),%r9d
lea    0xebd(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0xffffffff,(%rax)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x18(%rbp),%rax
mov    (%rax),%r9d
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
movl   $0xfffffffe,0x4(%rax)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x18(%rbp),%rax
mov    (%rax),%r9d
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x4(%rbp),%ecx
mov    -0x18(%rbp),%r8
mov    -0x18(%rbp),%rax
mov    (%rax),%r9d
lea    0xe27(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trick1>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0xee9(%rip),%eax
mov    %eax,0x8(%rsp)
mov    0xed6(%rip),%rax
mov    %rax,(%rsp)
lea    0x8(%rsp),%r14
lea    0x4(%rsp),%r15
lea    0xecd(%rip),%rbx
mov    %rsp,%r8
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x3,%ecx
mov    $0x1,%r9d
call   1030 <printf@plt>
movl   $0xffffffff,(%rsp)
mov    0x4(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
mov    %r15,%r8
mov    %edx,%r9d
call   1030 <printf@plt>
movl   $0xfffffffe,0x8(%rsp)
ff
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    $0xfffffffe,%ecx
mov    %r14,%r8
mov    $0xfffffffe,%r9d
call   1030 <printf@plt>
mov    0x8(%rsp),%ecx
add    $0x1,%ecx
mov    %ecx,0x8(%rsp)
mov    (%rsp),%esi
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %r14,%r8
mov    %ecx,%r9d
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.trick1.arr = [3 x i32] [i32 1, i32 2, i32 3]
@.str = [60 x i8] c"arr[0] = %d, arr[1] = %d, arr[2] = %d, ptr = %p, *ptr = %d\0A\00"
define void @trick1() {
%1 = alloca [3 x i32]
%2 = alloca i32*
%3 = bitcast [3 x i32]* %1 to i8*
%4 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
store i32* %4, i32** %2
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%8 = load i32, i32* %7
%9 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%10 = load i32, i32* %9
%11 = load i32*, i32** %2
%12 = load i32*, i32** %2
%13 = load i32, i32* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %8, i32 %10, i32* %11, i32 %13)
%15 = load i32*, i32** %2
%16 = getelementptr inbounds i32, i32* %15, i32 1
store i32* %16, i32** %2
store i32 -1, i32* %15
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%22 = load i32, i32* %21
%23 = load i32*, i32** %2
%24 = load i32*, i32** %2
%25 = load i32, i32* %24
%26 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %20, i32 %22, i32* %23, i32 %25)
%27 = load i32*, i32** %2
%28 = getelementptr inbounds i32, i32* %27, i32 1
store i32* %28, i32** %2
store i32 -2, i32* %28
%29 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%32 = load i32, i32* %31
%33 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%34 = load i32, i32* %33
%35 = load i32*, i32** %2
%36 = load i32*, i32** %2
%37 = load i32, i32* %36
%38 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %32, i32 %34, i32* %35, i32 %37)
%39 = load i32*, i32** %2
%40 = load i32, i32* %39
%41 = add nsw i32 %40, 1
store i32 %41, i32* %39
%42 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%43 = load i32, i32* %42
%44 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%45 = load i32, i32* %44
%46 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%47 = load i32, i32* %46
%48 = load i32*, i32** %2
%49 = load i32*, i32** %2
%50 = load i32, i32* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %43, i32 %45, i32 %47, i32* %48, i32 %50)
ret void
}

LLVM IR (-O2):
@__const.trick1.arr = [3 x i32] [i32 1, i32 2, i32 3]
@.str = [60 x i8] c"arr[0] = %d, arr[1] = %d, arr[2] = %d, ptr = %p, *ptr = %d\0A\00"
define void @trick1() {
%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 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%6 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 1, i32 2, i32 3, i32* %3, i32 1)
store i32 -1, i32* %3
%7 = load i32, i32* %4
%8 = load i32, i32* %5
%9 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 -1, i32 %7, i32 %8, i32* %4, i32 %7)
store i32 -2, i32* %5
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11, i32 -2, i32* %5, i32 -2)
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
store i32 %14, i32* %5
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %16, i32 %14, i32* %5, i32 %14)
ret void
}