#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);
char *enlarge_buffer(char *old, int size, int new_size) {
  char *rtn;
  int it;
  it = 0;
  if ((rtn = malloc(new_size)) == NULL)
    return (NULL);
  while (it < size) {
    rtn[it] = old[it];
    it++;
  }
  free(old);
  return (rtn);
}


x86 assembly (clang, -O0):
<enlarge_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    115c <enlarge_buffer+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <enlarge_buffer+0x82>
jmp    1161 <enlarge_buffer+0x41>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1191 <enlarge_buffer+0x71>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1161 <enlarge_buffer+0x41>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enlarge_buffer>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %edx,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1161 <enlarge_buffer+0x31>
test   %ebp,%ebp
jle    1159 <enlarge_buffer+0x29>
mov    %ebp,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <memcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8* @enlarge_buffer(i8* nocapture %0, i32 %1, i32 %2) {
%4 = tail call i8* @malloc(i32 %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %6
%11 = tail call i32 @free(i8* %0)
br label %12
12: ; preds = %3, %10
ret i8* %4
}