#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 */
char *realloc(char *, size_t);
bool make_space(char **buf, size_t *buflen, size_t position) {
  char *tmp;
  if (position < *buflen) {
    return true;
  }
  tmp = realloc(*buf, (*buflen) * 2);
  if (tmp == NULL) {
    return false;
  }
  *buf = tmp;
  *buflen *= 2;
  return true;
}


x86 assembly (clang, -O0):
<make_space>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jae    1141 <make_space+0x31>
movl   $0x1,-0x4(%rbp)
jmp    1193 <make_space+0x83>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
shl    $0x1,%rsi
call   1030 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1173 <make_space+0x63>
movl   $0x0,-0x4(%rbp)
jmp    1193 <make_space+0x83>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
shl    $0x1,%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_space>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    (%rsi),%rsi
mov    $0x1,%ebp
cmp    %rdx,%rsi
ja     1141 <make_space+0x31>
mov    %rdi,%r14
mov    (%rdi),%rdi
add    %rsi,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
je     113f <make_space+0x2f>
mov    %rax,(%r14)
shlq   (%rbx)
jmp    1141 <make_space+0x31>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @make_space(i8** %0, i64* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i8*
store i8** %0, i8*** %5
store i64* %1, i64** %6
store i64 %2, i64* %7
%9 = load i64, i64* %7
%10 = load i64*, i64** %6
%11 = load i64, i64* %10
%12 = icmp ult i64 %9, %11
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 1, i32* %4
br label %30
14: ; preds = %3
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = load i64*, i64** %6
%18 = load i64, i64* %17
%19 = mul i64 %18, 2
%20 = call i8* @realloc(i8* %16, i64 %19)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %14
store i32 0, i32* %4
br label %30
24: ; preds = %14
%25 = load i8*, i8** %8
%26 = load i8**, i8*** %5
store i8* %25, i8** %26
%27 = load i64*, i64** %6
%28 = load i64, i64* %27
%29 = mul i64 %28, 2
store i64 %29, i64* %27
store i32 1, i32* %4
br label %30
30: ; preds = %24, %23, %13
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @make_space(i8** nocapture %0, i64* nocapture %1, i64 %2) {
%4 = load i64, i64* %1
%5 = icmp ugt i64 %4, %2
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = load i8*, i8** %0
%8 = shl i64 %4, 1
%9 = tail call i8* @realloc(i8* %7, i64 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %6
store i8* %9, i8** %0
%12 = load i64, i64* %1
%13 = shl i64 %12, 1
store i64 %13, i64* %1
br label %14
14: ; preds = %6, %3, %11
%15 = phi i32 [ 1, %11 ], [ 1, %3 ], [ 0, %6 ]
ret i32 %15
}