#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);
void size_buffer(char **buffer, size_t *size, size_t requirement) {
  while (*size < requirement) {
    *size = (*size == 0) ? 1024 : 2 * *size;
    *buffer = realloc(*buffer, *size);
  }
}


x86 assembly (clang, -O0):
<size_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jae    118d <size_buffer+0x7d>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1151 <size_buffer+0x41>
mov    $0x400,%eax
mov    %rax,-0x20(%rbp)
jmp    1160 <size_buffer+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1030 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    1124 <size_buffer+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<size_buffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%rcx
cmp    %rdx,%rcx
jae    1161 <size_buffer+0x51>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rdi),%rax
mov    $0x400,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rcx,%rcx,1),%rsi
test   %rcx,%rcx
cmove  %r12,%rsi
mov    %rsi,(%rbx)
mov    %rax,%rdi
call   1030 <realloc@plt>
mov    %rax,(%r15)
mov    (%rbx),%rcx
cmp    %r14,%rcx
jb     1140 <size_buffer+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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