#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 */
scalar_t__ realloc(char *, int);
int strlen(char *);
char *ResizeIfNeeded(char *pBuffer, int *size, int addsize) {
  char *p = pBuffer;
  int newsize = strlen(pBuffer) + addsize + 1;
  if (newsize > *size) {
    newsize += 100;
    p = (char *)realloc(pBuffer, newsize);
    *size = newsize;
  }
  return p;
}


x86 assembly (clang, -O0):
<ResizeIfNeeded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    117e <ResizeIfNeeded+0x5e>
mov    -0x24(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ResizeIfNeeded>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
add    %r15d,%ebp
cmp    (%r14),%ebp
jl     1152 <ResizeIfNeeded+0x32>
add    $0x65,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <realloc@plt>
mov    %rax,%rbx
mov    %ebp,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @ResizeIfNeeded(i8* %0, i32* nocapture %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, %2
%6 = load i32, i32* %1
%7 = icmp slt i32 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = add nsw i32 %5, 101
%10 = tail call i64 @realloc(i8* %0, i32 %9)
%11 = inttoptr i64 %10 to i8*
store i32 %9, i32* %1
br label %12
12: ; preds = %8, %3
%13 = phi i8* [ %11, %8 ], [ %0, %3 ]
ret i8* %13
}