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

/* Variables and functions */
int /*<<< orphan*/ wiringPiSPIDataRW(int /*<<< orphan*/, int *, int);
int gertboardAnalogRead(int chan) {
  uint8_t spiData[2];
  uint8_t chanBits;
  if (chan == 0)
    chanBits = 0b11010000;
  else
    chanBits = 0b11110000;
  spiData[0] = chanBits;
  spiData[1] = 0;
  wiringPiSPIDataRW(0, spiData, 2);
  return ((spiData[0] << 7) | (spiData[1] >> 1)) & 0x3FF;
}


x86 assembly (clang, -O0):
<gertboardAnalogRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1131 <gertboardAnalogRead+0x21>
movl   $0xd0,-0x10(%rbp)
jmp    1138 <gertboardAnalogRead+0x28>
movl   $0xf0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0xc(%rbp),%rsi
xor    %edi,%edi
mov    $0x2,%edx
call   1030 <wiringPiSPIDataRW@plt>
mov    -0xc(%rbp),%eax
shl    $0x7,%eax
mov    -0x8(%rbp),%ecx
sar    $0x1,%ecx
or     %ecx,%eax
and    $0x3ff,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gertboardAnalogRead>:
push   %rax
xor    %eax,%eax
test   %edi,%edi
setne  %al
shl    $0x5,%eax
or     $0xd0,%eax
mov    %eax,(%rsp)
movl   $0x0,0x4(%rsp)
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x2,%edx
call   1030 <wiringPiSPIDataRW@plt>
mov    (%rsp),%ecx
mov    0x4(%rsp),%eax
shl    $0x7,%ecx
shr    %eax
or     %ecx,%eax
and    $0x3ff,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @gertboardAnalogRead(i32 %0) {
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 208, i32* %4
br label %9
8: ; preds = %1
store i32 240, i32* %4
br label %9
9: ; preds = %8, %7
%10 = load i32, i32* %4
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 %10, i32* %11
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 0, i32* %12
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%14 = call i32 @wiringPiSPIDataRW(i32 0, i32* %13, i32 2)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%16 = load i32, i32* %15
%17 = shl i32 %16, 7
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%19 = load i32, i32* %18
%20 = ashr i32 %19, 1
%21 = or i32 %17, %20
%22 = and i32 %21, 1023
ret i32 %22
}

LLVM IR (-O2):
define i32 @gertboardAnalogRead(i32 %0) {
%2 = alloca [2 x i32]
%3 = bitcast [2 x i32]* %2 to i8*
%4 = icmp eq i32 %0, 0
%5 = select i1 %4, i32 208, i32 240
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
store i32 %5, i32* %6
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
store i32 0, i32* %7
%8 = call i32 @wiringPiSPIDataRW(i32 0, i32* %6, i32 2)
%9 = load i32, i32* %6
%10 = shl i32 %9, 7
%11 = load i32, i32* %7
%12 = lshr i32 %11, 1
%13 = or i32 %12, %10
%14 = and i32 %13, 1023
ret i32 %14
}