#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 */
struct hashset {
  int dummy;
};

/* Variables and functions */
int CHAR_BIT;
int /*<<< orphan*/ assert(int);
size_t hashset_capacity(struct hashset *);
size_t hashset_count(struct hashset *);
int hashset_grow_delta(struct hashset *, size_t);
int hashset_ensure_capacity(struct hashset *s, size_t n) {
  assert(s);
  assert(n >= hashset_count(s));
  assert(hashset_capacity(s) >= hashset_count(s));
  assert(n <= ((size_t)1 << (CHAR_BIT * sizeof(size_t) - 1)));
  if (n > hashset_capacity(s)) {
    size_t delta = n - hashset_count(s);
    return hashset_grow_delta(s, delta);
  }
  return 0;
}


x86 assembly (clang, -O0):
<hashset_ensure_capacity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <hashset_count@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1050 <hashset_capacity@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <hashset_count@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
mov    0x2e25(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x3,%rcx
sub    $0x1,%rcx
mov    $0x1,%edx
shl    %cl,%rdx
mov    %rdx,%rcx
cmp    %rcx,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <hashset_capacity@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jbe    1236 <hashset_ensure_capacity+0xf6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <hashset_count@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <hashset_grow_delta@plt>
mov    %eax,-0x4(%rbp)
jmp    123d <hashset_ensure_capacity+0xfd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashset_ensure_capacity>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <hashset_count@plt>
xor    %edi,%edi
cmp    %r14,%rax
setbe  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1050 <hashset_capacity@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <hashset_count@plt>
xor    %edi,%edi
cmp    %rax,%r15
setae  %dil
call   1040 <assert@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%cl
shl    $0x3,%cl
add    $0xff,%cl
mov    $0x1,%eax
shl    %cl,%rax
xor    %edi,%edi
cmp    %r14,%rax
setae  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1050 <hashset_capacity@plt>
cmp    %r14,%rax
jae    11d4 <hashset_ensure_capacity+0x94>
mov    %rbx,%rdi
call   1030 <hashset_count@plt>
sub    %rax,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <hashset_grow_delta@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.hashset = type { i32 }
@CHAR_BIT = global i32 0
define i32 @hashset_ensure_capacity(%struct.hashset* %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.hashset*
%5 = alloca i64
%6 = alloca i64
store %struct.hashset* %0, %struct.hashset** %4
store i64 %1, i64* %5
%7 = load %struct.hashset*, %struct.hashset** %4
%8 = ptrtoint %struct.hashset* %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i64, i64* %5
%11 = load %struct.hashset*, %struct.hashset** %4
%12 = call i64 @hashset_count(%struct.hashset* %11)
%13 = icmp uge i64 %10, %12
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load %struct.hashset*, %struct.hashset** %4
%17 = call i64 @hashset_capacity(%struct.hashset* %16)
%18 = load %struct.hashset*, %struct.hashset** %4
%19 = call i64 @hashset_count(%struct.hashset* %18)
%20 = icmp uge i64 %17, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i64, i64* %5
%24 = load i32, i32* @CHAR_BIT
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 8
%27 = sub i64 %26, 1
%28 = shl i64 1, %27
%29 = icmp ule i64 %23, %28
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i64, i64* %5
%33 = load %struct.hashset*, %struct.hashset** %4
%34 = call i64 @hashset_capacity(%struct.hashset* %33)
%35 = icmp ugt i64 %32, %34
br i1 %35, label %36, label %44
36: ; preds = %2
%37 = load i64, i64* %5
%38 = load %struct.hashset*, %struct.hashset** %4
%39 = call i64 @hashset_count(%struct.hashset* %38)
%40 = sub i64 %37, %39
store i64 %40, i64* %6
%41 = load %struct.hashset*, %struct.hashset** %4
%42 = load i64, i64* %6
%43 = call i32 @hashset_grow_delta(%struct.hashset* %41, i64 %42)
store i32 %43, i32* %3
br label %45
44: ; preds = %2
store i32 0, i32* %3
br label %45
45: ; preds = %44, %36
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.hashset = type { i32 }
@CHAR_BIT = global i32 0
define i32 @hashset_ensure_capacity(%struct.hashset* %0, i64 %1) {
%3 = ptrtoint %struct.hashset* %0 to i64
%4 = trunc i64 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i64 @hashset_count(%struct.hashset* %0)
%7 = icmp ule i64 %6, %1
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i64 @hashset_capacity(%struct.hashset* %0)
%11 = tail call i64 @hashset_count(%struct.hashset* %0)
%12 = icmp uge i64 %10, %11
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = load i32, i32* @CHAR_BIT
%16 = sext i32 %15 to i64
%17 = shl nsw i64 %16, 3
%18 = add nsw i64 %17, -1
%19 = shl nuw i64 1, %18
%20 = icmp uge i64 %19, %1
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
%23 = tail call i64 @hashset_capacity(%struct.hashset* %0)
%24 = icmp ult i64 %23, %1
br i1 %24, label %25, label %29
25: ; preds = %2
%26 = tail call i64 @hashset_count(%struct.hashset* %0)
%27 = sub i64 %1, %26
%28 = tail call i32 @hashset_grow_delta(%struct.hashset* %0, i64 %27)
br label %29
29: ; preds = %2, %25
%30 = phi i32 [ %28, %25 ], [ 0, %2 ]
ret i32 %30
}