#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*/ assert(int);
char *myrealloc(char *, int);
void grow_mem_if_needed(char **what, int *cur_len, int requested_len) {
  char changed = 0;
  assert(requested_len > 0);
  while (*cur_len < requested_len) {
    changed = 1;
    if (*cur_len)
      (*cur_len) *= 2;
    else
      *cur_len = 128;
  }
  if (changed)
    *what = myrealloc(*what, *cur_len);
}


x86 assembly (clang, -O0):
<grow_mem_if_needed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
cmpl   $0x0,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
jge    1187 <grow_mem_if_needed+0x67>
movb   $0x1,-0x15(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
je     1178 <grow_mem_if_needed+0x58>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1182 <grow_mem_if_needed+0x62>
mov    -0x10(%rbp),%rax
movl   $0x80,(%rax)
jmp    1148 <grow_mem_if_needed+0x28>
cmpb   $0x0,-0x15(%rbp)
je     11ad <grow_mem_if_needed+0x8d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1040 <myrealloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grow_mem_if_needed>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %edx,%edx
setg   %dil
call   1030 <assert@plt>
mov    (%rbx),%eax
cmp    %ebp,%eax
jge    116f <grow_mem_if_needed+0x4f>
mov    $0x80,%ecx
mov    %eax,%esi
cs nopw 0x0(%rax,%rax,1)
test   %esi,%esi
lea    (%rsi,%rsi,1),%edx
mov    %edx,%esi
cmove  %ecx,%esi
cmp    %ebp,%esi
jl     1150 <grow_mem_if_needed+0x30>
mov    %esi,(%rbx)
cmp    %ebp,%eax
jge    116f <grow_mem_if_needed+0x4f>
mov    (%r14),%rdi
call   1040 <myrealloc@plt>
mov    %rax,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @grow_mem_if_needed(i8** %0, i32* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i8 0, i8* %7
%8 = load i32, i32* %6
%9 = icmp sgt i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
br label %12
12: ; preds = %27, %3
%13 = load i32*, i32** %5
%14 = load i32, i32* %13
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %28
17: ; preds = %12
store i8 1, i8* %7
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32*, i32** %5
%23 = load i32, i32* %22
%24 = mul nsw i32 %23, 2
store i32 %24, i32* %22
br label %27
25: ; preds = %17
%26 = load i32*, i32** %5
store i32 128, i32* %26
br label %27
27: ; preds = %25, %21
br label %12
28: ; preds = %12
%29 = load i8, i8* %7
%30 = icmp ne i8 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i8**, i8*** %4
%33 = load i8*, i8** %32
%34 = load i32*, i32** %5
%35 = load i32, i32* %34
%36 = call i8* @myrealloc(i8* %33, i32 %35)
%37 = load i8**, i8*** %4
store i8* %36, i8** %37
br label %38
38: ; preds = %31, %28
ret void
}

LLVM IR (-O2):
define void @grow_mem_if_needed(i8** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, %2
br i1 %8, label %9, label %19
9: ; preds = %3, %9
%10 = phi i32 [ %13, %9 ], [ %7, %3 ]
%11 = icmp eq i32 %10, 0
%12 = shl nsw i32 %10, 1
%13 = select i1 %11, i32 128, i32 %12
%14 = icmp slt i32 %13, %2
br i1 %14, label %9, label %15
15: ; preds = %9
store i32 %13, i32* %1
br i1 %8, label %16, label %19
16: ; preds = %15
%17 = load i8*, i8** %0
%18 = tail call i8* @myrealloc(i8* %17, i32 %13)
store i8* %18, i8** %0
br label %19
19: ; preds = %3, %16, %15
ret void
}