#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*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(int);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ stderr;
void expand_buf(char **b_f, int *b_flen) {
  if (((*b_f) == NULL) || ((*b_flen) == 0)) {
    (*b_f) = (char *)malloc(256);
    if ((*b_f) == NULL) {
      fprintf(stderr, "Unable to allocate %d byte CSV field buffer.\n", 256);
      abort();
    }
    (*b_flen) = 256;
  } else {
    (*b_flen) += 1024;
    (*b_f) = (char *)realloc((*b_f), (*b_flen));
    if ((*b_f) == NULL) {
      fprintf(stderr, "Unable to expand CSV field buffer to %d bytes.\n",
              (*b_flen));
      abort();
    }
  }
}


x86 assembly (clang, -O0):
<expand_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     116b <expand_buf+0x2b>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11bd <expand_buf+0x7d>
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ae <expand_buf+0x6e>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
mov    $0x100,%edx
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rax
movl   $0x100,(%rax)
jmp    121c <expand_buf+0xdc>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x400,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1060 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1217 <expand_buf+0xd7>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe23(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    121c <expand_buf+0xdc>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_buf>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1184 <expand_buf+0x44>
mov    (%r14),%esi
test   %esi,%esi
je     1184 <expand_buf+0x44>
add    $0x400,%esi
mov    %esi,(%r14)
call   1060 <realloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
jne    119d <expand_buf+0x5d>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%edx
lea    0xeac(%rip),%rsi
jmp    11ba <expand_buf+0x7a>
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     11a5 <expand_buf+0x65>
movl   $0x100,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
mov    $0x100,%edx
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"Unable to allocate %d byte CSV field buffer.\0A\00"
@.str.1 = [48 x i8] c"Unable to expand CSV field buffer to %d bytes.\0A\00"
define void @expand_buf(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
store i8** %0, i8*** %3
store i32* %1, i32** %4
%5 = load i8**, i8*** %3
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32*, i32** %4
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %8, %2
%13 = call i64 @malloc(i32 256)
%14 = inttoptr i64 %13 to i8*
%15 = load i8**, i8*** %3
store i8* %14, i8** %15
%16 = load i8**, i8*** %3
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 256)
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %12
%24 = load i32*, i32** %4
store i32 256, i32* %24
br label %46
25: ; preds = %8
%26 = load i32*, i32** %4
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1024
store i32 %28, i32* %26
%29 = load i8**, i8*** %3
%30 = load i8*, i8** %29
%31 = load i32*, i32** %4
%32 = load i32, i32* %31
%33 = call i64 @realloc(i8* %30, i32 %32)
%34 = inttoptr i64 %33 to i8*
%35 = load i8**, i8*** %3
store i8* %34, i8** %35
%36 = load i8**, i8*** %3
%37 = load i8*, i8** %36
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %45
39: ; preds = %25
%40 = load i32, i32* @stderr
%41 = load i32*, i32** %4
%42 = load i32, i32* %41
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = call i32 (...) @abort()
unreachable
45: ; preds = %25
br label %46
46: ; preds = %45, %23
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"Unable to allocate %d byte CSV field buffer.\0A\00"
@.str.1 = [48 x i8] c"Unable to expand CSV field buffer to %d bytes.\0A\00"
define void @expand_buf(i8** nocapture %0, i32* nocapture %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %5, %2
%9 = tail call i64 @malloc(i32 256)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %0
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 256)
%15 = tail call i32 (...) @abort()
unreachable
16: ; preds = %8
store i32 256, i32* %1
br label %27
17: ; preds = %5
%18 = add nsw i32 %6, 1024
store i32 %18, i32* %1
%19 = tail call i64 @realloc(i8* %3, i32 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %0
%21 = icmp eq i64 %19, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i32, i32* %1
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = tail call i32 (...) @abort()
unreachable
27: ; preds = %17, %16
ret void
}