#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) * 2);
  i[0] = 12345;
  i[1] = 54321;
  int *i2 = proctal_darr_global_realloc(i, sizeof(int));
  if (i2 == NULL) {
    fprintf(stderr, "Unexpectedly returned NULL.\n");
    return 1;
  }
  if (block_size(i2) != sizeof(int)) {
    fprintf(stderr, "Expected to create a new block.\n");
    return 1;
  }
  if (*i2 != 12345) {
    fprintf(stderr, "Original value was lost.\n");
    return 1;
  }
  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    $0x8,%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),%rdi
mov    $0x4,%esi
call   1030 <proctal_darr_global_realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b4 <main+0x74>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122b <main+0xeb>
mov    -0x18(%rbp),%rdi
call   1050 <block_size@plt>
cltq
cmp    $0x4,%rax
je     11ea <main+0xaa>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122b <main+0xeb>
mov    -0x18(%rbp),%rax
cmpl   $0x3039,(%rax)
je     121b <main+0xdb>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122b <main+0xeb>
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    $0x8,%esi
call   1030 <proctal_darr_global_realloc@plt>
movabs $0xd43100003039,%rcx
mov    %rcx,(%rax)
mov    %rax,%rdi
mov    $0x4,%esi
call   1030 <proctal_darr_global_realloc@plt>
test   %rax,%rax
je     1190 <main+0x50>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <block_size@plt>
cmp    $0x4,%eax
jne    11a2 <main+0x62>
cmpl   $0x3039,(%rbx)
jne    11b4 <main+0x74>
mov    %rbx,%rdi
call   1040 <proctal_darr_global_free@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
jmp    11c4 <main+0x84>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
jmp    11c4 <main+0x84>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%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 = [33 x i8] c"Expected 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 8)
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 = call i32* @proctal_darr_global_realloc(i32* %9, i32 4)
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %34
16: ; preds = %0
%17 = load i32*, i32** %3
%18 = call i32 @block_size(i32* %17)
%19 = sext i32 %18 to i64
%20 = icmp ne i64 %19, 4
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %34
24: ; preds = %16
%25 = load i32*, i32** %3
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 12345
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %34
31: ; preds = %24
%32 = load i32*, i32** %3
%33 = call i32 @proctal_darr_global_free(i32* %32)
store i32 0, i32* %1
br label %34
34: ; preds = %31, %28, %21, %13
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Unexpectedly returned NULL.\0A\00"
@.str.1 = [33 x i8] c"Expected 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 8)
store i32 12345, i32* %1
%2 = getelementptr inbounds i32, i32* %1, i64 1
store i32 54321, i32* %2
%3 = tail call i32* @proctal_darr_global_realloc(i32* %1, i32 4)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %22
8: ; preds = %0
%9 = tail call i32 @block_size(i32* %3)
%10 = icmp eq i32 %9, 4
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %22
14: ; preds = %8
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, 12345
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %14
%21 = tail call i32 @proctal_darr_global_free(i32* %3)
br label %22
22: ; preds = %20, %17, %11, %5
%23 = phi i32 [ 1, %5 ], [ 1, %11 ], [ 1, %17 ], [ 0, %20 ]
ret i32 %23
}