#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 resize_buffer(char **buffer, size_t *size) {
  if (!*buffer && *size == 0)
    *size = 16;
  char *temp = realloc(*buffer, *size);
  if (!temp)
    return false;
  *buffer = temp;
  return true;
}


x86 assembly (clang, -O0):
<resize_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1147 <resize_buffer+0x37>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1147 <resize_buffer+0x37>
mov    -0x18(%rbp),%rax
movq   $0x10,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1030 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1175 <resize_buffer+0x65>
movl   $0x0,-0x4(%rbp)
jmp    1187 <resize_buffer+0x77>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resize_buffer>:
push   %rbx
mov    %rsi,%rax
mov    %rdi,%rbx
mov    (%rdi),%rdi
mov    (%rsi),%rsi
test   %rdi,%rdi
jne    1133 <resize_buffer+0x23>
test   %rsi,%rsi
jne    1133 <resize_buffer+0x23>
movq   $0x10,(%rax)
mov    $0x10,%esi
call   1030 <realloc@plt>
test   %rax,%rax
je     1147 <resize_buffer+0x37>
mov    %rax,(%rbx)
mov    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

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