#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 /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
double volts_E1608(uint16_t value, uint8_t range) {
  double volt = 0.0;
  switch (range) {
  case (0x0):
    volt = (value - 0x8000) * 10.0 / 32768.;
    break;
  case (0x1):
    volt = (value - 0x8000) * 5.0 / 32768.;
    break;
  case (0x2):
    volt = (value - 0x8000) * 2.0 / 32768.;
    break;
  case (0x3):
    volt = (value - 0x8000) * 1.0 / 32768.;
    break;
  default:
    printf("Unknown range.\n");
    break;
  }
  return volt;
}


x86 assembly (clang, -O0):
<volts_E1608>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x3,%rax
ja     1203 <volts_E1608+0xf3>
mov    -0x18(%rbp),%rax
lea    0xee6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%eax
sub    $0x8000,%eax
cvtsi2sd %eax,%xmm0
movsd  0xec1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe95(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    120f <volts_E1608+0xff>
mov    -0x4(%rbp),%eax
sub    $0x8000,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe8b(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe67(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    120f <volts_E1608+0xff>
mov    -0x4(%rbp),%eax
sub    $0x8000,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe55(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe39(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    120f <volts_E1608+0xff>
mov    -0x4(%rbp),%eax
sub    $0x8000,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe1f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe0b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    120f <volts_E1608+0xff>
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<volts_E1608>:
push   %rax
cmp    $0x3,%esi
ja     113c <volts_E1608+0x2c>
mov    %esi,%eax
lea    0xef9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
add    $0xffff8000,%edi
cvtsi2sd %edi,%xmm0
mulsd  0xed6(%rip),%xmm0
jmp    117b <volts_E1608+0x6b>
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
pop    %rax
ret
add    $0xffff8000,%edi
cvtsi2sd %edi,%xmm0
mulsd  0xea9(%rip),%xmm0
jmp    117b <volts_E1608+0x6b>
add    $0xffff8000,%edi
cvtsi2sd %edi,%xmm0
addsd  %xmm0,%xmm0
jmp    117b <volts_E1608+0x6b>
add    $0xffff8000,%edi
cvtsi2sd %edi,%xmm0
mulsd  0xe7d(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Unknown range.\0A\00"
define double @volts_E1608(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 %0, i32* %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %5
%6 = load i32, i32* %4
switch i32 %6, label %31 [
i32 0, label %7
i32 1, label %13
i32 2, label %19
i32 3, label %25
]
7: ; preds = %2
%8 = load i32, i32* %3
%9 = sub nsw i32 %8, 32768
%10 = sitofp i32 %9 to double
%11 = fmul double %10, 1.000000e+01
%12 = fdiv double %11, 3.276800e+04
store double %12, double* %5
br label %33
13: ; preds = %2
%14 = load i32, i32* %3
%15 = sub nsw i32 %14, 32768
%16 = sitofp i32 %15 to double
%17 = fmul double %16, 5.000000e+00
%18 = fdiv double %17, 3.276800e+04
store double %18, double* %5
br label %33
19: ; preds = %2
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 32768
%22 = sitofp i32 %21 to double
%23 = fmul double %22, 2.000000e+00
%24 = fdiv double %23, 3.276800e+04
store double %24, double* %5
br label %33
25: ; preds = %2
%26 = load i32, i32* %3
%27 = sub nsw i32 %26, 32768
%28 = sitofp i32 %27 to double
%29 = fmul double %28, 1.000000e+00
%30 = fdiv double %29, 3.276800e+04
store double %30, double* %5
br label %33
31: ; preds = %2
%32 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %25, %19, %13, %7
%34 = load double, double* %5
ret double %34
}

LLVM IR (-O2):
@str = [15 x i8] c"Unknown range.\00"
define double @volts_E1608(i32 %0, i32 %1) {
switch i32 %1, label %22 [
i32 0, label %3
i32 1, label %8
i32 2, label %13
i32 3, label %18
]
3: ; preds = %2
%4 = add nsw i32 %0, -32768
%5 = sitofp i32 %4 to double
%6 = fmul double %5, 1.000000e+01
%7 = fmul double %6, 0x3F00000000000000
br label %24
8: ; preds = %2
%9 = add nsw i32 %0, -32768
%10 = sitofp i32 %9 to double
%11 = fmul double %10, 5.000000e+00
%12 = fmul double %11, 0x3F00000000000000
br label %24
13: ; preds = %2
%14 = add nsw i32 %0, -32768
%15 = sitofp i32 %14 to double
%16 = fmul double %15, 2.000000e+00
%17 = fmul double %16, 0x3F00000000000000
br label %24
18: ; preds = %2
%19 = add nsw i32 %0, -32768
%20 = sitofp i32 %19 to double
%21 = fmul double %20, 0x3F00000000000000
br label %24
22: ; preds = %2
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %18, %13, %8, %3
%25 = phi double [ 0.000000e+00, %22 ], [ %21, %18 ], [ %17, %13 ], [ %12, %8 ], [ %7, %3 ]
ret double %25
}