#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 */
typedef int /*<<< orphan*/ vec;
typedef int ptrdiff_t;

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int vec[10] = {98, 16, 24, 10, 87, 28, 93, 11, 54, 92};
  int *ptr0 = &vec[10 - 1];
  int *ptr1 = &vec[5];
  int *ptr2 = &vec[2];
  ptrdiff_t res1 = ptr0 - ptr1;
  ptrdiff_t res2 = ptr1 - ptr2;
  printf("             Array: ");
  for (int i = 0; i < sizeof(vec) / sizeof(vec[0]); i++)
    printf("%d, ", vec[i]);
  printf("\n   Address of ptr0: %d %p \n", *ptr0, (void *)ptr0);
  printf("   Address of ptr1: %d %p \n", *ptr1, (void *)ptr1);
  printf("   Address of ptr2: %d %p \n", *ptr2, (void *)ptr2);
  printf("       ptr0 - ptr1: %td\n", res1);
  printf("       ptr1 - ptr2: %td\n", res2);
  int *ptr4 = &vec[ptr0 - ptr1];
  printf("array[ptr0 - ptr1]: %d %p\n", *ptr4, (void *)ptr4);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
lea    -0x30(%rbp),%rax
add    $0x24,%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rax
add    $0x14,%rax
mov    %rax,-0x40(%rbp)
lea    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x48(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,-0x50(%rbp)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x54(%rbp)
movslq -0x54(%rbp),%rax
cmp    $0xa,%rax
jae    11d3 <main+0xb3>
movslq -0x54(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11a1 <main+0x81>
mov    -0x38(%rbp),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rdx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rax
mov    (%rax),%esi
mov    -0x40(%rbp),%rdx
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%esi
mov    -0x48(%rbp),%rdx
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4c(%rbp),%esi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%rax
sub    %rax,%rcx
sar    $0x2,%rcx
lea    -0x30(%rbp),%rax
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    (%rax),%esi
mov    -0x60(%rbp),%rdx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    0xefc(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xee0(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xec4(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%r14
lea    0x14(%rsp),%r15
lea    0xed7(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xede(%rip),%rbx
mov    %rbx,%rdi
mov    $0x62,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x8(%rsp),%r12
mov    %rbx,%rdi
mov    $0x18,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x57,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x1c,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x5d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xb,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x36,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x24(%rsp),%r13
mov    %rbx,%rdi
mov    $0x5c,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe3c(%rip),%rdi
mov    $0x5c,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x14(%rsp),%esi
lea    0xe3f(%rip),%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
lea    0xe46(%rip),%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe51(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe57(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%esi
lea    0xe59(%rip),%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.vec = [10 x i32] [i32 98, i32 16, i32 24, i32 10, i32 87, i32 28, i32 93, i32 11, i32 54, i32 92]
@.str = [21 x i8] c" Array: \00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.2 = [29 x i8] c"\0A Address of ptr0: %d %p \0A\00"
@.str.3 = [28 x i8] c" Address of ptr1: %d %p \0A\00"
@.str.4 = [28 x i8] c" Address of ptr2: %d %p \0A\00"
@.str.5 = [25 x i8] c" ptr0 - ptr1: %td\0A\00"
@.str.6 = [25 x i8] c" ptr1 - ptr2: %td\0A\00"
@.str.7 = [27 x i8] c"array[ptr0 - ptr1]: %d %p\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %1
%10 = bitcast [10 x i32]* %2 to i8*
%11 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 9
store i32* %11, i32** %3
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 5
store i32* %12, i32** %4
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 2
store i32* %13, i32** %5
%14 = load i32*, i32** %3
%15 = load i32*, i32** %4
%16 = ptrtoint i32* %14 to i64
%17 = ptrtoint i32* %15 to i64
%18 = sub i64 %16, %17
%19 = sdiv exact i64 %18, 4
%20 = trunc i64 %19 to i32
store i32 %20, i32* %6
%21 = load i32*, i32** %4
%22 = load i32*, i32** %5
%23 = ptrtoint i32* %21 to i64
%24 = ptrtoint i32* %22 to i64
%25 = sub i64 %23, %24
%26 = sdiv exact i64 %25, 4
%27 = trunc i64 %26 to i32
store i32 %27, i32* %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %29
29: ; preds = %39, %0
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = icmp ult i64 %31, 10
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %33
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %29
42: ; preds = %29
%43 = load i32*, i32** %3
%44 = load i32, i32* %43
%45 = load i32*, i32** %3
%46 = bitcast i32* %45 to i8*
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %44, i8* %46)
%48 = load i32*, i32** %4
%49 = load i32, i32* %48
%50 = load i32*, i32** %4
%51 = bitcast i32* %50 to i8*
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %49, i8* %51)
%53 = load i32*, i32** %5
%54 = load i32, i32* %53
%55 = load i32*, i32** %5
%56 = bitcast i32* %55 to i8*
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %54, i8* %56)
%58 = load i32, i32* %6
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %7
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %60)
%62 = load i32*, i32** %3
%63 = load i32*, i32** %4
%64 = ptrtoint i32* %62 to i64
%65 = ptrtoint i32* %63 to i64
%66 = sub i64 %64, %65
%67 = sdiv exact i64 %66, 4
%68 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %67
store i32* %68, i32** %9
%69 = load i32*, i32** %9
%70 = load i32, i32* %69
%71 = load i32*, i32** %9
%72 = bitcast i32* %71 to i8*
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %70, i8* %72)
%74 = load i32, i32* @EXIT_SUCCESS
ret i32 %74
}

LLVM IR (-O2):
@__const.main.vec = [10 x i32] [i32 98, i32 16, i32 24, i32 10, i32 87, i32 28, i32 93, i32 11, i32 54, i32 92]
@.str = [21 x i8] c" Array: \00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.2 = [29 x i8] c"\0A Address of ptr0: %d %p \0A\00"
@.str.3 = [28 x i8] c" Address of ptr1: %d %p \0A\00"
@.str.4 = [28 x i8] c" Address of ptr2: %d %p \0A\00"
@.str.5 = [25 x i8] c" ptr0 - ptr1: %td\0A\00"
@.str.6 = [25 x i8] c" ptr1 - ptr2: %td\0A\00"
@.str.7 = [27 x i8] c"array[ptr0 - ptr1]: %d %p\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 98)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 16)
%7 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 24)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 10)
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 87)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 28)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 93)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 11)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 54)
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 92)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 92, i32* %16)
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %19, i32* %3)
%21 = load i32, i32* %7
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %21, i32* %7)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i32 4)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 3)
%25 = load i32, i32* %10
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %25, i32* %10)
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}