#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(void) {
  int urn[5] = {100, 200, 300, 400, 500};
  int *ptr1, *ptr2, *ptr3;
  ptr1 = urn;
  ptr2 = &urn[2];
  printf("pointer value, deferenced 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, *(ptr4 + 3) = %d\n", ptr1 + 4, *(ptr1 + 3));
  ptr1++;
  printf("\nvalues after ptr1++:\n");
  printf("ptr1 = %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 = %td\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    0xed8(%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    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
add    $0x10,%rsi
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%edx
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
lea    0xe6b(%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    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
lea    0xec5(%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    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed5(%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    0xed8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xef3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x38(%rbp),%rdx
add    $0xfffffffffffffff8,%rdx
lea    0xefe(%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   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    0xedd(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,(%rsp)
lea    0xf81(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%edx
lea    0xeb1(%rip),%r15
mov    %rsp,%r12
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%r13
lea    0x10(%r13),%r14
lea    0xf83(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rsi
mov    0xc(%rsi),%edx
add    $0x10,%rsi
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
addq   $0x4,(%rsp)
lea    0xf76(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rsi
mov    (%rsi),%edx
mov    %r15,%rdi
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x14(%rsp),%rbx
mov    %rbx,0x8(%rsp)
lea    0xf63(%rip),%rdi
call   1030 <puts@plt>
mov    0x14(%rsp),%edx
lea    0xe70(%rip),%rdi
lea    0x8(%rsp),%rcx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
addq   $0xfffffffffffffffc,(%rsp)
addq   $0x4,0x8(%rsp)
lea    0xf48(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rsi
mov    0x8(%rsp),%rdx
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf49(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rsi
mov    (%rsp),%rdx
mov    %rsi,%rcx
sub    %rdx,%rcx
sar    $0x2,%rcx
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf43(%rip),%rdi
call   1030 <puts@plt>
add    $0x8,%r13
lea    0xe51(%rip),%rdi
mov    %r14,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [53 x i8] c"pointer value, deferenced 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, *(ptr4 + 3) = %d\0A\00"
@.str.4 = [23 x i8] c"\0Avalues after ptr1++:\0A\00"
@.str.5 = [23 x i8] c"\0Avalues after --ptr2:\0A\00"
@.str.6 = [35 x i8] c"ptr2 = %p, *ptr2 = %d, &ptr2 = %p\0A\00"
@.str.7 = [37 x i8] c"\0APointers reset to original values:\0A\00"
@.str.8 = [22 x i8] c"ptr1 = %p, ptr2 = %p\0A\00"
@.str.9 = [40 x i8] c"\0Asubtracting one pointer from another:\0A\00"
@.str.10 = [41 x i8] c"ptr2 = %p, ptr1 = %p, ptr2 - ptr1 = %td\0A\00"
@.str.11 = [37 x i8] c"\0Asubtracting an int from a pointer:\0A\00"
@.str.12 = [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 ([53 x i8], [53 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 3
%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 ([35 x i8], [35 x i8]* @.str.1, 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.5, 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.6, 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.7, 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.8, i64 0, i64 0), i32* %42, i32* %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, 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.10, 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.11, 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.12, 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, *(ptr4 + 3) = %d\0A\00"
@.str.6 = [35 x i8] c"ptr2 = %p, *ptr2 = %d, &ptr2 = %p\0A\00"
@.str.8 = [22 x i8] c"ptr1 = %p, ptr2 = %p\0A\00"
@.str.10 = [41 x i8] c"ptr2 = %p, ptr1 = %p, ptr2 - ptr1 = %td\0A\00"
@.str.12 = [26 x i8] c"ptr3 = %p, ptr3 - 2 = %p\0A\00"
@str = [52 x i8] c"pointer value, deferenced pointer, pointer address:\00"
@str.13 = [29 x i8] c"\0Aadding an int to a pointer:\00"
@str.14 = [22 x i8] c"\0Avalues after ptr1++:\00"
@str.15 = [22 x i8] c"\0Avalues after --ptr2:\00"
@str.16 = [36 x i8] c"\0APointers reset to original values:\00"
@str.17 = [39 x i8] c"\0Asubtracting one pointer from another:\00"
@str.18 = [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 ([52 x i8], [52 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.13, i64 0, i64 0))
%14 = load i32*, i32** %2
%15 = getelementptr inbounds i32, i32* %14, i64 4
%16 = getelementptr inbounds i32, i32* %14, i64 3
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32* %15, i32 %17)
%19 = load i32*, i32** %2
%20 = getelementptr inbounds i32, i32* %19, i64 1
store i32* %20, i32** %2
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.14, i64 0, i64 0))
%22 = load i32*, i32** %2
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32* %22, i32 %23, i32** %2)
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
store i32* %25, i32** %3
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.15, i64 0, i64 0))
%27 = load i32, i32* %25
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i32* %25, i32 %27, i32** %3)
%29 = load i32*, i32** %2
%30 = getelementptr inbounds i32, i32* %29, i64 -1
store i32* %30, i32** %2
%31 = load i32*, i32** %3
%32 = getelementptr inbounds i32, i32* %31, i64 1
store i32* %32, i32** %3
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.16, i64 0, i64 0))
%34 = load i32*, i32** %2
%35 = load i32*, i32** %3
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i32* %34, i32* %35)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.17, i64 0, i64 0))
%38 = load i32*, i32** %3
%39 = load i32*, i32** %2
%40 = ptrtoint i32* %38 to i64
%41 = ptrtoint i32* %39 to i64
%42 = sub i64 %40, %41
%43 = ashr exact i64 %42, 2
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0), i32* %38, i32* %39, i64 %43)
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.18, i64 0, i64 0))
%46 = getelementptr inbounds i32, i32* %11, i64 2
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.12, i64 0, i64 0), i32* %12, i32* %46)
ret i32 0
}