#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*/ CHECK(int, int, int, int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int spiClose(int);
int spiOpen(int, int, int /*<<< orphan*/);
int spiXfer(int, char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ time_sleep(double);
void tc() {
  int h, x, b, e;
  char txBuf[8], rxBuf[8];
  printf("SPI tests.");
  h = spiOpen(1, 50000, 0);
  CHECK(12, 1, h, 0, 0, "spiOpen");
  sprintf(txBuf, "\x01\x80");
  for (x = 0; x < 5; x++) {
    b = spiXfer(h, txBuf, rxBuf, 3);
    CHECK(12, 2, b, 3, 0, "spiXfer");
    if (b == 3) {
      time_sleep(1.0);
      printf("%d ", ((rxBuf[1] & 0x0F) * 256) | rxBuf[2]);
    }
  }
  e = spiClose(h);
  CHECK(12, 99, e, 0, 0, "spiClose");
}


x86 assembly (clang, -O0):
<tc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
mov    $0xc350,%esi
xor    %edx,%edx
call   1060 <spiOpen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edx
mov    $0xc,%edi
mov    $0x1,%esi
xor    %r8d,%r8d
lea    0xe62(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
lea    -0x18(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1080 <sprintf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    125b <tc+0xeb>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x3,%ecx
call   1040 <spiXfer@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    $0xc,%edi
mov    $0x2,%esi
mov    $0x3,%ecx
xor    %r8d,%r8d
lea    0xe10(%rip),%r9
call   1030 <CHECK@plt>
cmpl   $0x3,-0xc(%rbp)
jne    1248 <tc+0xd8>
movsd  0xddb(%rip),%xmm0
call   1090 <time_sleep@plt>
movsbl -0x1f(%rbp),%esi
and    $0xf,%esi
shl    $0x8,%esi
movsbl -0x1e(%rbp),%eax
or     %eax,%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    124d <tc+0xdd>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d0 <tc+0x60>
mov    -0x4(%rbp),%edi
call   1070 <spiClose@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    $0xc,%edi
mov    $0x63,%esi
xor    %r8d,%r8d
lea    0xdad(%rip),%r9
mov    %r8d,%ecx
call   1030 <CHECK@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tc>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
mov    $0xc350,%esi
xor    %edx,%edx
call   1060 <spiOpen@plt>
mov    %eax,%ebx
lea    0xe85(%rip),%r9
mov    $0xc,%edi
mov    $0x1,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
movw   $0x8001,0x10(%rsp)
movb   $0x0,0x12(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    $0x3,%ecx
call   1040 <spiXfer@plt>
mov    %eax,%ebp
lea    0xe4f(%rip),%r9
mov    $0xc,%edi
mov    $0x2,%esi
mov    %eax,%edx
mov    $0x3,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
cmp    $0x3,%ebp
jne    121a <tc+0xba>
movsd  0xe0b(%rip),%xmm0
call   1080 <time_sleep@plt>
movzbl 0x9(%rsp),%eax
and    $0xf,%eax
shl    $0x8,%eax
movsbl 0xa(%rsp),%esi
or     %eax,%esi
lea    0xe13(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    $0x3,%ecx
call   1040 <spiXfer@plt>
mov    %eax,%ebp
lea    0xde5(%rip),%r9
mov    $0xc,%edi
mov    $0x2,%esi
mov    %eax,%edx
mov    $0x3,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
cmp    $0x3,%ebp
jne    1284 <tc+0x124>
movsd  0xda1(%rip),%xmm0
call   1080 <time_sleep@plt>
movzbl 0x9(%rsp),%eax
and    $0xf,%eax
shl    $0x8,%eax
movsbl 0xa(%rsp),%esi
or     %eax,%esi
lea    0xda9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    $0x3,%ecx
call   1040 <spiXfer@plt>
mov    %eax,%ebp
lea    0xd7b(%rip),%r9
mov    $0xc,%edi
mov    $0x2,%esi
mov    %eax,%edx
mov    $0x3,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
cmp    $0x3,%ebp
jne    12ee <tc+0x18e>
movsd  0xd37(%rip),%xmm0
call   1080 <time_sleep@plt>
movzbl 0x9(%rsp),%eax
and    $0xf,%eax
shl    $0x8,%eax
movsbl 0xa(%rsp),%esi
or     %eax,%esi
lea    0xd3f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    $0x3,%ecx
call   1040 <spiXfer@plt>
mov    %eax,%ebp
lea    0xd11(%rip),%r9
mov    $0xc,%edi
mov    $0x2,%esi
mov    %eax,%edx
mov    $0x3,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
cmp    $0x3,%ebp
jne    1358 <tc+0x1f8>
movsd  0xccd(%rip),%xmm0
call   1080 <time_sleep@plt>
movzbl 0x9(%rsp),%eax
and    $0xf,%eax
shl    $0x8,%eax
movsbl 0xa(%rsp),%esi
or     %eax,%esi
lea    0xcd5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    $0x3,%ecx
call   1040 <spiXfer@plt>
mov    %eax,%ebp
lea    0xca7(%rip),%r9
mov    $0xc,%edi
mov    $0x2,%esi
mov    %eax,%edx
mov    $0x3,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
cmp    $0x3,%ebp
jne    13c2 <tc+0x262>
movsd  0xc63(%rip),%xmm0
call   1080 <time_sleep@plt>
movzbl 0x9(%rsp),%eax
and    $0xf,%eax
shl    $0x8,%eax
movsbl 0xa(%rsp),%esi
or     %eax,%esi
lea    0xc6b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1070 <spiClose@plt>
lea    0xc5a(%rip),%r9
mov    $0xc,%edi
mov    $0x63,%esi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <CHECK@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"SPI tests.\00"
@.str.1 = [8 x i8] c"spiOpen\00"
@.str.2 = [3 x i8] c"\01\80\00"
@.str.3 = [8 x i8] c"spiXfer\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [9 x i8] c"spiClose\00"
define void @tc() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [8 x i8]
%6 = alloca [8 x i8]
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @spiOpen(i32 1, i32 50000, i32 0)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = call i32 @CHECK(i32 12, i32 1, i32 %9, i32 0, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%12 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %13
13: ; preds = %38, %0
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 5
br i1 %15, label %16, label %41
16: ; preds = %13
%17 = load i32, i32* %1
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%20 = call i32 @spiXfer(i32 %17, i8* %18, i8* %19, i32 3)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = call i32 @CHECK(i32 12, i32 2, i32 %21, i32 3, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %37
25: ; preds = %16
%26 = call i32 @time_sleep(double 1.000000e+00)
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = and i32 %29, 15
%31 = mul nsw i32 %30, 256
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 2
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = or i32 %31, %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %25, %16
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %13
41: ; preds = %13
%42 = load i32, i32* %1
%43 = call i32 @spiClose(i32 %42)
store i32 %43, i32* %4
%44 = load i32, i32* %4
%45 = call i32 @CHECK(i32 12, i32 99, i32 %44, i32 0, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"SPI tests.\00"
@.str.1 = [8 x i8] c"spiOpen\00"
@.str.2 = [3 x i8] c"\01\80\00"
@.str.3 = [8 x i8] c"spiXfer\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [9 x i8] c"spiClose\00"
define void @tc() {
%1 = alloca [8 x i8]
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @spiOpen(i32 1, i32 50000, i32 0)
%7 = tail call i32 @CHECK(i32 12, i32 1, i32 %6, i32 0, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 1
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 2
%10 = call i32 @spiXfer(i32 %6, i8* %3, i8* %4, i32 3)
%11 = call i32 @CHECK(i32 12, i32 2, i32 %10, i32 3, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i32 %10, 3
br i1 %12, label %13, label %23
13: ; preds = %0
%14 = call i32 @time_sleep(double 1.000000e+00)
%15 = load i8, i8* %8
%16 = and i8 %15, 15
%17 = zext i8 %16 to i32
%18 = shl nuw nsw i32 %17, 8
%19 = load i8, i8* %9
%20 = sext i8 %19 to i32
%21 = or i32 %18, %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %0, %13
%24 = call i32 @spiXfer(i32 %6, i8* %3, i8* %4, i32 3)
%25 = call i32 @CHECK(i32 12, i32 2, i32 %24, i32 3, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32 %24, 3
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = call i32 @time_sleep(double 1.000000e+00)
%29 = load i8, i8* %8
%30 = and i8 %29, 15
%31 = zext i8 %30 to i32
%32 = shl nuw nsw i32 %31, 8
%33 = load i8, i8* %9
%34 = sext i8 %33 to i32
%35 = or i32 %32, %34
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %27, %23
%38 = call i32 @spiXfer(i32 %6, i8* %3, i8* %4, i32 3)
%39 = call i32 @CHECK(i32 12, i32 2, i32 %38, i32 3, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i32 %38, 3
br i1 %40, label %41, label %51
41: ; preds = %37
%42 = call i32 @time_sleep(double 1.000000e+00)
%43 = load i8, i8* %8
%44 = and i8 %43, 15
%45 = zext i8 %44 to i32
%46 = shl nuw nsw i32 %45, 8
%47 = load i8, i8* %9
%48 = sext i8 %47 to i32
%49 = or i32 %46, %48
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %41, %37
%52 = call i32 @spiXfer(i32 %6, i8* %3, i8* %4, i32 3)
%53 = call i32 @CHECK(i32 12, i32 2, i32 %52, i32 3, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%54 = icmp eq i32 %52, 3
br i1 %54, label %55, label %65
55: ; preds = %51
%56 = call i32 @time_sleep(double 1.000000e+00)
%57 = load i8, i8* %8
%58 = and i8 %57, 15
%59 = zext i8 %58 to i32
%60 = shl nuw nsw i32 %59, 8
%61 = load i8, i8* %9
%62 = sext i8 %61 to i32
%63 = or i32 %60, %62
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %55, %51
%66 = call i32 @spiXfer(i32 %6, i8* %3, i8* %4, i32 3)
%67 = call i32 @CHECK(i32 12, i32 2, i32 %66, i32 3, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%68 = icmp eq i32 %66, 3
br i1 %68, label %69, label %79
69: ; preds = %65
%70 = call i32 @time_sleep(double 1.000000e+00)
%71 = load i8, i8* %8
%72 = and i8 %71, 15
%73 = zext i8 %72 to i32
%74 = shl nuw nsw i32 %73, 8
%75 = load i8, i8* %9
%76 = sext i8 %75 to i32
%77 = or i32 %74, %76
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %77)
br label %79
79: ; preds = %69, %65
%80 = call i32 @spiClose(i32 %6)
%81 = call i32 @CHECK(i32 12, i32 99, i32 %80, i32 0, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
ret void
}