#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 pow(double, double);
int tc_core_time2tick(double);
unsigned tc_cbq_calc_offtime(unsigned bndw, unsigned rate, unsigned avpkt,
                             int ewma_log, unsigned minburst) {
  double g = 1.0 - 1.0 / (1 << ewma_log);
  double offtime = (double)avpkt / rate - (double)avpkt / bndw;
  if (minburst == 0)
    return 0;
  if (minburst == 1)
    offtime *= pow(g, -(double)minburst) - 1;
  else
    offtime *= 1 + (pow(g, -(double)(minburst - 1)) - 1) / (1 - g);
  return tc_core_time2tick(offtime * 1000000);
}


x86 assembly (clang, -O0):
<tc_cbq_calc_offtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x14(%rbp),%cl
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm2
movsd  0xeb2(%rip),%xmm0
movaps %xmm0,%xmm1
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%eax
cvtsi2sd %rax,%xmm1
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm2
movaps %xmm1,%xmm0
divsd  %xmm2,%xmm0
mov    -0x8(%rbp),%eax
cvtsi2sd %rax,%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11a0 <tc_cbq_calc_offtime+0x80>
movl   $0x0,-0x4(%rbp)
jmp    1258 <tc_cbq_calc_offtime+0x138>
cmpl   $0x1,-0x18(%rbp)
jne    11e9 <tc_cbq_calc_offtime+0xc9>
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%eax
cvtsi2sd %rax,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
call   1030 <pow@plt>
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1243 <tc_cbq_calc_offtime+0x123>
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
cvtsi2sd %rax,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
call   1030 <pow@plt>
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xddc(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xdcb(%rip),%xmm0
addsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xdbd(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
call   1040 <tc_core_time2tick@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tc_cbq_calc_offtime>:
mov    $0x1,%eax
shl    %cl,%eax
test   %r8d,%r8d
je     1199 <tc_cbq_calc_offtime+0x79>
sub    $0x18,%rsp
cvtsi2sd %eax,%xmm0
movsd  0xec4(%rip),%xmm3
movapd %xmm3,%xmm1
mov    %edx,%eax
cvtsi2sd %rax,%xmm2
divsd  %xmm0,%xmm1
movapd %xmm3,%xmm0
mov    %esi,%eax
cvtsi2sd %rax,%xmm5
subsd  %xmm1,%xmm0
movapd %xmm2,%xmm3
mov    %edi,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  %xmm5,%xmm3
divsd  %xmm1,%xmm2
subsd  %xmm2,%xmm3
movsd  %xmm3,0x10(%rsp)
cmp    $0x1,%r8d
jne    119d <tc_cbq_calc_offtime+0x7d>
movsd  0xe80(%rip),%xmm1
call   1030 <pow@plt>
add    $0xffffffff,%eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
jmp    11e0 <tc_cbq_calc_offtime+0xc0>
mov    %r8d,%eax
ret
add    $0xffffffff,%r8d
xorps  %xmm1,%xmm1
cvtsi2sd %r8,%xmm1
xorpd  0xe6f(%rip),%xmm1
movsd  %xmm0,0x8(%rsp)
call   1030 <pow@plt>
add    $0xffffffff,%eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movsd  0xe32(%rip),%xmm0
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
divsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
movsd  0x10(%rsp),%xmm0
mulsd  %xmm2,%xmm0
mulsd  0xe1e(%rip),%xmm0
add    $0x18,%rsp
jmp    1040 <tc_core_time2tick@plt>

LLVM IR (-O0):
define i32 @tc_cbq_calc_offtime(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
%13 = alloca double
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%14 = load i32, i32* %10
%15 = shl i32 1, %14
%16 = sitofp i32 %15 to double
%17 = fdiv double 1.000000e+00, %16
%18 = fsub double 1.000000e+00, %17
store double %18, double* %12
%19 = load i32, i32* %9
%20 = uitofp i32 %19 to double
%21 = load i32, i32* %8
%22 = uitofp i32 %21 to double
%23 = fdiv double %20, %22
%24 = load i32, i32* %9
%25 = uitofp i32 %24 to double
%26 = load i32, i32* %7
%27 = uitofp i32 %26 to double
%28 = fdiv double %25, %27
%29 = fsub double %23, %28
store double %29, double* %13
%30 = load i32, i32* %11
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %5
store i32 0, i32* %6
br label %65
33: ; preds = %5
%34 = load i32, i32* %11
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = load double, double* %12
%38 = load i32, i32* %11
%39 = uitofp i32 %38 to double
%40 = fneg double %39
%41 = call i32 @pow(double %37, double %40)
%42 = sub nsw i32 %41, 1
%43 = sitofp i32 %42 to double
%44 = load double, double* %13
%45 = fmul double %44, %43
store double %45, double* %13
br label %61
46: ; preds = %33
%47 = load double, double* %12
%48 = load i32, i32* %11
%49 = sub i32 %48, 1
%50 = uitofp i32 %49 to double
%51 = fneg double %50
%52 = call i32 @pow(double %47, double %51)
%53 = sub nsw i32 %52, 1
%54 = sitofp i32 %53 to double
%55 = load double, double* %12
%56 = fsub double 1.000000e+00, %55
%57 = fdiv double %54, %56
%58 = fadd double 1.000000e+00, %57
%59 = load double, double* %13
%60 = fmul double %59, %58
store double %60, double* %13
br label %61
61: ; preds = %46, %36
%62 = load double, double* %13
%63 = fmul double %62, 1.000000e+06
%64 = call i32 @tc_core_time2tick(double %63)
store i32 %64, i32* %6
br label %65
65: ; preds = %61, %32
%66 = load i32, i32* %6
ret i32 %66
}

LLVM IR (-O2):
define i32 @tc_cbq_calc_offtime(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = shl nuw i32 1, %3
%7 = sitofp i32 %6 to double
%8 = fdiv double 1.000000e+00, %7
%9 = fsub double 1.000000e+00, %8
%10 = uitofp i32 %2 to double
%11 = uitofp i32 %1 to double
%12 = fdiv double %10, %11
%13 = uitofp i32 %0 to double
%14 = fdiv double %10, %13
%15 = fsub double %12, %14
switch i32 %4, label %20 [
i32 0, label %35
i32 1, label %16
]
16: ; preds = %5
%17 = tail call i32 @pow(double %9, double -1.000000e+00)
%18 = add nsw i32 %17, -1
%19 = sitofp i32 %18 to double
br label %30
20: ; preds = %5
%21 = add i32 %4, -1
%22 = uitofp i32 %21 to double
%23 = fneg double %22
%24 = tail call i32 @pow(double %9, double %23)
%25 = add nsw i32 %24, -1
%26 = sitofp i32 %25 to double
%27 = fsub double 1.000000e+00, %9
%28 = fdiv double %26, %27
%29 = fadd double %28, 1.000000e+00
br label %30
30: ; preds = %20, %16
%31 = phi double [ %19, %16 ], [ %29, %20 ]
%32 = fmul double %15, %31
%33 = fmul double %32, 1.000000e+06
%34 = tail call i32 @tc_core_time2tick(double %33)
br label %35
35: ; preds = %5, %30
%36 = phi i32 [ %34, %30 ], [ %4, %5 ]
ret i32 %36
}