#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 ptrdiff_t;

/* Variables and functions */
int /*<<< orphan*/ free(int *);
int *malloc(int);
int main(void) {
  int *array = malloc(sizeof(int) * 10);
  if (array == NULL)
    return 1;
  int *array2 = malloc(sizeof(int) * 10);
  if (array2 == NULL) {
    free(array);
    return 1;
  }
  int *p = array;
  int *q = array2 + 5;
  ptrdiff_t qp = q - p;
  ptrdiff_t pq = p - q;
  if (qp == 5 && pq == -5) {
    free(array);
    free(array2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <main+0x34>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <main+0xc7>
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1182 <main+0x62>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <main+0xc7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x14,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %eax,-0x30(%rbp)
cmpl   $0x5,-0x2c(%rbp)
jne    11e0 <main+0xc0>
cmpl   $0xfffffffb,-0x30(%rbp)
jne    11e0 <main+0xc0>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x28,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     117b <main+0x5b>
mov    %rax,%rbx
mov    $0x28,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1182 <main+0x62>
mov    %rax,%r14
add    $0x14,%rax
mov    %rax,%rcx
sub    %rbx,%rcx
shr    $0x2,%rcx
xor    %ebp,%ebp
cmp    $0x5,%ecx
jne    118f <main+0x6f>
mov    %rbx,%rcx
sub    %rax,%rcx
shr    $0x2,%rcx
cmp    $0xfffffffb,%ecx
jne    118f <main+0x6f>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %r14,%rbx
jmp    1187 <main+0x67>
mov    $0x1,%ebp
jmp    118f <main+0x6f>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32* @malloc(i32 40)
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %0
store i32 1, i32* %1
br label %48
12: ; preds = %0
%13 = call i32* @malloc(i32 40)
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32*, i32** %2
%18 = call i32 @free(i32* %17)
store i32 1, i32* %1
br label %48
19: ; preds = %12
%20 = load i32*, i32** %2
store i32* %20, i32** %4
%21 = load i32*, i32** %3
%22 = getelementptr inbounds i32, i32* %21, i64 5
store i32* %22, i32** %5
%23 = load i32*, i32** %5
%24 = load i32*, i32** %4
%25 = ptrtoint i32* %23 to i64
%26 = ptrtoint i32* %24 to i64
%27 = sub i64 %25, %26
%28 = sdiv exact i64 %27, 4
%29 = trunc i64 %28 to i32
store i32 %29, i32* %6
%30 = load i32*, i32** %4
%31 = load i32*, i32** %5
%32 = ptrtoint i32* %30 to i64
%33 = ptrtoint i32* %31 to i64
%34 = sub i64 %32, %33
%35 = sdiv exact i64 %34, 4
%36 = trunc i64 %35 to i32
store i32 %36, i32* %7
%37 = load i32, i32* %6
%38 = icmp eq i32 %37, 5
br i1 %38, label %39, label %47
39: ; preds = %19
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, -5
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i32*, i32** %2
%44 = call i32 @free(i32* %43)
%45 = load i32*, i32** %3
%46 = call i32 @free(i32* %45)
br label %47
47: ; preds = %42, %39, %19
store i32 0, i32* %1
br label %48
48: ; preds = %47, %16, %11
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32* @malloc(i32 40)
%2 = icmp eq i32* %1, null
br i1 %2, label %25, label %3
3: ; preds = %0
%4 = tail call i32* @malloc(i32 40)
%5 = icmp eq i32* %4, null
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = getelementptr inbounds i32, i32* %4, i64 5
%8 = ptrtoint i32* %7 to i64
%9 = ptrtoint i32* %1 to i64
%10 = sub i64 %8, %9
%11 = lshr exact i64 %10, 2
%12 = trunc i64 %11 to i32
%13 = sub i64 %9, %8
%14 = lshr exact i64 %13, 2
%15 = trunc i64 %14 to i32
%16 = icmp eq i32 %12, 5
%17 = icmp eq i32 %15, -5
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %25
19: ; preds = %6
%20 = tail call i32 @free(i32* %1)
br label %21
21: ; preds = %3, %19
%22 = phi i32* [ %4, %19 ], [ %1, %3 ]
%23 = phi i32 [ 0, %19 ], [ 1, %3 ]
%24 = tail call i32 @free(i32* %22)
br label %25
25: ; preds = %21, %6, %0
%26 = phi i32 [ 1, %0 ], [ 0, %6 ], [ %23, %21 ]
ret i32 %26
}