#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 main() {
  int urn[5] = {100, 200, 300, 400, 500};
  int *ptr1, *ptr2, *ptr3;
  ptr1 = urn;
  ptr2 = &urn[2];
  printf("pointer value, dereferenced pointer, pointer address:\n");
  printf("ptr1 = %p, *ptr1 = %d, &ptr1 = %p\n", ptr1, *ptr1, &ptr1);
  ptr3 = ptr1 + 4;
  printf("\nadding an int to a pointer:\n");
  printf("ptr1 + 4 = %p, *(ptr1 + 4) = %d\n", ptr1 + 4, *(ptr1 + 4));
  ptr1++;
  printf("\nvalues after ptr1++:\n");
  printf("ptr1 + 4 = %p, *ptr1 = %d, &ptr1 = %p\n", ptr1, *ptr1, &ptr1);
  ptr2--;
  printf("\nvalues after ptr2--:\n");
  printf("ptr2 = %p, *ptr2 = %d, &ptr2 = %p\n", ptr2, *ptr2, &ptr2);
  --ptr1;
  ++ptr2;
  printf("\nPointers reset to original values:\n");
  printf("ptr1 = %p, ptr2 = %p\n", ptr1, ptr2);
  printf("\nsubtracting one pointer from another:\n");
  printf("ptr2 = %p, ptr1 = %p, ptr2 - ptr1 = %ld\n", ptr2, ptr1, ptr2 - ptr1);
  printf("\nsubtracting an int from a pointer:\n");
  printf("ptr3 = %p, ptr3 - 2 = %p\n", ptr3, ptr3 - 2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed5(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    0xeda(%rip),%rdi
lea    -0x28(%rbp),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x38(%rbp)
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
add    $0x10,%rsi
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%edx
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    0xee6(%rip),%rdi
lea    -0x28(%rbp),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x30(%rbp)
lea    0xeef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
lea    0xeee(%rip),%rdi
lea    -0x30(%rbp),%rcx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xef6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rax,%rcx
sar    $0x2,%rcx
lea    0xf01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x38(%rbp),%rdx
add    $0xfffffffffffffff8,%rdx
lea    0xf27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0xedf(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xec4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,(%rsp)
lea    0xfaa(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%edx
lea    0xeb3(%rip),%rdi
mov    %rsp,%r15
mov    %rbx,%rsi
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%r12
lea    0x10(%r12),%r14
lea    0xfb0(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rsi
mov    0x10(%rsi),%edx
add    $0x10,%rsi
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
addq   $0x4,(%rsp)
lea    0xfa3(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rsi
mov    (%rsi),%edx
lea    0xe9b(%rip),%rdi
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x14(%rsp),%rbx
mov    %rbx,0x8(%rsp)
lea    0xf8c(%rip),%rdi
call   1030 <puts@plt>
mov    0x14(%rsp),%edx
lea    0xe97(%rip),%rdi
lea    0x8(%rsp),%rcx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
addq   $0xfffffffffffffffc,(%rsp)
addq   $0x4,0x8(%rsp)
lea    0xf71(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rsi
mov    0x8(%rsp),%rdx
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf72(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
mov    %rsi,%rcx
sub    %rdx,%rcx
sar    $0x2,%rcx
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf6c(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%r12
lea    0xe78(%rip),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.urn = [5 x i32] [i32 100, i32 200, i32 300, i32 400, i32 500]
@.str = [55 x i8] c"pointer value, dereferenced pointer, pointer address:\0A\00"
@.str.1 = [35 x i8] c"ptr1 = %p, *ptr1 = %d, &ptr1 = %p\0A\00"
@.str.2 = [30 x i8] c"\0Aadding an int to a pointer:\0A\00"
@.str.3 = [33 x i8] c"ptr1 + 4 = %p, *(ptr1 + 4) = %d\0A\00"
@.str.4 = [23 x i8] c"\0Avalues after ptr1++:\0A\00"
@.str.5 = [39 x i8] c"ptr1 + 4 = %p, *ptr1 = %d, &ptr1 = %p\0A\00"
@.str.6 = [23 x i8] c"\0Avalues after ptr2--:\0A\00"
@.str.7 = [35 x i8] c"ptr2 = %p, *ptr2 = %d, &ptr2 = %p\0A\00"
@.str.8 = [37 x i8] c"\0APointers reset to original values:\0A\00"
@.str.9 = [22 x i8] c"ptr1 = %p, ptr2 = %p\0A\00"
@.str.10 = [40 x i8] c"\0Asubtracting one pointer from another:\0A\00"
@.str.11 = [41 x i8] c"ptr2 = %p, ptr1 = %p, ptr2 - ptr1 = %ld\0A\00"
@.str.12 = [37 x i8] c"\0Asubtracting an int from a pointer:\0A\00"
@.str.13 = [26 x i8] c"ptr3 = %p, ptr3 - 2 = %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
%6 = bitcast [5 x i32]* %2 to i8*
%7 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
store i32* %7, i32** %3
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 2
store i32* %8, i32** %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%10 = load i32*, i32** %3
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32* %10, i32 %12, i32** %3)
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 4
store i32* %15, i32** %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 4
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 4
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32* %18, i32 %21)
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i32 1
store i32* %24, i32** %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32*, i32** %3
%27 = load i32*, i32** %3
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32* %26, i32 %28, i32** %3)
%30 = load i32*, i32** %4
%31 = getelementptr inbounds i32, i32* %30, i32 -1
store i32* %31, i32** %4
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%33 = load i32*, i32** %4
%34 = load i32*, i32** %4
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i32* %33, i32 %35, i32** %4)
%37 = load i32*, i32** %3
%38 = getelementptr inbounds i32, i32* %37, i32 -1
store i32* %38, i32** %3
%39 = load i32*, i32** %4
%40 = getelementptr inbounds i32, i32* %39, i32 1
store i32* %40, i32** %4
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
%42 = load i32*, i32** %3
%43 = load i32*, i32** %4
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32* %42, i32* %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0))
%46 = load i32*, i32** %4
%47 = load i32*, i32** %3
%48 = load i32*, i32** %4
%49 = load i32*, i32** %3
%50 = ptrtoint i32* %48 to i64
%51 = ptrtoint i32* %49 to i64
%52 = sub i64 %50, %51
%53 = sdiv exact i64 %52, 4
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.11, i64 0, i64 0), i32* %46, i32* %47, i64 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.12, i64 0, i64 0))
%56 = load i32*, i32** %5
%57 = load i32*, i32** %5
%58 = getelementptr inbounds i32, i32* %57, i64 -2
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i32* %56, i32* %58)
ret i32 0
}

LLVM IR (-O2):
@__const.main.urn = [5 x i32] [i32 100, i32 200, i32 300, i32 400, i32 500]
@.str.1 = [35 x i8] c"ptr1 = %p, *ptr1 = %d, &ptr1 = %p\0A\00"
@.str.3 = [33 x i8] c"ptr1 + 4 = %p, *(ptr1 + 4) = %d\0A\00"
@.str.5 = [39 x i8] c"ptr1 + 4 = %p, *ptr1 = %d, &ptr1 = %p\0A\00"
@.str.7 = [35 x i8] c"ptr2 = %p, *ptr2 = %d, &ptr2 = %p\0A\00"
@.str.9 = [22 x i8] c"ptr1 = %p, ptr2 = %p\0A\00"
@.str.11 = [41 x i8] c"ptr2 = %p, ptr1 = %p, ptr2 - ptr1 = %ld\0A\00"
@.str.13 = [26 x i8] c"ptr3 = %p, ptr3 - 2 = %p\0A\00"
@str = [54 x i8] c"pointer value, dereferenced pointer, pointer address:\00"
@str.14 = [29 x i8] c"\0Aadding an int to a pointer:\00"
@str.15 = [22 x i8] c"\0Avalues after ptr1++:\00"
@str.16 = [22 x i8] c"\0Avalues after ptr2--:\00"
@str.17 = [36 x i8] c"\0APointers reset to original values:\00"
@str.18 = [39 x i8] c"\0Asubtracting one pointer from another:\00"
@str.19 = [36 x i8] c"\0Asubtracting an int from a pointer:\00"
define i32 @main() {
%1 = alloca [5 x i32]
%2 = alloca i32*
%3 = alloca i32*
%4 = bitcast [5 x i32]* %1 to i8*
%5 = bitcast i32** %2 to i8*
%6 = bitcast i32** %3 to i8*
%7 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
store i32* %7, i32** %2
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* %7
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32* %7, i32 %9, i32** %2)
%11 = load i32*, i32** %2
%12 = getelementptr inbounds i32, i32* %11, i64 4
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.14, i64 0, i64 0))
%14 = load i32*, i32** %2
%15 = getelementptr inbounds i32, i32* %14, i64 4
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32* %15, i32 %16)
%18 = load i32*, i32** %2
%19 = getelementptr inbounds i32, i32* %18, i64 1
store i32* %19, i32** %2
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.15, i64 0, i64 0))
%21 = load i32*, i32** %2
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i32* %21, i32 %22, i32** %2)
%24 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
store i32* %24, i32** %3
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.16, i64 0, i64 0))
%26 = load i32, i32* %24
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i32* %24, i32 %26, i32** %3)
%28 = load i32*, i32** %2
%29 = getelementptr inbounds i32, i32* %28, i64 -1
store i32* %29, i32** %2
%30 = load i32*, i32** %3
%31 = getelementptr inbounds i32, i32* %30, i64 1
store i32* %31, i32** %3
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.17, i64 0, i64 0))
%33 = load i32*, i32** %2
%34 = load i32*, i32** %3
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i32* %33, i32* %34)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.18, i64 0, i64 0))
%37 = load i32*, i32** %3
%38 = load i32*, i32** %2
%39 = ptrtoint i32* %37 to i64
%40 = ptrtoint i32* %38 to i64
%41 = sub i64 %39, %40
%42 = ashr exact i64 %41, 2
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.11, i64 0, i64 0), i32* %37, i32* %38, i64 %42)
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.19, i64 0, i64 0))
%45 = getelementptr inbounds i32, i32* %11, i64 2
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.13, i64 0, i64 0), i32* %12, i32* %45)
ret i32 0
}