#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 *);
int /*<<< orphan*/ stderr;
double toDouble(char *data, int size) {
  double ret = 0;
  if (size == 1) {
    ret = (double)((unsigned char *)data)[0];
    ret = ret / 255 - 0.5;
  } else if (size == 2) {
    ret = (double)((char)data[0] + (char)data[1] * 255);
    ret /= 65535;
  } else {
    fprintf(stderr, "Unsupported byte length\n");
  }
  return ret;
}


x86 assembly (clang, -O0):
<toDouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1168 <toDouble+0x58>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xec2(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xeae(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11c7 <toDouble+0xb7>
cmpl   $0x2,-0xc(%rbp)
jne    11ad <toDouble+0x9d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    -0x8(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
imul   $0xff,%ecx,%ecx
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe61(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11c2 <toDouble+0xb2>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11c7 <toDouble+0xb7>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toDouble>:
push   %rax
cmp    $0x2,%esi
je     1134 <toDouble+0x24>
cmp    $0x1,%esi
jne    1152 <toDouble+0x42>
movzbl (%rdi),%eax
cvtsi2sd %eax,%xmm0
divsd  0xede(%rip),%xmm0
addsd  0xede(%rip),%xmm0
pop    %rax
ret
movsbl (%rdi),%eax
movsbl 0x1(%rdi),%ecx
mov    %ecx,%edx
shl    $0x8,%edx
sub    %ecx,%edx
add    %eax,%edx
cvtsi2sd %edx,%xmm0
divsd  0xeb0(%rip),%xmm0
pop    %rax
ret
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
call   1030 <fprintf@plt>
xorps  %xmm0,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Unsupported byte length\0A\00"
define double @toDouble(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca double
store i8* %0, i8** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = uitofp i8 %11 to double
store double %12, double* %5
%13 = load double, double* %5
%14 = fdiv double %13, 2.550000e+02
%15 = fsub double %14, 5.000000e-01
store double %15, double* %5
br label %37
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %33
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = mul nsw i32 %27, 255
%29 = add nsw i32 %23, %28
%30 = sitofp i32 %29 to double
store double %30, double* %5
%31 = load double, double* %5
%32 = fdiv double %31, 6.553500e+04
store double %32, double* %5
br label %36
33: ; preds = %16
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %33, %19
br label %37
37: ; preds = %36, %8
%38 = load double, double* %5
ret double %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Unsupported byte length\0A\00"
define double @toDouble(i8* nocapture %0, i32 %1) {
switch i32 %1, label %18 [
i32 1, label %3
i32 2, label %8
]
3: ; preds = %2
%4 = load i8, i8* %0
%5 = uitofp i8 %4 to double
%6 = fdiv double %5, 2.550000e+02
%7 = fadd double %6, -5.000000e-01
br label %21
8: ; preds = %2
%9 = load i8, i8* %0
%10 = sext i8 %9 to i32
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = mul nsw i32 %13, 255
%15 = add nsw i32 %14, %10
%16 = sitofp i32 %15 to double
%17 = fdiv double %16, 6.553500e+04
br label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %8, %18, %3
%22 = phi double [ %7, %3 ], [ %17, %8 ], [ 0.000000e+00, %18 ]
ret double %22
}