#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 */
void *mzalloc(int);
void *realloc(void *, int);
void resize_if_full(void **array, int curr, int *capacity, int size) {
  if (*capacity == 0) {
    *capacity = 100;
    *array = mzalloc(size * (*capacity));
  } else if (curr == *capacity) {
    *array = realloc(*array, size * (*capacity) * 2);
    *capacity *= 2;
  }
}


x86 assembly (clang, -O0):
<resize_if_full>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    116b <resize_if_full+0x4b>
mov    -0x18(%rbp),%rax
movl   $0x64,(%rax)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rax
imul   (%rax),%edi
call   1030 <mzalloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11ad <resize_if_full+0x8d>
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jne    11a8 <resize_if_full+0x88>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rax
imul   (%rax),%esi
shl    $0x1,%esi
call   1040 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11ad <resize_if_full+0x8d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resize_if_full>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
mov    (%rdx),%eax
test   %eax,%eax
je     114a <resize_if_full+0x2a>
cmp    %esi,%eax
jne    115b <resize_if_full+0x3b>
mov    (%r14),%rdi
imul   %esi,%ecx
add    %ecx,%ecx
mov    %ecx,%esi
call   1040 <realloc@plt>
mov    %rax,(%r14)
shll   (%rbx)
jmp    115b <resize_if_full+0x3b>
movl   $0x64,(%rbx)
imul   $0x64,%ecx,%edi
call   1030 <mzalloc@plt>
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @resize_if_full(i8** nocapture %0, i32 %1, i32* nocapture %2, i32 %3) {
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
store i32 100, i32* %2
%8 = mul nsw i32 %3, 100
%9 = tail call i8* @mzalloc(i32 %8)
store i8* %9, i8** %0
br label %19
10: ; preds = %4
%11 = icmp eq i32 %5, %1
br i1 %11, label %12, label %19
12: ; preds = %10
%13 = load i8*, i8** %0
%14 = shl i32 %3, 1
%15 = mul i32 %14, %1
%16 = tail call i8* @realloc(i8* %13, i32 %15)
store i8* %16, i8** %0
%17 = load i32, i32* %2
%18 = shl nsw i32 %17, 1
store i32 %18, i32* %2
br label %19
19: ; preds = %10, %12, %7
ret void
}