#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *_TOML_increaseBuffer(char *oldBuffer, int *size) {
  int newSize = *size + 1024;
  char *newBuffer = malloc(newSize + 1);
  newBuffer[newSize] = 0;
  if (oldBuffer) {
    strncpy(newBuffer, oldBuffer, *size + 1);
    free(oldBuffer);
  }
  *size = newSize;
  return newBuffer;
}


x86 assembly (clang, -O0):
<_TOML_increaseBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x400,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x8(%rbp)
je     1193 <_TOML_increaseBuffer+0x63>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
add    $0x1,%edx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_TOML_increaseBuffer>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
movslq (%rsi),%rbx
lea    0x400(%rbx),%r12
lea    0x401(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%r13
movb   $0x0,0x400(%rax,%rbx,1)
test   %r15,%r15
je     117a <_TOML_increaseBuffer+0x4a>
lea    0x1(%rbx),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <strncpy@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12d,(%r14)
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @_TOML_increaseBuffer(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = add nsw i32 %8, 1024
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8 0, i8* %16
%17 = load i8*, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %28
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = load i8*, i8** %3
%22 = load i32*, i32** %4
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
%25 = call i32 @strncpy(i8* %20, i8* %21, i32 %24)
%26 = load i8*, i8** %3
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %19, %2
%29 = load i32, i32* %5
%30 = load i32*, i32** %4
store i32 %29, i32* %30
%31 = load i8*, i8** %6
ret i8* %31
}

LLVM IR (-O2):
define i8* @_TOML_increaseBuffer(i8* %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = add nsw i32 %3, 1024
%5 = add nsw i32 %3, 1025
%6 = tail call i8* @malloc(i32 %5)
%7 = sext i32 %4 to i64
%8 = getelementptr inbounds i8, i8* %6, i64 %7
store i8 0, i8* %8
%9 = icmp eq i8* %0, null
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = add nsw i32 %3, 1
%12 = tail call i32 @strncpy(i8* %6, i8* %0, i32 %11)
%13 = tail call i32 @free(i8* %0)
br label %14
14: ; preds = %10, %2
store i32 %4, i32* %1
ret i8* %6
}