#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 obbox_2 {
  int dummy;
};
struct findpts_local_hash_data_2 {
  int dummy;
};

/* Variables and functions */
unsigned int ceil(int /*<<< orphan*/);
unsigned int hash_count_2(struct findpts_local_hash_data_2 *,
                          struct obbox_2 const *const, unsigned int const,
                          unsigned int);
int /*<<< orphan*/ hash_setfac_2(struct findpts_local_hash_data_2 *,
                                 unsigned int);
int /*<<< orphan*/ pow(unsigned int const, double);
unsigned int hash_opt_size_2(struct findpts_local_hash_data_2 *p,
                             const struct obbox_2 *const obb,
                             const unsigned int nel,
                             const unsigned int max_size) {
  unsigned int nl = 1, nu = ceil(pow(max_size - nel, 1.0 / 2));
  unsigned int size_low = 2 + nel;
  while (nu - nl > 1) {
    unsigned int nm = nl + (nu - nl) / 2, nmd = nm * nm, size;
    ;
    size = nmd + 1 + hash_count_2(p, obb, nel, nm);
    if (size <= max_size)
      nl = nm, size_low = size;
    else
      nu = nm;
  }
  hash_setfac_2(p, nl);
  return size_low;
}


x86 assembly (clang, -O0):
<hash_opt_size_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
sub    -0x14(%rbp),%edi
movsd  0xe95(%rip),%xmm0
call   1060 <pow@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    $0x1,%eax
jbe    11fb <hash_opt_size_2+0xbb>
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
shr    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%ecx
call   1040 <hash_count_2@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
ja     11f0 <hash_opt_size_2+0xb0>
mov    -0x28(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11f6 <hash_opt_size_2+0xb6>
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1183 <hash_opt_size_2+0x43>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <hash_setfac_2@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_opt_size_2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %edx,%ebx
mov    %rsi,0x10(%rsp)
mov    %rdi,%r13
mov    %ecx,%edi
sub    %edx,%edi
movsd  0xe99(%rip),%xmm0
call   1060 <pow@plt>
mov    %eax,%edi
call   1030 <ceil@plt>
mov    %rbx,%rcx
mov    %eax,%r14d
lea    0x2(%rbx),%ebp
lea    -0x1(%r14),%r15d
mov    $0x1,%ebx
cmp    $0x2,%r15d
mov    %r13,0x8(%rsp)
jb     11ed <hash_opt_size_2+0xad>
mov    $0x1,%ebx
mov    %r12d,0x4(%rsp)
nopw   0x0(%rax,%rax,1)
shr    %r15d
add    %ebx,%r15d
mov    %r15d,%r12d
imul   %r12d,%r12d
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    %rcx,%r13
mov    %r13d,%edx
mov    %r15d,%ecx
call   1040 <hash_count_2@plt>
mov    %r13,%rcx
add    %r12d,%eax
add    $0x1,%eax
mov    0x4(%rsp),%r12d
cmp    %r12d,%eax
cmovbe %eax,%ebp
cmova  %r15d,%r14d
cmovbe %r15d,%ebx
mov    %r14d,%r15d
sub    %ebx,%r15d
cmp    $0x1,%r15d
ja     11a0 <hash_opt_size_2+0x60>
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1050 <hash_setfac_2@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.findpts_local_hash_data_2 = type { i32 }
%struct.obbox_2 = type { i32 }
define i32 @hash_opt_size_2(%struct.findpts_local_hash_data_2* %0, %struct.obbox_2* %1, i32 %2, i32 %3) {
%5 = alloca %struct.findpts_local_hash_data_2*
%6 = alloca %struct.obbox_2*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store %struct.findpts_local_hash_data_2* %0, %struct.findpts_local_hash_data_2** %5
store %struct.obbox_2* %1, %struct.obbox_2** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 1, i32* %9
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = sub i32 %15, %16
%18 = call i32 @pow(i32 %17, double 5.000000e-01)
%19 = call i32 @ceil(i32 %18)
store i32 %19, i32* %10
%20 = load i32, i32* %7
%21 = add i32 2, %20
store i32 %21, i32* %11
br label %22
22: ; preds = %53, %4
%23 = load i32, i32* %10
%24 = load i32, i32* %9
%25 = sub i32 %23, %24
%26 = icmp ugt i32 %25, 1
br i1 %26, label %27, label %54
27: ; preds = %22
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = load i32, i32* %9
%31 = sub i32 %29, %30
%32 = udiv i32 %31, 2
%33 = add i32 %28, %32
store i32 %33, i32* %12
%34 = load i32, i32* %12
%35 = load i32, i32* %12
%36 = mul i32 %34, %35
store i32 %36, i32* %13
%37 = load i32, i32* %13
%38 = add i32 %37, 1
%39 = load %struct.findpts_local_hash_data_2*, %struct.findpts_local_hash_data_2** %5
%40 = load %struct.obbox_2*, %struct.obbox_2** %6
%41 = load i32, i32* %7
%42 = load i32, i32* %12
%43 = call i32 @hash_count_2(%struct.findpts_local_hash_data_2* %39, %struct.obbox_2* %40, i32 %41, i32 %42)
%44 = add i32 %38, %43
store i32 %44, i32* %14
%45 = load i32, i32* %14
%46 = load i32, i32* %8
%47 = icmp ule i32 %45, %46
br i1 %47, label %48, label %51
48: ; preds = %27
%49 = load i32, i32* %12
store i32 %49, i32* %9
%50 = load i32, i32* %14
store i32 %50, i32* %11
br label %53
51: ; preds = %27
%52 = load i32, i32* %12
store i32 %52, i32* %10
br label %53
53: ; preds = %51, %48
br label %22
54: ; preds = %22
%55 = load %struct.findpts_local_hash_data_2*, %struct.findpts_local_hash_data_2** %5
%56 = load i32, i32* %9
%57 = call i32 @hash_setfac_2(%struct.findpts_local_hash_data_2* %55, i32 %56)
%58 = load i32, i32* %11
ret i32 %58
}

LLVM IR (-O2):
%struct.findpts_local_hash_data_2 = type { i32 }
%struct.obbox_2 = type { i32 }
define i32 @hash_opt_size_2(%struct.findpts_local_hash_data_2* %0, %struct.obbox_2* %1, i32 %2, i32 %3) {
%5 = sub i32 %3, %2
%6 = tail call i32 @pow(i32 %5, double 5.000000e-01)
%7 = tail call i32 @ceil(i32 %6)
%8 = add i32 %2, 2
%9 = add i32 %7, -1
%10 = icmp ugt i32 %9, 1
br i1 %10, label %11, label %28
11: ; preds = %4, %11
%12 = phi i32 [ %26, %11 ], [ %9, %4 ]
%13 = phi i32 [ %25, %11 ], [ 1, %4 ]
%14 = phi i32 [ %24, %11 ], [ %7, %4 ]
%15 = phi i32 [ %23, %11 ], [ %8, %4 ]
%16 = lshr i32 %12, 1
%17 = add i32 %16, %13
%18 = mul i32 %17, %17
%19 = add i32 %18, 1
%20 = tail call i32 @hash_count_2(%struct.findpts_local_hash_data_2* %0, %struct.obbox_2* %1, i32 %2, i32 %17)
%21 = add i32 %19, %20
%22 = icmp ugt i32 %21, %3
%23 = select i1 %22, i32 %15, i32 %21
%24 = select i1 %22, i32 %17, i32 %14
%25 = select i1 %22, i32 %13, i32 %17
%26 = sub i32 %24, %25
%27 = icmp ugt i32 %26, 1
br i1 %27, label %11, label %28
28: ; preds = %11, %4
%29 = phi i32 [ %8, %4 ], [ %23, %11 ]
%30 = phi i32 [ 1, %4 ], [ %25, %11 ]
%31 = tail call i32 @hash_setfac_2(%struct.findpts_local_hash_data_2* %0, i32 %30)
ret i32 %29
}