#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));
  *i = 12345;
  int *i2 = proctal_darr_global_realloc(i, sizeof(int) * 2);
  if (i2 == NULL) {
    fprintf(stderr, "Failed to allocate a new block.\n");
    return 1;
  }
  if (block_size(i2) != sizeof(int) * 2) {
    fprintf(stderr, "Wrong block size.\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    $0x4,%esi
call   1030 <proctal_darr_global_realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x3039,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
call   1030 <proctal_darr_global_realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a9 <main+0x69>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1220 <main+0xe0>
mov    -0x18(%rbp),%rdi
call   1050 <block_size@plt>
cltq
cmp    $0x8,%rax
je     11df <main+0x9f>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1220 <main+0xe0>
mov    -0x18(%rbp),%rax
cmpl   $0x3039,(%rax)
je     1210 <main+0xd0>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1220 <main+0xe0>
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    $0x4,%esi
call   1030 <proctal_darr_global_realloc@plt>
movl   $0x3039,(%rax)
mov    %rax,%rdi
mov    $0x8,%esi
call   1030 <proctal_darr_global_realloc@plt>
test   %rax,%rax
je     1189 <main+0x49>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <block_size@plt>
cmp    $0x8,%eax
jne    119b <main+0x5b>
cmpl   $0x3039,(%rbx)
jne    11ad <main+0x6d>
mov    %rbx,%rdi
call   1040 <proctal_darr_global_free@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
jmp    11bd <main+0x7d>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
jmp    11bd <main+0x7d>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Failed to allocate a new block.\0A\00"
@.str.1 = [19 x i8] c"Wrong block size.\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 4)
store i32* %4, i32** %2
%5 = load i32*, i32** %2
store i32 12345, i32* %5
%6 = load i32*, i32** %2
%7 = call i32* @proctal_darr_global_realloc(i32* %6, i32 8)
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %31
13: ; preds = %0
%14 = load i32*, i32** %3
%15 = call i32 @block_size(i32* %14)
%16 = sext i32 %15 to i64
%17 = icmp ne i64 %16, 8
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %31
21: ; preds = %13
%22 = load i32*, i32** %3
%23 = load i32, i32* %22
%24 = icmp ne i32 %23, 12345
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %31
28: ; preds = %21
%29 = load i32*, i32** %3
%30 = call i32 @proctal_darr_global_free(i32* %29)
store i32 0, i32* %1
br label %31
31: ; preds = %28, %25, %18, %10
%32 = load i32, i32* %1
ret i32 %32
}

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