#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__ emalloc(int);
scalar_t__ erealloc(int *, int);
int /*<<< orphan*/ pow2(int);
void grow_iarray(int nar, int **arpp) {
  if (nar == 0) {
    *arpp = (int *)emalloc(1 * sizeof(int));
    return;
  }
  if (!pow2(nar))
    return;
  *arpp = (int *)erealloc(*arpp, 2 * nar * sizeof(int));
}


x86 assembly (clang, -O0):
<grow_iarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1162 <grow_iarray+0x32>
mov    $0x4,%edi
call   1050 <emalloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    119c <grow_iarray+0x6c>
mov    -0x4(%rbp),%edi
call   1030 <pow2@plt>
cmp    $0x0,%eax
jne    1178 <grow_iarray+0x48>
jmp    119c <grow_iarray+0x6c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1040 <erealloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grow_iarray>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
test   %edi,%edi
je     1154 <grow_iarray+0x24>
mov    %edi,%ebp
call   1030 <pow2@plt>
test   %eax,%eax
je     1161 <grow_iarray+0x31>
mov    (%rbx),%rdi
shl    $0x3,%ebp
mov    %ebp,%esi
call   1040 <erealloc@plt>
jmp    115e <grow_iarray+0x2e>
mov    $0x4,%edi
call   1050 <emalloc@plt>
mov    %rax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @grow_iarray(i32 %0, i32** %1) {
%3 = alloca i32
%4 = alloca i32**
store i32 %0, i32* %3
store i32** %1, i32*** %4
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = call i64 @emalloc(i32 4)
%9 = inttoptr i64 %8 to i32*
%10 = load i32**, i32*** %4
store i32* %9, i32** %10
br label %27
11: ; preds = %2
%12 = load i32, i32* %3
%13 = call i32 @pow2(i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %11
br label %27
16: ; preds = %11
%17 = load i32**, i32*** %4
%18 = load i32*, i32** %17
%19 = load i32, i32* %3
%20 = mul nsw i32 2, %19
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 4
%23 = trunc i64 %22 to i32
%24 = call i64 @erealloc(i32* %18, i32 %23)
%25 = inttoptr i64 %24 to i32*
%26 = load i32**, i32*** %4
store i32* %25, i32** %26
br label %27
27: ; preds = %16, %15, %7
ret void
}

LLVM IR (-O2):
define void @grow_iarray(i32 %0, i32** nocapture %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i64 @emalloc(i32 4)
br label %13
6: ; preds = %2
%7 = tail call i32 @pow2(i32 %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = load i32*, i32** %1
%11 = shl i32 %0, 3
%12 = tail call i64 @erealloc(i32* %10, i32 %11)
br label %13
13: ; preds = %4, %9
%14 = phi i64 [ %12, %9 ], [ %5, %4 ]
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %1
br label %16
16: ; preds = %13, %6
ret void
}