#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 */
char *Malloc(int);
int /*<<< orphan*/ Realloc(void **, int);
int Size(char *);
int /*<<< orphan*/ assert(int);
int strlen(char *);
void _makespace(char **str, int needed) {
  int used;
  if (*str == NULL)
    *str = Malloc(needed + 1);
  else {
    used = strlen(*str) + 1;
    while (used + needed > Size(*str)) {
      int newsize = Size(*str) + 32;
      Realloc((void **)str, newsize);
      assert(Size(*str) == newsize);
    }
  }
}


x86 assembly (clang, -O0):
<_makespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1187 <_makespace+0x37>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <Malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11ff <_makespace+0xaf>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1070 <Size@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jle    11fa <_makespace+0xaa>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1070 <Size@plt>
add    $0x20,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <Realloc@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1070 <Size@plt>
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
jmp    1199 <_makespace+0x49>
jmp    11ff <_makespace+0xaf>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_makespace>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     11ab <_makespace+0x5b>
call   1050 <strlen@plt>
add    %eax,%r14d
add    $0x1,%r14d
xchg   %ax,%ax
mov    (%rbx),%rdi
call   1070 <Size@plt>
cmp    %eax,%r14d
jle    11ba <_makespace+0x6a>
mov    (%rbx),%rdi
call   1070 <Size@plt>
mov    %eax,%ebp
add    $0x20,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <Realloc@plt>
mov    (%rbx),%rdi
call   1070 <Size@plt>
xor    %edi,%edi
cmp    %ebp,%eax
sete   %dil
call   1060 <assert@plt>
jmp    1170 <_makespace+0x20>
add    $0x1,%r14d
mov    %r14d,%edi
call   1030 <Malloc@plt>
mov    %rax,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @_makespace(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
%13 = call i8* @Malloc(i32 %12)
%14 = load i8**, i8*** %3
store i8* %13, i8** %14
br label %44
15: ; preds = %2
%16 = load i8**, i8*** %3
%17 = load i8*, i8** %16
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %20
20: ; preds = %28, %15
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = add nsw i32 %21, %22
%24 = load i8**, i8*** %3
%25 = load i8*, i8** %24
%26 = call i32 @Size(i8* %25)
%27 = icmp sgt i32 %23, %26
br i1 %27, label %28, label %43
28: ; preds = %20
%29 = load i8**, i8*** %3
%30 = load i8*, i8** %29
%31 = call i32 @Size(i8* %30)
%32 = add nsw i32 %31, 32
store i32 %32, i32* %6
%33 = load i8**, i8*** %3
%34 = load i32, i32* %6
%35 = call i32 @Realloc(i8** %33, i32 %34)
%36 = load i8**, i8*** %3
%37 = load i8*, i8** %36
%38 = call i32 @Size(i8* %37)
%39 = load i32, i32* %6
%40 = icmp eq i32 %38, %39
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
br label %20
43: ; preds = %20
br label %44
44: ; preds = %43, %10
ret void
}

LLVM IR (-O2):
define void @_makespace(i8** %0, i32 %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = add nsw i32 %1, 1
%7 = tail call i8* @Malloc(i32 %6)
store i8* %7, i8** %0
br label %28
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %3)
%10 = add i32 %1, 1
%11 = add i32 %10, %9
%12 = load i8*, i8** %0
%13 = tail call i32 @Size(i8* %12)
%14 = icmp sgt i32 %11, %13
br i1 %14, label %15, label %28
15: ; preds = %8, %15
%16 = load i8*, i8** %0
%17 = tail call i32 @Size(i8* %16)
%18 = add nsw i32 %17, 32
%19 = tail call i32 @Realloc(i8** %0, i32 %18)
%20 = load i8*, i8** %0
%21 = tail call i32 @Size(i8* %20)
%22 = icmp eq i32 %21, %18
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = load i8*, i8** %0
%26 = tail call i32 @Size(i8* %25)
%27 = icmp sgt i32 %11, %26
br i1 %27, label %15, label %28
28: ; preds = %15, %8, %5
ret void
}