#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 block_size(int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ proctal_darr_global_free(int *);
int *proctal_darr_global_realloc(int *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  int *i = proctal_darr_global_realloc(NULL, sizeof(int) * 3);
  i[0] = 12345;
  i[1] = 54321;
  i[2] = 33333;
  int *i2 = proctal_darr_global_realloc(i, sizeof(int) * 2);
  if (i2 == NULL) {
    fprintf(stderr, "Unexpectedly returned NULL.\n");
    return 1;
  }
  if (block_size(i2) != sizeof(int) * 2) {
    fprintf(stderr, "Did not expect to create a new block.\n");
    return 1;
  }
  if (i2[0] != 12345 || i2[1] != 54321) {
    fprintf(stderr, "Original value was lost.\n");
    return 1;
  }
  i2[0] = 0;
  i2[1] = 0;
  proctal_darr_global_free(i2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
mov    $0xc,%esi
call   1030 <proctal_darr_global_realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x3039,(%rax)
mov    -0x10(%rbp),%rax
movl   $0xd431,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x8235,0x8(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1030 <proctal_darr_global_realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bf <main+0x7f>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125c <main+0x11c>
mov    -0x18(%rbp),%rdi
call   1050 <block_size@plt>
cltq
cmp    $0x8,%rax
je     11f5 <main+0xb5>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125c <main+0x11c>
mov    -0x18(%rbp),%rax
cmpl   $0x3039,(%rax)
jne    1216 <main+0xd6>
mov    -0x18(%rbp),%rax
cmpl   $0xd431,0x4(%rax)
je     1237 <main+0xf7>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125c <main+0x11c>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <proctal_darr_global_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
mov    $0xc,%esi
call   1030 <proctal_darr_global_realloc@plt>
movabs $0xd43100003039,%rcx
mov    %rcx,(%rax)
movl   $0x8235,0x8(%rax)
mov    %rax,%rdi
mov    $0x8,%esi
call   1030 <proctal_darr_global_realloc@plt>
test   %rax,%rax
je     11a7 <main+0x67>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <block_size@plt>
cmp    $0x8,%eax
jne    11b9 <main+0x79>
cmpl   $0x3039,(%rbx)
jne    11cb <main+0x8b>
cmpl   $0xd431,0x4(%rbx)
jne    11cb <main+0x8b>
movq   $0x0,(%rbx)
mov    %rbx,%rdi
call   1040 <proctal_darr_global_free@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
jmp    11db <main+0x9b>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
jmp    11db <main+0x9b>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Unexpectedly returned NULL.\0A\00"
@.str.1 = [39 x i8] c"Did not expect to create a new block.\0A\00"
@.str.2 = [26 x i8] c"Original value was lost.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32* @proctal_darr_global_realloc(i32* null, i32 12)
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = getelementptr inbounds i32, i32* %5, i64 0
store i32 12345, i32* %6
%7 = load i32*, i32** %2
%8 = getelementptr inbounds i32, i32* %7, i64 1
store i32 54321, i32* %8
%9 = load i32*, i32** %2
%10 = getelementptr inbounds i32, i32* %9, i64 2
store i32 33333, i32* %10
%11 = load i32*, i32** %2
%12 = call i32* @proctal_darr_global_realloc(i32* %11, i32 8)
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %46
18: ; preds = %0
%19 = load i32*, i32** %3
%20 = call i32 @block_size(i32* %19)
%21 = sext i32 %20 to i64
%22 = icmp ne i64 %21, 8
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %46
26: ; preds = %18
%27 = load i32*, i32** %3
%28 = getelementptr inbounds i32, i32* %27, i64 0
%29 = load i32, i32* %28
%30 = icmp ne i32 %29, 12345
br i1 %30, label %36, label %31
31: ; preds = %26
%32 = load i32*, i32** %3
%33 = getelementptr inbounds i32, i32* %32, i64 1
%34 = load i32, i32* %33
%35 = icmp ne i32 %34, 54321
br i1 %35, label %36, label %39
36: ; preds = %31, %26
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %46
39: ; preds = %31
%40 = load i32*, i32** %3
%41 = getelementptr inbounds i32, i32* %40, i64 0
store i32 0, i32* %41
%42 = load i32*, i32** %3
%43 = getelementptr inbounds i32, i32* %42, i64 1
store i32 0, i32* %43
%44 = load i32*, i32** %3
%45 = call i32 @proctal_darr_global_free(i32* %44)
store i32 0, i32* %1
br label %46
46: ; preds = %39, %36, %23, %15
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Unexpectedly returned NULL.\0A\00"
@.str.1 = [39 x i8] c"Did not expect to create a new block.\0A\00"
@.str.2 = [26 x i8] c"Original value was lost.\0A\00"
define i32 @main() {
%1 = tail call i32* @proctal_darr_global_realloc(i32* null, i32 12)
store i32 12345, i32* %1
%2 = getelementptr inbounds i32, i32* %1, i64 1
store i32 54321, i32* %2
%3 = getelementptr inbounds i32, i32* %1, i64 2
store i32 33333, i32* %3
%4 = tail call i32* @proctal_darr_global_realloc(i32* %1, i32 8)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %27
9: ; preds = %0
%10 = tail call i32 @block_size(i32* %4)
%11 = icmp eq i32 %10, 8
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %27
15: ; preds = %9
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 12345
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = getelementptr inbounds i32, i32* %4, i64 1
%20 = load i32, i32* %19
%21 = icmp eq i32 %20, 54321
br i1 %21, label %25, label %22
22: ; preds = %18, %15
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %27
25: ; preds = %18
store i32 0, i32* %4
store i32 0, i32* %19
%26 = tail call i32 @proctal_darr_global_free(i32* %4)
br label %27
27: ; preds = %25, %22, %12, %6
%28 = phi i32 [ 1, %6 ], [ 1, %12 ], [ 1, %22 ], [ 0, %25 ]
ret i32 %28
}