#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 GetDistExtraBits(unsigned int);
int GetLengthExtraBits(unsigned int);
int GetLengthSymbol(unsigned int);
double GetCostFixed(unsigned litlen, unsigned dist, void *unused) {
  (void)unused;
  if (dist == 0) {
    if (litlen <= 143)
      return 8;
    else
      return 9;
  } else {
    int dbits = GetDistExtraBits(dist);
    int lbits = GetLengthExtraBits(litlen);
    int lsym = GetLengthSymbol(litlen);
    double cost = 0;
    if (lsym <= 279)
      cost += 7;
    else
      cost += 8;
    cost += 5;
    return cost + dbits + lbits;
  }
}


x86 assembly (clang, -O0):
<GetCostFixed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    117d <GetCostFixed+0x4d>
cmpl   $0x8f,-0xc(%rbp)
ja     116b <GetCostFixed+0x3b>
movsd  0xe9f(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120a <GetCostFixed+0xda>
movsd  0xea5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120a <GetCostFixed+0xda>
mov    -0x10(%rbp),%edi
call   1040 <GetDistExtraBits@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <GetLengthExtraBits@plt>
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <GetLengthSymbol@plt>
mov    %eax,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x117,-0x24(%rbp)
jg     11ca <GetCostFixed+0x9a>
movsd  0xe4d(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11dc <GetCostFixed+0xac>
movsd  0xe2e(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe2c(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
addsd  %xmm1,%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetCostFixed>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
test   %esi,%esi
je     1179 <GetCostFixed+0x49>
mov    %esi,%edi
call   1040 <GetDistExtraBits@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <GetLengthExtraBits@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1050 <GetLengthSymbol@plt>
xor    %ecx,%ecx
cmp    $0x118,%eax
cvtsi2sd %ebp,%xmm1
setl   %cl
lea    0xe97(%rip),%rax
addsd  (%rax,%rcx,8),%xmm1
cvtsi2sd %r14d,%xmm0
addsd  %xmm1,%xmm0
jmp    1190 <GetCostFixed+0x60>
xor    %eax,%eax
cmp    $0x90,%ebx
setb   %al
lea    0xe85(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @GetCostFixed(i32 %0, i32 %1, i8* %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%12 = load i8*, i8** %7
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %3
%16 = load i32, i32* %5
%17 = icmp ule i32 %16, 143
br i1 %17, label %18, label %19
18: ; preds = %15
store double 8.000000e+00, double* %4
br label %45
19: ; preds = %15
store double 9.000000e+00, double* %4
br label %45
20: ; preds = %3
%21 = load i32, i32* %6
%22 = call i32 @GetDistExtraBits(i32 %21)
store i32 %22, i32* %8
%23 = load i32, i32* %5
%24 = call i32 @GetLengthExtraBits(i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %5
%26 = call i32 @GetLengthSymbol(i32 %25)
store i32 %26, i32* %10
store double 0.000000e+00, double* %11
%27 = load i32, i32* %10
%28 = icmp sle i32 %27, 279
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load double, double* %11
%31 = fadd double %30, 7.000000e+00
store double %31, double* %11
br label %35
32: ; preds = %20
%33 = load double, double* %11
%34 = fadd double %33, 8.000000e+00
store double %34, double* %11
br label %35
35: ; preds = %32, %29
%36 = load double, double* %11
%37 = fadd double %36, 5.000000e+00
store double %37, double* %11
%38 = load double, double* %11
%39 = load i32, i32* %8
%40 = sitofp i32 %39 to double
%41 = fadd double %38, %40
%42 = load i32, i32* %9
%43 = sitofp i32 %42 to double
%44 = fadd double %41, %43
store double %44, double* %4
br label %45
45: ; preds = %35, %19, %18
%46 = load double, double* %4
ret double %46
}

LLVM IR (-O2):
define double @GetCostFixed(i32 %0, i32 %1, i8* nocapture readnone %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = icmp ult i32 %0, 144
%7 = select i1 %6, double 8.000000e+00, double 9.000000e+00
br label %18
8: ; preds = %3
%9 = tail call i32 @GetDistExtraBits(i32 %1)
%10 = tail call i32 @GetLengthExtraBits(i32 %0)
%11 = tail call i32 @GetLengthSymbol(i32 %0)
%12 = icmp slt i32 %11, 280
%13 = select i1 %12, double 1.200000e+01, double 1.300000e+01
%14 = sitofp i32 %9 to double
%15 = fadd double %13, %14
%16 = sitofp i32 %10 to double
%17 = fadd double %15, %16
br label %18
18: ; preds = %5, %8
%19 = phi double [ %17, %8 ], [ %7, %5 ]
ret double %19
}