#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_3 {
  int dummy;
};
struct findpts_local_hash_data_3 {
  int dummy;
};

/* Variables and functions */
unsigned int ceil(int /*<<< orphan*/);
unsigned int hash_count_3(struct findpts_local_hash_data_3 *,
                          struct obbox_3 const *const, unsigned int const,
                          unsigned int);
int /*<<< orphan*/ hash_setfac_3(struct findpts_local_hash_data_3 *,
                                 unsigned int);
int /*<<< orphan*/ pow(unsigned int const, double);
unsigned int hash_opt_size_3(struct findpts_local_hash_data_3 *p,
                             const struct obbox_3 *const obb,
                             const unsigned int nel,
                             const unsigned int max_size) {
  unsigned int nl = 1, nu = ceil(pow(max_size - nel, 1.0 / 3));
  unsigned int size_low = 2 + nel;
  while (nu - nl > 1) {
    unsigned int nm = nl + (nu - nl) / 2, nmd = nm * nm, size;
    nmd *= nm;
    size = nmd + 1 + hash_count_3(p, obb, nel, nm);
    if (size <= max_size)
      nl = nm, size_low = size;
    else
      nu = nm;
  }
  hash_setfac_3(p, nl);
  return size_low;
}


x86 assembly (clang, -O0):
<hash_opt_size_3>:
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   1050 <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    1205 <hash_opt_size_3+0xc5>
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    -0x28(%rbp),%eax
imul   -0x2c(%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   1060 <hash_count_3@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
ja     11fa <hash_opt_size_3+0xba>
mov    -0x28(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1200 <hash_opt_size_3+0xc0>
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1183 <hash_opt_size_3+0x43>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <hash_setfac_3@plt>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_opt_size_3>:
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   1050 <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     11f1 <hash_opt_size_3+0xb1>
mov    $0x1,%ebx
mov    %r12d,0x4(%rsp)
nopw   0x0(%rax,%rax,1)
shr    %r15d
add    %ebx,%r15d
mov    %r15d,%r12d
imul   %r12d,%r12d
imul   %r15d,%r12d
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    %rcx,%r13
mov    %r13d,%edx
mov    %r15d,%ecx
call   1060 <hash_count_3@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_3+0x60>
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1040 <hash_setfac_3@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_3 = type { i32 }
%struct.obbox_3 = type { i32 }
define i32 @hash_opt_size_3(%struct.findpts_local_hash_data_3* %0, %struct.obbox_3* %1, i32 %2, i32 %3) {
%5 = alloca %struct.findpts_local_hash_data_3*
%6 = alloca %struct.obbox_3*
%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_3* %0, %struct.findpts_local_hash_data_3** %5
store %struct.obbox_3* %1, %struct.obbox_3** %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 0x3FD5555555555555)
%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 = %56, %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 %57
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* %12
%38 = load i32, i32* %13
%39 = mul i32 %38, %37
store i32 %39, i32* %13
%40 = load i32, i32* %13
%41 = add i32 %40, 1
%42 = load %struct.findpts_local_hash_data_3*, %struct.findpts_local_hash_data_3** %5
%43 = load %struct.obbox_3*, %struct.obbox_3** %6
%44 = load i32, i32* %7
%45 = load i32, i32* %12
%46 = call i32 @hash_count_3(%struct.findpts_local_hash_data_3* %42, %struct.obbox_3* %43, i32 %44, i32 %45)
%47 = add i32 %41, %46
store i32 %47, i32* %14
%48 = load i32, i32* %14
%49 = load i32, i32* %8
%50 = icmp ule i32 %48, %49
br i1 %50, label %51, label %54
51: ; preds = %27
%52 = load i32, i32* %12
store i32 %52, i32* %9
%53 = load i32, i32* %14
store i32 %53, i32* %11
br label %56
54: ; preds = %27
%55 = load i32, i32* %12
store i32 %55, i32* %10
br label %56
56: ; preds = %54, %51
br label %22
57: ; preds = %22
%58 = load %struct.findpts_local_hash_data_3*, %struct.findpts_local_hash_data_3** %5
%59 = load i32, i32* %9
%60 = call i32 @hash_setfac_3(%struct.findpts_local_hash_data_3* %58, i32 %59)
%61 = load i32, i32* %11
ret i32 %61
}

LLVM IR (-O2):
%struct.findpts_local_hash_data_3 = type { i32 }
%struct.obbox_3 = type { i32 }
define i32 @hash_opt_size_3(%struct.findpts_local_hash_data_3* %0, %struct.obbox_3* %1, i32 %2, i32 %3) {
%5 = sub i32 %3, %2
%6 = tail call i32 @pow(i32 %5, double 0x3FD5555555555555)
%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 %29
11: ; preds = %4, %11
%12 = phi i32 [ %27, %11 ], [ %9, %4 ]
%13 = phi i32 [ %26, %11 ], [ 1, %4 ]
%14 = phi i32 [ %25, %11 ], [ %7, %4 ]
%15 = phi i32 [ %24, %11 ], [ %8, %4 ]
%16 = lshr i32 %12, 1
%17 = add i32 %16, %13
%18 = mul i32 %17, %17
%19 = mul i32 %18, %17
%20 = add i32 %19, 1
%21 = tail call i32 @hash_count_3(%struct.findpts_local_hash_data_3* %0, %struct.obbox_3* %1, i32 %2, i32 %17)
%22 = add i32 %20, %21
%23 = icmp ugt i32 %22, %3
%24 = select i1 %23, i32 %15, i32 %22
%25 = select i1 %23, i32 %17, i32 %14
%26 = select i1 %23, i32 %13, i32 %17
%27 = sub i32 %25, %26
%28 = icmp ugt i32 %27, 1
br i1 %28, label %11, label %29
29: ; preds = %11, %4
%30 = phi i32 [ %8, %4 ], [ %24, %11 ]
%31 = phi i32 [ 1, %4 ], [ %26, %11 ]
%32 = tail call i32 @hash_setfac_3(%struct.findpts_local_hash_data_3* %0, i32 %31)
ret i32 %30
}