#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int *realloc(int *, size_t);
int /*<<< orphan*/ stderr;
int *get_buf(int nump) {
  static int *buf;
  static size_t buf_size;
  if ((size_t)nump > buf_size) {
    buf_size *= 2;
    if (nump > buf_size)
      buf_size = nump + 64;
    int *bufn = realloc(buf, buf_size * sizeof(int));
    if (bufn == NULL) {
      fprintf(stderr, "memory allocation error\n");
      exit(1);
    }
    buf = bufn;
  }
  return buf;
}


x86 assembly (clang, -O0):
<get_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
cmp    0x2f02(%rip),%rax
jbe    11ce <get_buf+0x9e>
mov    0x2ef5(%rip),%rax
shl    $0x1,%rax
mov    %rax,0x2eea(%rip)
movslq -0x4(%rbp),%rax
cmp    0x2edf(%rip),%rax
jbe    117e <get_buf+0x4e>
mov    -0x4(%rbp),%eax
add    $0x40,%eax
cltq
mov    %rax,0x2eca(%rip)
mov    0x2ebb(%rip),%rdi
mov    0x2ebc(%rip),%rsi
shl    $0x2,%rsi
call   1040 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <get_buf+0x93>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,0x2e72(%rip)
mov    0x2e6b(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_buf>:
push   %rax
movslq %edi,%rcx
mov    0x2f0d(%rip),%rax
cmp    %rcx,%rax
jae    1175 <get_buf+0x45>
add    %rax,%rax
lea    0x40(%rcx),%edx
cmp    %rcx,%rax
movslq %edx,%rsi
cmovae %rax,%rsi
mov    %rsi,0x2ef1(%rip)
mov    0x2ee2(%rip),%rdi
shl    $0x2,%rsi
call   1040 <realloc@plt>
test   %rax,%rax
je     117e <get_buf+0x4e>
mov    %rax,0x2ecd(%rip)
pop    %rcx
ret
mov    0x2ec4(%rip),%rax
pop    %rcx
ret
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@get_buf.buf = internal global i32* null
@get_buf.buf_size = internal global i64 0
@stderr = global i32 0
@.str = [25 x i8] c"memory allocation error\0A\00"
define i32* @get_buf(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = sext i32 %4 to i64
%6 = load i64, i64* @get_buf.buf_size
%7 = icmp ugt i64 %5, %6
br i1 %7, label %8, label %32
8: ; preds = %1
%9 = load i64, i64* @get_buf.buf_size
%10 = mul i64 %9, 2
store i64 %10, i64* @get_buf.buf_size
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = load i64, i64* @get_buf.buf_size
%14 = icmp ugt i64 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 64
%18 = sext i32 %17 to i64
store i64 %18, i64* @get_buf.buf_size
br label %19
19: ; preds = %15, %8
%20 = load i32*, i32** @get_buf.buf
%21 = load i64, i64* @get_buf.buf_size
%22 = mul i64 %21, 4
%23 = call i32* @realloc(i32* %20, i64 %22)
store i32* %23, i32** %3
%24 = load i32*, i32** %3
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %19
%31 = load i32*, i32** %3
store i32* %31, i32** @get_buf.buf
br label %32
32: ; preds = %30, %1
%33 = load i32*, i32** @get_buf.buf
ret i32* %33
}

LLVM IR (-O2):
@get_buf.buf = internal unnamed_addr global i32* null
@get_buf.buf_size = internal unnamed_addr global i64 0
@stderr = global i32 0
@.str = [25 x i8] c"memory allocation error\0A\00"
define i32* @get_buf(i32 %0) {
%2 = sext i32 %0 to i64
%3 = load i64, i64* @get_buf.buf_size
%4 = icmp ult i64 %3, %2
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = load i32*, i32** @get_buf.buf
br label %22
7: ; preds = %1
%8 = shl i64 %3, 1
%9 = icmp ult i64 %8, %2
%10 = add nsw i32 %0, 64
%11 = sext i32 %10 to i64
%12 = select i1 %9, i64 %11, i64 %8
store i64 %12, i64* @get_buf.buf_size
%13 = load i32*, i32** @get_buf.buf
%14 = shl i64 %12, 2
%15 = tail call i32* @realloc(i32* %13, i64 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %7
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %7
store i32* %15, i32** @get_buf.buf
br label %22
22: ; preds = %5, %21
%23 = phi i32* [ %6, %5 ], [ %15, %21 ]
ret i32* %23
}