#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int, int);
int pow(int, unsigned int);
int /*<<< orphan*/ stderr;
int tc_red_eval_ewma(unsigned qmin, unsigned burst, unsigned avpkt) {
  int wlog = 1;
  double W = 0.5;
  double a = (double)burst + 1 - (double)qmin / avpkt;
  if (a < 1.0) {
    fprintf(stderr,
            "tc_red_eval_ewma() burst %u is too small ?"
            " Try burst %u\n",
            burst, 1 + qmin / avpkt);
    return -1;
  }
  for (wlog = 1; wlog < 32; wlog++, W /= 2) {
    if (a <= (1 - pow(1 - W, burst)) / W)
      return wlog;
  }
  return -1;
}


x86 assembly (clang, -O0):
<tc_red_eval_ewma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movabs $0x3fe0000000000000,%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xeaa(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%eax
cvtsi2sd %rax,%xmm1
mov    -0x10(%rbp),%eax
cvtsi2sd %rax,%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe81(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11c1 <tc_red_eval_ewma+0xa1>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%eax
xor    %edx,%edx
divl   -0x10(%rbp)
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
add    $0x1,%ecx
lea    0xe60(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <tc_red_eval_ewma+0x131>
movl   $0x1,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jge    124a <tc_red_eval_ewma+0x12a>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe1c(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
mov    -0xc(%rbp),%esi
call   1040 <pow@plt>
movsd  -0x38(%rbp),%xmm1
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1221 <tc_red_eval_ewma+0x101>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <tc_red_eval_ewma+0x131>
jmp    1226 <tc_red_eval_ewma+0x106>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xdcc(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11c8 <tc_red_eval_ewma+0xa8>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tc_red_eval_ewma>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %esi,%eax
cvtsi2sd %rax,%xmm2
movsd  0xec9(%rip),%xmm3
mov    %edi,%eax
cvtsi2sd %rax,%xmm0
addsd  %xmm3,%xmm2
mov    %edx,%eax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
subsd  %xmm0,%xmm2
ucomisd %xmm2,%xmm3
jbe    1185 <tc_red_eval_ewma+0x65>
mov    %edx,%ecx
mov    0x2e80(%rip),%rax
mov    (%rax),%ebp
mov    %edi,%eax
xor    %edx,%edx
div    %ecx
lea    0x1(%rax),%ecx
lea    0xe9e(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    123e <tc_red_eval_ewma+0x11e>
movsd  %xmm2,0x10(%rsp)
movsd  0xe75(%rip),%xmm1
mov    $0x2,%ebp
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movapd %xmm3,%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
mov    %ebx,%esi
call   1040 <pow@plt>
movsd  0x8(%rsp),%xmm1
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
divsd  %xmm1,%xmm0
ucomisd 0x10(%rsp),%xmm0
jae    123b <tc_red_eval_ewma+0x11b>
mulsd  0xe27(%rip),%xmm1
cmp    $0x20,%ebp
je     117b <tc_red_eval_ewma+0x5b>
movsd  0xe12(%rip),%xmm0
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
mov    %ebx,%esi
movsd  %xmm1,0x8(%rsp)
call   1040 <pow@plt>
movsd  0x8(%rsp),%xmm1
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
divsd  %xmm1,%xmm0
ucomisd 0x10(%rsp),%xmm0
jae    123e <tc_red_eval_ewma+0x11e>
mulsd  0xddd(%rip),%xmm1
add    $0x2,%ebp
movsd  0xdca(%rip),%xmm3
jmp    11a0 <tc_red_eval_ewma+0x80>
add    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"tc_red_eval_ewma() burst %u is too small ? Try burst %u\0A\00"
define i32 @tc_red_eval_ewma(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 1, i32* %8
store double 5.000000e-01, double* %9
%11 = load i32, i32* %6
%12 = uitofp i32 %11 to double
%13 = fadd double %12, 1.000000e+00
%14 = load i32, i32* %5
%15 = uitofp i32 %14 to double
%16 = load i32, i32* %7
%17 = uitofp i32 %16 to double
%18 = fdiv double %15, %17
%19 = fsub double %13, %18
store double %19, double* %10
%20 = load double, double* %10
%21 = fcmp olt double %20, 1.000000e+00
br i1 %21, label %22, label %30
22: ; preds = %3
%23 = load i32, i32* @stderr
%24 = load i32, i32* %6
%25 = load i32, i32* %5
%26 = load i32, i32* %7
%27 = udiv i32 %25, %26
%28 = add i32 1, %27
%29 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %28)
store i32 -1, i32* %4
br label %55
30: ; preds = %3
store i32 1, i32* %8
br label %31
31: ; preds = %49, %30
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 32
br i1 %33, label %34, label %54
34: ; preds = %31
%35 = load double, double* %10
%36 = load double, double* %9
%37 = fsub double 1.000000e+00, %36
%38 = fptosi double %37 to i32
%39 = load i32, i32* %6
%40 = call i32 @pow(i32 %38, i32 %39)
%41 = sub nsw i32 1, %40
%42 = sitofp i32 %41 to double
%43 = load double, double* %9
%44 = fdiv double %42, %43
%45 = fcmp ole double %35, %44
br i1 %45, label %46, label %48
46: ; preds = %34
%47 = load i32, i32* %8
store i32 %47, i32* %4
br label %55
48: ; preds = %34
br label %49
49: ; preds = %48
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
%52 = load double, double* %9
%53 = fdiv double %52, 2.000000e+00
store double %53, double* %9
br label %31
54: ; preds = %31
store i32 -1, i32* %4
br label %55
55: ; preds = %54, %46, %22
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"tc_red_eval_ewma() burst %u is too small ? Try burst %u\0A\00"
define i32 @tc_red_eval_ewma(i32 %0, i32 %1, i32 %2) {
%4 = uitofp i32 %1 to double
%5 = fadd double %4, 1.000000e+00
%6 = uitofp i32 %0 to double
%7 = uitofp i32 %2 to double
%8 = fdiv double %6, %7
%9 = fsub double %5, %8
%10 = fcmp olt double %9, 1.000000e+00
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = udiv i32 %0, %2
%14 = add i32 %13, 1
%15 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %14)
br label %41
16: ; preds = %3, %38
%17 = phi double [ %40, %38 ], [ 5.000000e-01, %3 ]
%18 = phi i32 [ %39, %38 ], [ 1, %3 ]
%19 = fsub double 1.000000e+00, %17
%20 = fptosi double %19 to i32
%21 = tail call i32 @pow(i32 %20, i32 %1)
%22 = sub nsw i32 1, %21
%23 = sitofp i32 %22 to double
%24 = fdiv double %23, %17
%25 = fcmp ugt double %9, %24
br i1 %25, label %26, label %41
26: ; preds = %16
%27 = add nuw nsw i32 %18, 1
%28 = fmul double %17, 5.000000e-01
%29 = icmp eq i32 %27, 32
br i1 %29, label %41, label %30
30: ; preds = %26
%31 = fsub double 1.000000e+00, %28
%32 = fptosi double %31 to i32
%33 = tail call i32 @pow(i32 %32, i32 %1)
%34 = sub nsw i32 1, %33
%35 = sitofp i32 %34 to double
%36 = fdiv double %35, %28
%37 = fcmp ugt double %9, %36
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = add nuw nsw i32 %18, 2
%40 = fmul double %28, 5.000000e-01
br label %16
41: ; preds = %26, %16, %30, %11
%42 = phi i32 [ -1, %11 ], [ -1, %26 ], [ %18, %16 ], [ %27, %30 ]
ret i32 %42
}