#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 double uint16_t;

/* Variables and functions */
int cmd_adc(char, double *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int adc(char pin, double aref, double *result) {
  uint16_t value = 0;
  int r = cmd_adc(pin & 0x07, &value);
  if (!r) {
    fprintf(stderr, "ADC fault\n");
    return 0;
  }
  *result = value * (aref / 1024.0);
  return 1;
}


x86 assembly (clang, -O0):
<adc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsbl -0x5(%rbp),%eax
and    $0x7,%eax
lea    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1030 <cmd_adc@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1180 <adc+0x60>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <adc+0x89>
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe6e(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adc>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movsd  %xmm0,0x8(%rsp)
movq   $0x0,(%rsp)
and    $0x7,%edi
mov    %rsp,%rsi
call   1030 <cmd_adc@plt>
test   %eax,%eax
je     1163 <adc+0x43>
movsd  0x8(%rsp),%xmm0
mulsd  0xead(%rip),%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx)
mov    $0x1,%eax
jmp    117a <adc+0x5a>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"ADC fault\0A\00"
define i32 @adc(i8 signext %0, double %1, double* %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca double
%7 = alloca double*
%8 = alloca double
%9 = alloca i32
store i8 %0, i8* %5
store double %1, double* %6
store double* %2, double** %7
store double 0.000000e+00, double* %8
%10 = load i8, i8* %5
%11 = sext i8 %10 to i32
%12 = and i32 %11, 7
%13 = trunc i32 %12 to i8
%14 = call i32 @cmd_adc(i8 signext %13, double* %8)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %3
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %26
20: ; preds = %3
%21 = load double, double* %8
%22 = load double, double* %6
%23 = fdiv double %22, 1.024000e+03
%24 = fmul double %21, %23
%25 = load double*, double** %7
store double %24, double* %25
store i32 1, i32* %4
br label %26
26: ; preds = %20, %17
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"ADC fault\0A\00"
define i32 @adc(i8 signext %0, double %1, double* nocapture writeonly %2) {
%4 = alloca double
%5 = bitcast double* %4 to i8*
store double 0.000000e+00, double* %4
%6 = and i8 %0, 7
%7 = call i32 @cmd_adc(i8 signext %6, double* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %16
12: ; preds = %3
%13 = load double, double* %4
%14 = fmul double %1, 0x3F50000000000000
%15 = fmul double %14, %13
store double %15, double* %2
br label %16
16: ; preds = %12, %9
%17 = phi i32 [ 1, %12 ], [ 0, %9 ]
ret i32 %17
}