#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*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  int *pa = (int *)malloc(100);
  int *pb = pa + 1;
  int *pc = (int *)0;
  *pa = 1;
  *pb = 2;
  printf("Pointer difference: %d %d\n", pb - pa, ((int)pb) - ((int)pa));
  int c = *(pa + 1);
  printf("Pointer addition: %d\n", c);
  printf("Pointer comparison to zero: %d %d %d\n", pa == 0, pb == 0, pc == 0);
  printf("Pointer comparison: %d %d %d %d %d\n", pa<pb, pa == pb, pa> pb, !pb,
         !pc);
  free(pa);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rax
sub    %eax,%edx
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
cmpq   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edx
cmpq   $0x0,-0x20(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%ecx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
setb   %al
and    $0x1,%al
movzbl %al,%esi
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edx
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
seta   %al
and    $0x1,%al
movzbl %al,%ecx
cmpq   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r8d
cmpq   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r9d
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x64,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movabs $0x200000001,%rax
mov    %rax,(%rbx)
lea    0xeae(%rip),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rbx),%esi
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb6(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x1,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec5(%rip),%rdi
mov    $0x1,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    $0x1,%r9d
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Pointer difference: %d %d\0A\00"
@.str.1 = [22 x i8] c"Pointer addition: %d\0A\00"
@.str.2 = [38 x i8] c"Pointer comparison to zero: %d %d %d\0A\00"
@.str.3 = [36 x i8] c"Pointer comparison: %d %d %d %d %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i64 @malloc(i32 100)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = getelementptr inbounds i32, i32* %8, i64 1
store i32* %9, i32** %3
store i32* null, i32** %4
%10 = load i32*, i32** %2
store i32 1, i32* %10
%11 = load i32*, i32** %3
store i32 2, i32* %11
%12 = load i32*, i32** %3
%13 = load i32*, i32** %2
%14 = ptrtoint i32* %12 to i64
%15 = ptrtoint i32* %13 to i64
%16 = sub i64 %14, %15
%17 = sdiv exact i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = load i32*, i32** %3
%20 = ptrtoint i32* %19 to i32
%21 = load i32*, i32** %2
%22 = ptrtoint i32* %21 to i32
%23 = sub nsw i32 %20, %22
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %23)
%25 = load i32*, i32** %2
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %26
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32*, i32** %2
%31 = icmp eq i32* %30, null
%32 = zext i1 %31 to i32
%33 = load i32*, i32** %3
%34 = icmp eq i32* %33, null
%35 = zext i1 %34 to i32
%36 = load i32*, i32** %4
%37 = icmp eq i32* %36, null
%38 = zext i1 %37 to i32
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %35, i32 %38)
%40 = load i32*, i32** %2
%41 = load i32*, i32** %3
%42 = icmp ult i32* %40, %41
%43 = zext i1 %42 to i32
%44 = load i32*, i32** %2
%45 = load i32*, i32** %3
%46 = icmp eq i32* %44, %45
%47 = zext i1 %46 to i32
%48 = load i32*, i32** %2
%49 = load i32*, i32** %3
%50 = icmp ugt i32* %48, %49
%51 = zext i1 %50 to i32
%52 = load i32*, i32** %3
%53 = icmp ne i32* %52, null
%54 = xor i1 %53, true
%55 = zext i1 %54 to i32
%56 = load i32*, i32** %4
%57 = icmp ne i32* %56, null
%58 = xor i1 %57, true
%59 = zext i1 %58 to i32
%60 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 %47, i32 %51, i32 %55, i32 %59)
%61 = load i32*, i32** %2
%62 = call i32 @free(i32* %61)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Pointer difference: %d %d\0A\00"
@.str.1 = [22 x i8] c"Pointer addition: %d\0A\00"
@.str.2 = [38 x i8] c"Pointer comparison to zero: %d %d %d\0A\00"
@.str.3 = [36 x i8] c"Pointer comparison: %d %d %d %d %d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 100)
%2 = inttoptr i64 %1 to i32*
%3 = getelementptr inbounds i32, i32* %2, i64 1
store i32 1, i32* %2
store i32 2, i32* %3
%4 = ptrtoint i32* %3 to i64
%5 = sub i64 %4, %1
%6 = lshr exact i64 %5, 2
%7 = trunc i64 %6 to i32
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %7, i32 4)
%9 = load i32, i32* %3
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0, i32 1)
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 0, i32 0, i32 0, i32 1)
%13 = tail call i32 @free(i32* %2)
ret i32 0
}