#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 array_new_capacity_(size_t capacity, size_t size) {
  const size_t MIN_INCREMENT = 16;
  const size_t MAX_INCREMENT = 1024;
  while (capacity < size) {
    if (capacity < MIN_INCREMENT) {
      capacity += MIN_INCREMENT;
    } else if (capacity > MAX_INCREMENT) {
      capacity += MAX_INCREMENT;
    } else {
      capacity += capacity;
    }
  }
  return capacity;
}


x86 assembly (clang, -O0):
<array_new_capacity_>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x10,-0x18(%rbp)
movq   $0x400,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    117d <array_new_capacity_+0x7d>
cmpq   $0x10,-0x8(%rbp)
jae    1146 <array_new_capacity_+0x46>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <array_new_capacity_+0x78>
cmpq   $0x400,-0x8(%rbp)
jbe    1167 <array_new_capacity_+0x67>
mov    -0x8(%rbp),%rax
add    $0x400,%rax
mov    %rax,-0x8(%rbp)
jmp    1173 <array_new_capacity_+0x73>
mov    -0x8(%rbp),%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <array_new_capacity_+0x78>
jmp    111c <array_new_capacity_+0x1c>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_new_capacity_>:
mov    %rdi,%rax
cmp    %rsi,%rdi
jb     1119 <array_new_capacity_+0x19>
ret
nopl   0x0(%rax)
add    $0x10,%rax
cmp    %rsi,%rax
jae    1108 <array_new_capacity_+0x8>
cmp    $0xf,%rax
jbe    1110 <array_new_capacity_+0x10>
cmp    $0x401,%rax
jb     1130 <array_new_capacity_+0x30>
add    $0x400,%rax
jmp    1114 <array_new_capacity_+0x14>
nop
add    %rax,%rax
jmp    1114 <array_new_capacity_+0x14>

LLVM IR (-O0):
define i64 @array_new_capacity_(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
store i64 16, i64* %5
store i64 1024, i64* %6
br label %7
7: ; preds = %28, %2
%8 = load i64, i64* %3
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %29
11: ; preds = %7
%12 = load i64, i64* %3
%13 = icmp ult i64 %12, 16
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i64, i64* %3
%16 = add i64 %15, 16
store i64 %16, i64* %3
br label %28
17: ; preds = %11
%18 = load i64, i64* %3
%19 = icmp ugt i64 %18, 1024
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i64, i64* %3
%22 = add i64 %21, 1024
store i64 %22, i64* %3
br label %27
23: ; preds = %17
%24 = load i64, i64* %3
%25 = load i64, i64* %3
%26 = add i64 %25, %24
store i64 %26, i64* %3
br label %27
27: ; preds = %23, %20
br label %28
28: ; preds = %27, %14
br label %7
29: ; preds = %7
%30 = load i64, i64* %3
ret i64 %30
}

LLVM IR (-O2):
define i64 @array_new_capacity_(i64 %0, i64 %1) {
%3 = icmp ult i64 %0, %1
br i1 %3, label %4, label %18
4: ; preds = %2, %15
%5 = phi i64 [ %16, %15 ], [ %0, %2 ]
%6 = icmp ult i64 %5, 16
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = add nuw nsw i64 %5, 16
br label %15
9: ; preds = %4
%10 = icmp ugt i64 %5, 1024
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = add i64 %5, 1024
br label %15
13: ; preds = %9
%14 = shl nuw nsw i64 %5, 1
br label %15
15: ; preds = %11, %13, %7
%16 = phi i64 [ %8, %7 ], [ %12, %11 ], [ %14, %13 ]
%17 = icmp ult i64 %16, %1
br i1 %17, label %4, label %18
18: ; preds = %15, %2
%19 = phi i64 [ %0, %2 ], [ %16, %15 ]
ret i64 %19
}