#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 /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, int);
void expand_line_buffer(char **adrBuf, int *ptrSize, char **adrPtr) {
  char *newbuf;
  int newsize;
  newsize = *ptrSize + 512;
  newbuf = (char *)malloc(newsize);
  if (newbuf == 0) {
    fprintf(stderr, "Insufficient memory for line");
    exit(1);
  }
  if (*ptrSize == 0) {
    if (adrPtr) {
      *adrPtr = newbuf;
    }
  } else {
    strncpy(newbuf, *adrBuf, *ptrSize);
    if (adrPtr) {
      *adrPtr += newbuf - *adrBuf;
    }
    free(*adrBuf);
  }
  *adrBuf = newbuf;
  *ptrSize = newsize;
}


x86 assembly (clang, -O0):
<expand_line_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x200,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a8 <expand_line_buffer+0x58>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11d0 <expand_line_buffer+0x80>
cmpq   $0x0,-0x18(%rbp)
je     11cb <expand_line_buffer+0x7b>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1215 <expand_line_buffer+0xc5>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1040 <strncpy@plt>
cmpq   $0x0,-0x18(%rbp)
je     1209 <expand_line_buffer+0xb9>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
sub    %rax,%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_line_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    $0x200,%ebp
add    (%rsi),%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ba <expand_line_buffer+0x6a>
mov    %rax,%rbx
mov    (%r12),%edx
test   %edx,%edx
je     11a2 <expand_line_buffer+0x52>
mov    (%r14),%rsi
mov    %rbx,%rdi
call   1040 <strncpy@plt>
test   %r15,%r15
je     1198 <expand_line_buffer+0x48>
mov    %rbx,%rax
sub    (%r14),%rax
add    %rax,(%r15)
mov    (%r14),%rdi
call   1030 <free@plt>
jmp    11aa <expand_line_buffer+0x5a>
test   %r15,%r15
je     11aa <expand_line_buffer+0x5a>
mov    %rbx,(%r15)
mov    %rbx,(%r14)
mov    %ebp,(%r12)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Insufficient memory for line\00"
define void @expand_line_buffer(i8** %0, i32* %1, i8** %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i8** %2, i8*** %6
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 512
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %3
%22 = load i32*, i32** %5
%23 = load i32, i32* %22
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i8**, i8*** %6
%27 = icmp ne i8** %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %7
%30 = load i8**, i8*** %6
store i8* %29, i8** %30
br label %31
31: ; preds = %28, %25
br label %55
32: ; preds = %21
%33 = load i8*, i8** %7
%34 = load i8**, i8*** %4
%35 = load i8*, i8** %34
%36 = load i32*, i32** %5
%37 = load i32, i32* %36
%38 = call i32 @strncpy(i8* %33, i8* %35, i32 %37)
%39 = load i8**, i8*** %6
%40 = icmp ne i8** %39, null
br i1 %40, label %41, label %51
41: ; preds = %32
%42 = load i8*, i8** %7
%43 = load i8**, i8*** %4
%44 = load i8*, i8** %43
%45 = ptrtoint i8* %42 to i64
%46 = ptrtoint i8* %44 to i64
%47 = sub i64 %45, %46
%48 = load i8**, i8*** %6
%49 = load i8*, i8** %48
%50 = getelementptr inbounds i8, i8* %49, i64 %47
store i8* %50, i8** %48
br label %51
51: ; preds = %41, %32
%52 = load i8**, i8*** %4
%53 = load i8*, i8** %52
%54 = call i32 @free(i8* %53)
br label %55
55: ; preds = %51, %31
%56 = load i8*, i8** %7
%57 = load i8**, i8*** %4
store i8* %56, i8** %57
%58 = load i32, i32* %8
%59 = load i32*, i32** %5
store i32 %58, i32* %59
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Insufficient memory for line\00"
define void @expand_line_buffer(i8** nocapture %0, i32* nocapture %1, i8** %2) {
%4 = load i32, i32* %1
%5 = add nsw i32 %4, 512
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %3
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = icmp eq i8** %2, null
br i1 %17, label %32, label %18
18: ; preds = %16
store i8* %7, i8** %2
br label %32
19: ; preds = %13
%20 = load i8*, i8** %0
%21 = tail call i32 @strncpy(i8* %7, i8* %20, i32 %14)
%22 = icmp eq i8** %2, null
br i1 %22, label %29, label %23
23: ; preds = %19
%24 = load i8*, i8** %0
%25 = ptrtoint i8* %24 to i64
%26 = sub i64 %6, %25
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i64 %26
store i8* %28, i8** %2
br label %29
29: ; preds = %23, %19
%30 = load i8*, i8** %0
%31 = tail call i32 @free(i8* %30)
br label %32
32: ; preds = %16, %18, %29
store i8* %7, i8** %0
store i32 %5, i32* %1
ret void
}