#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*/ assert(int);
unsigned int plat_idx_to_val(unsigned int idx) {
  unsigned int error_bits, k, base;
  assert(idx < (19 * (1 << 8)));
  if (idx < ((1 << 8) << 1))
    return idx;
  error_bits = (idx >> 8) - 1;
  base = 1 << (error_bits + 8);
  k = idx % (1 << 8);
  return base + ((k + 0.5) * (1 << error_bits));
}


x86 assembly (clang, -O0):
<plat_idx_to_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1300,-0x8(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x200,-0x8(%rbp)
jae    1147 <plat_idx_to_val+0x37>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <plat_idx_to_val+0x93>
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%cl
add    $0x8,%cl
mov    $0x1,%eax
mov    %eax,%edx
shl    %cl,%edx
mov    %edx,%ecx
mov    %ecx,-0x14(%rbp)
movzbl -0x8(%rbp),%ecx
mov    %ecx,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
cvtsi2sd %rcx,%xmm1
mov    -0x10(%rbp),%ecx
cvtsi2sd %rcx,%xmm0
movsd  0xe7a(%rip),%xmm2
addsd  %xmm2,%xmm0
mov    -0xc(%rbp),%cl
shl    %cl,%eax
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plat_idx_to_val>:
push   %rbx
mov    %edi,%ebx
xor    %edi,%edi
cmp    $0x1300,%ebx
setb   %dil
call   1030 <assert@plt>
cmp    $0x200,%ebx
jb     1167 <plat_idx_to_val+0x57>
mov    %ebx,%ecx
shr    $0x8,%ecx
mov    $0x80,%eax
shl    %cl,%eax
cvtsi2sd %rax,%xmm0
movzbl %bl,%eax
cvtsi2sd %eax,%xmm1
add    $0xff,%cl
mov    $0x1,%eax
shl    %cl,%eax
addsd  0xeaa(%rip),%xmm1
cvtsi2sd %eax,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
cvttsd2si %xmm2,%rbx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @plat_idx_to_val(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp ult i32 %7, 4864
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %3
%12 = icmp ult i32 %11, 512
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load i32, i32* %3
store i32 %14, i32* %2
br label %34
15: ; preds = %1
%16 = load i32, i32* %3
%17 = lshr i32 %16, 8
%18 = sub i32 %17, 1
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = add i32 %19, 8
%21 = shl i32 1, %20
store i32 %21, i32* %6
%22 = load i32, i32* %3
%23 = urem i32 %22, 256
store i32 %23, i32* %5
%24 = load i32, i32* %6
%25 = uitofp i32 %24 to double
%26 = load i32, i32* %5
%27 = uitofp i32 %26 to double
%28 = fadd double %27, 5.000000e-01
%29 = load i32, i32* %4
%30 = shl i32 1, %29
%31 = sitofp i32 %30 to double
%32 = call double @llvm.fmuladd.f64(double %28, double %31, double %25)
%33 = fptoui double %32 to i32
store i32 %33, i32* %2
br label %34
34: ; preds = %15, %13
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
define i32 @plat_idx_to_val(i32 %0) {
%2 = icmp ult i32 %0, 4864
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = icmp ult i32 %0, 512
br i1 %5, label %18, label %6
6: ; preds = %1
%7 = lshr i32 %0, 8
%8 = add nsw i32 %7, -1
%9 = shl i32 128, %7
%10 = and i32 %0, 255
%11 = uitofp i32 %9 to double
%12 = uitofp i32 %10 to double
%13 = fadd double %12, 5.000000e-01
%14 = shl nuw i32 1, %8
%15 = sitofp i32 %14 to double
%16 = tail call double @llvm.fmuladd.f64(double %13, double %15, double %11)
%17 = fptoui double %16 to i32
br label %18
18: ; preds = %1, %6
%19 = phi i32 [ %17, %6 ], [ %0, %1 ]
ret i32 %19
}