#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*/ SPI_DataRw(unsigned char *, int);
int /*<<< orphan*/ SPI_Off(int);
int /*<<< orphan*/ SPI_On(int);
int SPI_Read_Value(int farm_fd, unsigned char channel) {
  unsigned char buff[3];
  int adcValue = 0;
  buff[0] = 0x06 | ((channel & 0x07) >> 7);
  buff[1] = ((channel & 0x07) << 6);
  buff[2] = 0x00;
  SPI_Off(farm_fd);
  SPI_DataRw(buff, 3);
  buff[1] = 0x0F & buff[1];
  adcValue = (buff[1] << 8) | buff[2];
  SPI_On(farm_fd);
  return adcValue;
}


x86 assembly (clang, -O0):
<SPI_Read_Value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x7,%eax
sar    $0x7,%eax
or     $0x6,%eax
mov    %al,-0x8(%rbp)
movzbl -0x5(%rbp),%eax
and    $0x7,%eax
shl    $0x6,%eax
mov    %al,-0x7(%rbp)
movb   $0x0,-0x6(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <SPI_Off@plt>
lea    -0x8(%rbp),%rdi
mov    $0x3,%esi
call   1040 <SPI_DataRw@plt>
movzbl -0x7(%rbp),%eax
and    $0xf,%eax
mov    %al,-0x7(%rbp)
movzbl -0x7(%rbp),%eax
shl    $0x8,%eax
movzbl -0x6(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <SPI_On@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SPI_Read_Value>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movb   $0x6,0x5(%rsp)
shl    $0x6,%sil
mov    %sil,0x6(%rsp)
movb   $0x0,0x7(%rsp)
call   1050 <SPI_Off@plt>
lea    0x5(%rsp),%rdi
mov    $0x3,%esi
call   1040 <SPI_DataRw@plt>
movzbl 0x6(%rsp),%eax
and    $0xf,%eax
mov    %al,0x6(%rsp)
shl    $0x8,%eax
movzbl 0x7(%rsp),%ebp
or     %eax,%ebp
mov    %ebx,%edi
call   1030 <SPI_On@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @SPI_Read_Value(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca [3 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i8 %1, i8* %4
store i32 0, i32* %6
%7 = load i8, i8* %4
%8 = zext i8 %7 to i32
%9 = and i32 %8, 7
%10 = ashr i32 %9, 7
%11 = or i32 6, %10
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 %12, i8* %13
%14 = load i8, i8* %4
%15 = zext i8 %14 to i32
%16 = and i32 %15, 7
%17 = shl i32 %16, 6
%18 = trunc i32 %17 to i8
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %18, i8* %19
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
store i8 0, i8* %20
%21 = load i32, i32* %3
%22 = call i32 @SPI_Off(i32 %21)
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%24 = call i32 @SPI_DataRw(i8* %23, i32 3)
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = and i32 15, %27
%29 = trunc i32 %28 to i8
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 %29, i8* %30
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = shl i32 %33, 8
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = or i32 %34, %37
store i32 %38, i32* %6
%39 = load i32, i32* %3
%40 = call i32 @SPI_On(i32 %39)
%41 = load i32, i32* %6
ret i32 %41
}

LLVM IR (-O2):
define i32 @SPI_Read_Value(i32 %0, i8 zeroext %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
store i8 6, i8* %4
%5 = shl i8 %1, 6
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
store i8 %5, i8* %6
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %7
%8 = tail call i32 @SPI_Off(i32 %0)
%9 = call i32 @SPI_DataRw(i8* %4, i32 3)
%10 = load i8, i8* %6
%11 = and i8 %10, 15
store i8 %11, i8* %6
%12 = zext i8 %11 to i32
%13 = shl nuw nsw i32 %12, 8
%14 = load i8, i8* %7
%15 = zext i8 %14 to i32
%16 = or i32 %13, %15
%17 = call i32 @SPI_On(i32 %0)
ret i32 %16
}