#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 */
scalar_t__ ceil(int);
int /*<<< orphan*/ exp(int);
double floor(int /*<<< orphan*/);
int log(double);
int calc_obits(int dim, int res, int esize) {
  double off;
  int bits;
  if (res == 0 || res == 1)
    return 0;
  if (dim == 1)
    off = esize;
  else {
    off = (double)esize * floor(exp(log((double)res) * dim - log(res - 1.0)));
  }
  bits = (int)ceil(log(off) / log(2.0) - 1e-14);
  return bits;
}


x86 assembly (clang, -O0):
<calc_obits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1165 <calc_obits+0x25>
cmpl   $0x1,-0xc(%rbp)
jne    1171 <calc_obits+0x31>
movl   $0x0,-0x4(%rbp)
jmp    1221 <calc_obits+0xe1>
cmpl   $0x1,-0x8(%rbp)
jne    118a <calc_obits+0x4a>
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11dd <calc_obits+0x9d>
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
call   1050 <log@plt>
imul   -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe4e(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1050 <log@plt>
mov    -0x2c(%rbp),%edi
sub    %eax,%edi
call   1040 <exp@plt>
mov    %eax,%edi
call   1060 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
mov    %eax,-0x30(%rbp)
movsd  0xe1e(%rip),%xmm0
call   1050 <log@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  0xdfd(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_obits>:
xor    %eax,%eax
cmp    $0x2,%esi
jb     11e4 <calc_obits+0xa4>
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
cvtsi2sd %edx,%xmm0
cmp    $0x1,%edi
je     11ac <calc_obits+0x6c>
cvtsi2sd %esi,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
call   1050 <log@plt>
imul   %eax,%ebx
movsd  0x8(%rsp),%xmm0
addsd  0xe7c(%rip),%xmm0
call   1050 <log@plt>
sub    %eax,%ebx
mov    %ebx,%edi
call   1040 <exp@plt>
mov    %eax,%edi
call   1060 <floor@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
call   1050 <log@plt>
mov    %eax,%ebx
movsd  0xe4d(%rip),%xmm0
call   1050 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0xe3a(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <ceil@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @calc_obits(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %16
15: ; preds = %12, %3
store i32 0, i32* %4
br label %49
16: ; preds = %12
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %7
%21 = sitofp i32 %20 to double
store double %21, double* %8
br label %38
22: ; preds = %16
%23 = load i32, i32* %7
%24 = sitofp i32 %23 to double
%25 = load i32, i32* %6
%26 = sitofp i32 %25 to double
%27 = call i32 @log(double %26)
%28 = load i32, i32* %5
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %6
%31 = sitofp i32 %30 to double
%32 = fsub double %31, 1.000000e+00
%33 = call i32 @log(double %32)
%34 = sub nsw i32 %29, %33
%35 = call i32 @exp(i32 %34)
%36 = call double @floor(i32 %35)
%37 = fmul double %24, %36
store double %37, double* %8
br label %38
38: ; preds = %22, %19
%39 = load double, double* %8
%40 = call i32 @log(double %39)
%41 = call i32 @log(double 2.000000e+00)
%42 = sdiv i32 %40, %41
%43 = sitofp i32 %42 to double
%44 = fsub double %43, 0x3D06849B86A12B9B
%45 = fptosi double %44 to i32
%46 = call i64 @ceil(i32 %45)
%47 = trunc i64 %46 to i32
store i32 %47, i32* %9
%48 = load i32, i32* %9
store i32 %48, i32* %4
br label %49
49: ; preds = %38, %15
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
define i32 @calc_obits(i32 %0, i32 %1, i32 %2) {
%4 = icmp ult i32 %1, 2
br i1 %4, label %28, label %5
5: ; preds = %3
%6 = icmp eq i32 %0, 1
%7 = sitofp i32 %2 to double
br i1 %6, label %18, label %8
8: ; preds = %5
%9 = sitofp i32 %1 to double
%10 = tail call i32 @log(double %9)
%11 = mul nsw i32 %10, %0
%12 = fadd double %9, -1.000000e+00
%13 = tail call i32 @log(double %12)
%14 = sub nsw i32 %11, %13
%15 = tail call i32 @exp(i32 %14)
%16 = tail call double @floor(i32 %15)
%17 = fmul double %16, %7
br label %18
18: ; preds = %5, %8
%19 = phi double [ %17, %8 ], [ %7, %5 ]
%20 = tail call i32 @log(double %19)
%21 = tail call i32 @log(double 2.000000e+00)
%22 = sdiv i32 %20, %21
%23 = sitofp i32 %22 to double
%24 = fadd double %23, 0xBD06849B86A12B9B
%25 = fptosi double %24 to i32
%26 = tail call i64 @ceil(i32 %25)
%27 = trunc i64 %26 to i32
br label %28
28: ; preds = %3, %18
%29 = phi i32 [ %27, %18 ], [ 0, %3 ]
ret i32 %29
}