#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 */
typedef double uint32_t;

/* Variables and functions */
int /*<<< orphan*/ Log(int, char *, ...);
double log(int);
int pow(int, int);
double calculate_itu_rating(uint32_t delay, double loss,
                            double avg_loss_length) {
  double rating;
  double Ie;
  double Ieeff;
  double Ppl;
  double Bpl;
  double BurstR;
  double mT = 100.0;
  double sT = 1.0;
  double Ta = delay / 1000.0;
  double x;
  double Idd, part1, part2;
  Log(7, "Calculating ITU R value");
  Ppl = loss;
  Ie = 0.0;
  Bpl = 4.3;
  if (avg_loss_length > 0) {
    BurstR = avg_loss_length;
  } else {
    BurstR = 1;
  }
  Ieeff = Ie + (95 - Ie) * (Ppl / ((Ppl / BurstR) + Bpl));
  Log(7, "  Loss Impact: %f\n", Ieeff);
  if (Ta <= mT) {
    Idd = 0;
  } else {
    x = log(Ta / mT) / log(2);
    part1 = pow((1 + pow(x, 6 - sT)), 1 / (6 - sT));
    part2 = 3 * pow((1 + pow(x / 3, 6 - sT)), 1 / (6 - sT));
    Idd = 25 * (part1 - part2 + 2);
  }
  Log(7, "  Delay Impact: %f\n", Idd);
  rating = 93.2 - Idd - Ieeff;
  Log(7, "R value: %.02f\n", rating);
  return rating;
}


x86 assembly (clang, -O0):
<calculate_itu_rating>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  0xec6(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xeb1(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe97(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    $0x7,%edi
lea    0xeca(%rip),%rsi
mov    $0x0,%al
call   1030 <Log@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe59(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11cd <calculate_itu_rating+0x9d>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    11da <calculate_itu_rating+0xaa>
movsd  0xe3b(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  0xe39(%rip),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm3
divsd  -0x48(%rbp),%xmm3
addsd  -0x40(%rbp),%xmm3
divsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    $0x7,%edi
lea    0xe46(%rip),%rsi
mov    $0x1,%al
call   1030 <Log@plt>
movsd  -0x60(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     124a <calculate_itu_rating+0x11a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    1353 <calculate_itu_rating+0x223>
movsd  -0x60(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
movsd  %xmm0,-0x88(%rbp)
ff
mov    $0x2,%edi
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x88(%rbp),%xmm0
ff
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
cvttsd2si -0x68(%rbp),%edi
movsd  0xda8(%rip),%xmm0
subsd  -0x58(%rbp),%xmm0
cvttsd2si %xmm0,%esi
call   1050 <pow@plt>
mov    %eax,%edi
add    $0x1,%edi
movsd  0xd8d(%rip),%xmm1
subsd  -0x58(%rbp),%xmm1
movsd  0xd58(%rip),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
call   1050 <pow@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  0xd65(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
movsd  0xd4d(%rip),%xmm0
subsd  -0x58(%rbp),%xmm0
cvttsd2si %xmm0,%esi
call   1050 <pow@plt>
mov    %eax,%edi
add    $0x1,%edi
movsd  0xd32(%rip),%xmm1
subsd  -0x58(%rbp),%xmm1
movsd  0xcfd(%rip),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
call   1050 <pow@plt>
imul   $0x3,%eax,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x78(%rbp),%xmm1
subsd  -0x80(%rbp),%xmm1
movsd  0xcf2(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xcde(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
mov    $0x7,%edi
lea    0xd17(%rip),%rsi
mov    $0x1,%al
call   1030 <Log@plt>
movsd  0xcd5(%rip),%xmm0
subsd  -0x70(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x7,%edi
lea    0xcfc(%rip),%rsi
mov    $0x1,%al
call   1030 <Log@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_itu_rating>:
sub    $0x28,%rsp
movapd %xmm2,0x10(%rsp)
movsd  %xmm1,0x20(%rsp)
divsd  0xeb8(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xef3(%rip),%rsi
mov    $0x7,%edi
xor    %eax,%eax
call   1030 <Log@plt>
xorpd  %xmm2,%xmm2
xorpd  %xmm0,%xmm0
movapd 0x10(%rsp),%xmm1
cmpltsd %xmm1,%xmm0
andpd  %xmm0,%xmm1
movapd %xmm1,%xmm3
movsd  0xe84(%rip),%xmm1
andnpd %xmm1,%xmm0
orpd   %xmm3,%xmm0
movsd  0x20(%rsp),%xmm3
movapd %xmm3,%xmm1
divsd  %xmm0,%xmm1
addsd  0xe6e(%rip),%xmm1
divsd  %xmm1,%xmm3
mulsd  0xe6a(%rip),%xmm3
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
addsd  %xmm2,%xmm3
lea    0xe9d(%rip),%rsi
mov    $0x7,%edi
movsd  %xmm3,0x20(%rsp)
movapd %xmm3,%xmm0
mov    $0x1,%al
call   1030 <Log@plt>
movsd  0xe3f(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jae    129b <calculate_itu_rating+0x16b>
movapd %xmm1,%xmm0
divsd  0xe23(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%edi
call   1040 <log@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
cvttsd2si %xmm1,%edi
mov    $0x5,%esi
call   1050 <pow@plt>
lea    0x1(%rax),%edi
xor    %esi,%esi
call   1050 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
divsd  0xdcf(%rip),%xmm0
cvttsd2si %xmm0,%edi
mov    $0x5,%esi
call   1050 <pow@plt>
lea    0x1(%rax),%edi
xor    %esi,%esi
call   1050 <pow@plt>
lea    (%rax,%rax,2),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
addsd  0xda3(%rip),%xmm1
mulsd  0xda3(%rip),%xmm1
movsd  %xmm1,0x10(%rsp)
lea    0xdd1(%rip),%rsi
mov    $0x7,%edi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1030 <Log@plt>
movsd  0xd84(%rip),%xmm0
subsd  0x10(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xdb2(%rip),%rsi
mov    $0x7,%edi
mov    $0x1,%al
call   1030 <Log@plt>
movsd  0x10(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Calculating ITU R value\00"
@.str.1 = [19 x i8] c" Loss Impact: %f\0A\00"
@.str.2 = [20 x i8] c" Delay Impact: %f\0A\00"
@.str.3 = [16 x i8] c"R value: %.02f\0A\00"
define double @calculate_itu_rating(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
store double 1.000000e+02, double* %13
store double 1.000000e+00, double* %14
%20 = load double, double* %4
%21 = fdiv double %20, 1.000000e+03
store double %21, double* %15
%22 = call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%23 = load double, double* %5
store double %23, double* %10
store double 0.000000e+00, double* %8
store double 4.300000e+00, double* %11
%24 = load double, double* %6
%25 = fcmp ogt double %24, 0.000000e+00
br i1 %25, label %26, label %28
26: ; preds = %3
%27 = load double, double* %6
store double %27, double* %12
br label %29
28: ; preds = %3
store double 1.000000e+00, double* %12
br label %29
29: ; preds = %28, %26
%30 = load double, double* %8
%31 = load double, double* %8
%32 = fsub double 9.500000e+01, %31
%33 = load double, double* %10
%34 = load double, double* %10
%35 = load double, double* %12
%36 = fdiv double %34, %35
%37 = load double, double* %11
%38 = fadd double %36, %37
%39 = fdiv double %33, %38
%40 = call double @llvm.fmuladd.f64(double %32, double %39, double %30)
store double %40, double* %9
%41 = load double, double* %9
%42 = call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %41)
%43 = load double, double* %15
%44 = load double, double* %13
%45 = fcmp ole double %43, %44
br i1 %45, label %46, label %47
46: ; preds = %29
store double 0.000000e+00, double* %17
br label %88
47: ; preds = %29
%48 = load double, double* %15
%49 = load double, double* %13
%50 = fdiv double %48, %49
%51 = fptosi double %50 to i32
%52 = call double @log(i32 %51)
%53 = call double @log(i32 2)
%54 = fdiv double %52, %53
store double %54, double* %16
%55 = load double, double* %16
%56 = fptosi double %55 to i32
%57 = load double, double* %14
%58 = fsub double 6.000000e+00, %57
%59 = fptosi double %58 to i32
%60 = call i32 @pow(i32 %56, i32 %59)
%61 = add nsw i32 1, %60
%62 = load double, double* %14
%63 = fsub double 6.000000e+00, %62
%64 = fdiv double 1.000000e+00, %63
%65 = fptosi double %64 to i32
%66 = call i32 @pow(i32 %61, i32 %65)
%67 = sitofp i32 %66 to double
store double %67, double* %18
%68 = load double, double* %16
%69 = fdiv double %68, 3.000000e+00
%70 = fptosi double %69 to i32
%71 = load double, double* %14
%72 = fsub double 6.000000e+00, %71
%73 = fptosi double %72 to i32
%74 = call i32 @pow(i32 %70, i32 %73)
%75 = add nsw i32 1, %74
%76 = load double, double* %14
%77 = fsub double 6.000000e+00, %76
%78 = fdiv double 1.000000e+00, %77
%79 = fptosi double %78 to i32
%80 = call i32 @pow(i32 %75, i32 %79)
%81 = mul nsw i32 3, %80
%82 = sitofp i32 %81 to double
store double %82, double* %19
%83 = load double, double* %18
%84 = load double, double* %19
%85 = fsub double %83, %84
%86 = fadd double %85, 2.000000e+00
%87 = fmul double 2.500000e+01, %86
store double %87, double* %17
br label %88
88: ; preds = %47, %46
%89 = load double, double* %17
%90 = call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %89)
%91 = load double, double* %17
%92 = fsub double 9.320000e+01, %91
%93 = load double, double* %9
%94 = fsub double %92, %93
store double %94, double* %7
%95 = load double, double* %7
%96 = call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), double %95)
%97 = load double, double* %7
ret double %97
}

LLVM IR (-O2):
@.str = [24 x i8] c"Calculating ITU R value\00"
@.str.1 = [19 x i8] c" Loss Impact: %f\0A\00"
@.str.2 = [20 x i8] c" Delay Impact: %f\0A\00"
@.str.3 = [16 x i8] c"R value: %.02f\0A\00"
define double @calculate_itu_rating(double %0, double %1, double %2) {
%4 = fdiv double %0, 1.000000e+03
%5 = tail call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = fcmp ogt double %2, 0.000000e+00
%7 = select i1 %6, double %2, double 1.000000e+00
%8 = fdiv double %1, %7
%9 = fadd double %8, 4.300000e+00
%10 = fdiv double %1, %9
%11 = tail call double @llvm.fmuladd.f64(double %10, double 9.500000e+01, double 0.000000e+00)
%12 = tail call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), double %11)
%13 = fcmp ugt double %4, 1.000000e+02
br i1 %13, label %14, label %35
14: ; preds = %3
%15 = fdiv double %4, 1.000000e+02
%16 = fptosi double %15 to i32
%17 = tail call double @log(i32 %16)
%18 = tail call double @log(i32 2)
%19 = fdiv double %17, %18
%20 = fptosi double %19 to i32
%21 = tail call i32 @pow(i32 %20, i32 5)
%22 = add nsw i32 %21, 1
%23 = tail call i32 @pow(i32 %22, i32 0)
%24 = sitofp i32 %23 to double
%25 = fdiv double %19, 3.000000e+00
%26 = fptosi double %25 to i32
%27 = tail call i32 @pow(i32 %26, i32 5)
%28 = add nsw i32 %27, 1
%29 = tail call i32 @pow(i32 %28, i32 0)
%30 = mul nsw i32 %29, 3
%31 = sitofp i32 %30 to double
%32 = fsub double %24, %31
%33 = fadd double %32, 2.000000e+00
%34 = fmul double %33, 2.500000e+01
br label %35
35: ; preds = %3, %14
%36 = phi double [ %34, %14 ], [ 0.000000e+00, %3 ]
%37 = tail call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), double %36)
%38 = fsub double 9.320000e+01, %36
%39 = fsub double %38, %11
%40 = tail call i32 (i32, i8*, ...) @Log(i32 7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), double %39)
ret double %39
}