#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, int *, int);
void gertboardAnalogWrite(int chan, int value) {
  uint8_t spiData[2];
  uint8_t chanBits, dataBits;
  if (chan == 0)
    chanBits = 0x30;
  else
    chanBits = 0xB0;
  chanBits |= ((value >> 4) & 0x0F);
  dataBits = ((value << 4) & 0xF0);
  spiData[0] = chanBits;
  spiData[1] = dataBits;
  wiringPiSPIDataRW(1, spiData, 2);
}


x86 assembly (clang, -O0):
<gertboardAnalogWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1134 <gertboardAnalogWrite+0x24>
movl   $0x30,-0x14(%rbp)
jmp    113b <gertboardAnalogWrite+0x2b>
movl   $0xb0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x4,%eax
and    $0xf,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
and    $0xf0,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1030 <wiringPiSPIDataRW@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gertboardAnalogWrite>:
push   %rax
xor    %eax,%eax
test   %edi,%edi
setne  %al
shl    $0x7,%eax
mov    %esi,%ecx
shr    $0x4,%ecx
and    $0xf,%ecx
add    %ecx,%eax
add    $0x30,%eax
shl    $0x4,%esi
movzbl %sil,%ecx
mov    %eax,(%rsp)
mov    %ecx,0x4(%rsp)
mov    %rsp,%rsi
mov    $0x1,%edi
mov    $0x2,%edx
call   1030 <wiringPiSPIDataRW@plt>
pop    %rax
ret

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

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