#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 */
size_t *realloc(size_t *, size_t);
bool inc_arr_sz(size_t **valarr, size_t *arr_maxsz, size_t maxsz) {
  size_t *valarr_tmpptr;
  if (*arr_maxsz > maxsz / 2)
    *arr_maxsz = maxsz;
  else
    *arr_maxsz *= 2;
  if ((valarr_tmpptr = realloc(*valarr, *arr_maxsz * sizeof(size_t))) == NULL)
    return false;
  *valarr = valarr_tmpptr;
  return true;
}


x86 assembly (clang, -O0):
<inc_arr_sz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
shr    $0x1,%rcx
cmp    %rcx,%rax
jbe    114c <inc_arr_sz+0x3c>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    115a <inc_arr_sz+0x4a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
shl    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
shl    $0x3,%rsi
call   1030 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    118b <inc_arr_sz+0x7b>
movl   $0x0,-0x4(%rbp)
jmp    119d <inc_arr_sz+0x8d>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inc_arr_sz>:
push   %rbx
mov    (%rsi),%rcx
mov    %rdx,%rbx
shr    %rbx
lea    (%rcx,%rcx,1),%rax
cmp    %rbx,%rcx
cmova  %rdx,%rax
mov    %rdi,%rbx
mov    %rax,(%rsi)
mov    (%rdi),%rdi
shl    $0x3,%rax
mov    %rax,%rsi
call   1030 <realloc@plt>
test   %rax,%rax
je     1149 <inc_arr_sz+0x39>
mov    %rax,(%rbx)
mov    $0x1,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @inc_arr_sz(i64** nocapture %0, i64* nocapture %1, i64 %2) {
%4 = load i64, i64* %1
%5 = lshr i64 %2, 1
%6 = icmp ugt i64 %4, %5
%7 = shl i64 %4, 1
%8 = select i1 %6, i64 %2, i64 %7
store i64 %8, i64* %1
%9 = load i64*, i64** %0
%10 = shl i64 %8, 3
%11 = tail call i64* @realloc(i64* %9, i64 %10)
%12 = icmp eq i64* %11, null
br i1 %12, label %14, label %13
13: ; preds = %3
store i64* %11, i64** %0
br label %14
14: ; preds = %3, %13
%15 = phi i32 [ 1, %13 ], [ 0, %3 ]
ret i32 %15
}