#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*/ record_stats(void *, size_t, size_t);
size_t resize_double(size_t current, size_t requested, void *data) {
  size_t new_capacity = current;
  if (new_capacity < 2)
    new_capacity = requested;
  while (new_capacity < requested)
    new_capacity += new_capacity * 2;
  if (data)
    record_stats(data, current, new_capacity);
  return new_capacity;
}


x86 assembly (clang, -O0):
<resize_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x2,-0x20(%rbp)
jae    113f <resize_double+0x2f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1144 <resize_double+0x34>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1167 <resize_double+0x57>
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1144 <resize_double+0x34>
cmpq   $0x0,-0x18(%rbp)
je     1183 <resize_double+0x73>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <record_stats@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resize_double>:
push   %rbx
mov    %rdi,%rax
cmp    $0x2,%rdi
mov    %rdi,%rbx
cmovb  %rsi,%rbx
cmp    %rsi,%rbx
jae    1139 <resize_double+0x29>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rbx,%rbx,2),%rbx
cmp    %rsi,%rbx
jb     1130 <resize_double+0x20>
test   %rdx,%rdx
je     114c <resize_double+0x3c>
mov    %rdx,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1030 <record_stats@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i64 @resize_double(i64 %0, i64 %1, i8* %2) {
%4 = icmp ult i64 %0, 2
%5 = select i1 %4, i64 %1, i64 %0
%6 = icmp ult i64 %5, %1
br i1 %6, label %7, label %11
7: ; preds = %3, %7
%8 = phi i64 [ %9, %7 ], [ %5, %3 ]
%9 = mul i64 %8, 3
%10 = icmp ult i64 %9, %1
br i1 %10, label %7, label %11
11: ; preds = %7, %3
%12 = phi i64 [ %5, %3 ], [ %9, %7 ]
%13 = icmp eq i8* %2, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @record_stats(i8* %2, i64 %0, i64 %12)
br label %16
16: ; preds = %14, %11
ret i64 %12
}