#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);
void arrayPointerSample2() {
  int arrA[] = {1, 2, 3, 4, 5};
  int *p1 = arrA;
  int *p2 = &arrA[1];
  int *p3 = &arrA[2];
  printf("p1+1 = %d\n", *(p1 + 1));
  printf("p2-1 = %d\n", *(p2 - 1));
  printf("p2-- = %d\n", --*p2);
  printf("p2 = %d\n", *p2);
  printf("p3 - p1 = %lu\n", p3 - p1);
}


x86 assembly (clang, -O0):
<arrayPointerSample2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0xee1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xede(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xedc(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    -0x4(%rax),%esi
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
add    $0xffffffff,%esi
mov    %esi,(%rax)
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,%esi
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrayPointerSample2>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
lea    0xedc(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x2,%esi
pop    %rax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@__const.arrayPointerSample2.arrA = [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5]
@.str = [11 x i8] c"p1+1 = %d\0A\00"
@.str.1 = [11 x i8] c"p2-1 = %d\0A\00"
@.str.2 = [11 x i8] c"p2-- = %d\0A\00"
@.str.3 = [9 x i8] c"p2 = %d\0A\00"
@.str.4 = [15 x i8] c"p3 - p1 = %lu\0A\00"
define void @arrayPointerSample2() {
%1 = alloca [5 x i32]
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = bitcast [5 x i32]* %1 to i8*
%6 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
store i32* %6, i32** %2
%7 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
store i32* %7, i32** %3
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 2
store i32* %8, i32** %4
%9 = load i32*, i32** %2
%10 = getelementptr inbounds i32, i32* %9, i64 1
%11 = load i32, i32* %10
%12 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32*, i32** %3
%14 = getelementptr inbounds i32, i32* %13, i64 -1
%15 = load i32, i32* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32*, i32** %3
%18 = load i32, i32* %17
%19 = add nsw i32 %18, -1
store i32 %19, i32* %17
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %3
%22 = load i32, i32* %21
%23 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %4
%25 = load i32*, i32** %2
%26 = ptrtoint i32* %24 to i64
%27 = ptrtoint i32* %25 to i64
%28 = sub i64 %26, %27
%29 = sdiv exact i64 %28, 4
%30 = trunc i64 %29 to i32
%31 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %30)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"p1+1 = %d\0A\00"
@.str.1 = [11 x i8] c"p2-1 = %d\0A\00"
@.str.2 = [11 x i8] c"p2-- = %d\0A\00"
@.str.3 = [9 x i8] c"p2 = %d\0A\00"
@.str.4 = [15 x i8] c"p3 - p1 = %lu\0A\00"
define void @arrayPointerSample2() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 2)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 1)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 1)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 2)
ret void
}