#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 int uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
double edid_decode_fixed_point(uint16_t value) {
  double result = 0.0;
  assert((~value & 0xfc00) == 0xfc00);
  for (uint8_t i = 0; value && (i < 10); i++, value >>= 1)
    result = result + ((value & 0x1) * (1.0 / (1 << (10 - i))));
  return result;
}


x86 assembly (clang, -O0):
<edid_decode_fixed_point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
xor    $0xffffffff,%eax
and    $0xfc00,%eax
cmp    $0xfc00,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x15(%rbp)
je     1160 <edid_decode_fixed_point+0x50>
cmpl   $0xa,-0x14(%rbp)
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1170 <edid_decode_fixed_point+0x60>
jmp    11c2 <edid_decode_fixed_point+0xb2>
movsd  -0x10(%rbp),%xmm1
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    $0xa,%ecx
sub    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2sd %eax,%xmm3
movsd  0xe66(%rip),%xmm2
divsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1147 <edid_decode_fixed_point+0x37>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edid_decode_fixed_point>:
push   %rbx
mov    %edi,%ebx
xor    %edi,%edi
test   $0xfc00,%ebx
sete   %dil
call   1030 <assert@plt>
xorpd  %xmm0,%xmm0
test   %ebx,%ebx
je     1182 <edid_decode_fixed_point+0x72>
xor    %eax,%eax
mov    $0xa,%ecx
movsd  0xec5(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edx
and    $0x1,%edx
mov    $0x1,%esi
shl    %cl,%esi
xorps  %xmm2,%xmm2
cvtsi2sd %edx,%xmm2
movapd %xmm0,%xmm3
xorps  %xmm4,%xmm4
cvtsi2sd %esi,%xmm4
movapd %xmm1,%xmm0
divsd  %xmm4,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
cmp    $0x2,%ebx
jb     1182 <edid_decode_fixed_point+0x72>
lea    0x1(%rax),%edx
sar    %ebx
add    $0xffffffff,%ecx
cmp    $0x9,%eax
mov    %edx,%eax
jb     1140 <edid_decode_fixed_point+0x30>
pop    %rbx
ret

LLVM IR (-O0):
define double @edid_decode_fixed_point(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
store i32 %0, i32* %2
store double 0.000000e+00, double* %3
%5 = load i32, i32* %2
%6 = xor i32 %5, -1
%7 = and i32 %6, 64512
%8 = icmp eq i32 %7, 64512
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
store i32 0, i32* %4
br label %11
11: ; preds = %30, %1
%12 = load i32, i32* %2
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 10
br label %17
17: ; preds = %14, %11
%18 = phi i1 [ false, %11 ], [ %16, %14 ]
br i1 %18, label %19, label %35
19: ; preds = %17
%20 = load double, double* %3
%21 = load i32, i32* %2
%22 = and i32 %21, 1
%23 = sitofp i32 %22 to double
%24 = load i32, i32* %4
%25 = sub nsw i32 10, %24
%26 = shl i32 1, %25
%27 = sitofp i32 %26 to double
%28 = fdiv double 1.000000e+00, %27
%29 = call double @llvm.fmuladd.f64(double %23, double %28, double %20)
store double %29, double* %3
br label %30
30: ; preds = %19
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
%33 = load i32, i32* %2
%34 = ashr i32 %33, 1
store i32 %34, i32* %2
br label %11
35: ; preds = %17
%36 = load double, double* %3
ret double %36
}

LLVM IR (-O2):
define double @edid_decode_fixed_point(i32 %0) {
%2 = and i32 %0, 64512
%3 = icmp eq i32 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp eq i32 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %9, %1
%8 = phi double [ 0.000000e+00, %1 ], [ %19, %9 ]
ret double %8
9: ; preds = %1, %9
%10 = phi i32 [ %20, %9 ], [ 0, %1 ]
%11 = phi double [ %19, %9 ], [ 0.000000e+00, %1 ]
%12 = phi i32 [ %21, %9 ], [ %0, %1 ]
%13 = and i32 %12, 1
%14 = sitofp i32 %13 to double
%15 = sub nuw nsw i32 10, %10
%16 = shl nuw nsw i32 1, %15
%17 = sitofp i32 %16 to double
%18 = fdiv double 1.000000e+00, %17
%19 = tail call double @llvm.fmuladd.f64(double %14, double %18, double %11)
%20 = add nuw nsw i32 %10, 1
%21 = ashr i32 %12, 1
%22 = icmp ugt i32 %12, 1
%23 = icmp ult i32 %10, 9
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %9, label %7
}