#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;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ SpiClosePort(int /*<<< orphan*/);
int SpiOpenPort(int /*<<< orphan*/);
int /*<<< orphan*/ SpiWriteAndRead(int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  int op1 = SpiOpenPort(0);
  if (op1 == 1) {
    return op1;
  }
  uint32_t data = 0xFF;
  SpiWriteAndRead(0, &data);
  printf(" response 0:  %#x \r\n", data);
  SpiWriteAndRead(0, &data);
  printf(" response 0:  %#x \r\n", data);
  for (uint8_t i = 0x01; i <= 0x07; i++) {
    data = i <= 0x04 ? i : 0xFF;
    SpiWriteAndRead(0, &data);
    printf(" response  %#x \r\n", data);
  }
  SpiClosePort(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1030 <SpiOpenPort@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    116e <main+0x2e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1218 <main+0xd8>
movl   $0xff,-0xc(%rbp)
xor    %edi,%edi
lea    -0xc(%rbp),%rsi
call   1050 <SpiWriteAndRead@plt>
mov    -0xc(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
lea    -0xc(%rbp),%rsi
call   1050 <SpiWriteAndRead@plt>
mov    -0xc(%rbp),%esi
lea    0xe5c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x10(%rbp)
cmpl   $0x7,-0x10(%rbp)
jg     120a <main+0xca>
cmpl   $0x4,-0x10(%rbp)
jg     11cf <main+0x8f>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11dc <main+0x9c>
mov    $0xff,%eax
mov    %eax,-0x14(%rbp)
jmp    11dc <main+0x9c>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
xor    %edi,%edi
lea    -0xc(%rbp),%rsi
call   1050 <SpiWriteAndRead@plt>
mov    -0xc(%rbp),%esi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11b0 <main+0x70>
xor    %edi,%edi
call   1060 <SpiClosePort@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1030 <SpiOpenPort@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x1,%ecx
je     127d <main+0x13d>
movl   $0xff,0x4(%rsp)
lea    0x4(%rsp),%r14
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <SpiWriteAndRead@plt>
mov    0x4(%rsp),%esi
lea    0xe83(%rip),%rbx
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <SpiWriteAndRead@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movl   $0x1,0x4(%rsp)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <SpiWriteAndRead@plt>
mov    0x4(%rsp),%esi
lea    0xe5d(%rip),%rbx
mov    %rbx,%rdi
call   1040 <printf@plt>
movl   $0x2,0x4(%rsp)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <SpiWriteAndRead@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movl   $0x3,0x4(%rsp)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <SpiWriteAndRead@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movl   $0x4,0x4(%rsp)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <SpiWriteAndRead@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movl   $0xff,0x4(%rsp)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <SpiWriteAndRead@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movl   $0xff,0x4(%rsp)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <SpiWriteAndRead@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
movl   $0xff,0x4(%rsp)
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <SpiWriteAndRead@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <SpiClosePort@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c" response 0: %#x \0D\0A\00"
@.str.1 = [18 x i8] c" response %#x \0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @SpiOpenPort(i32 0)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = load i32, i32* %2
store i32 %9, i32* %1
br label %36
10: ; preds = %0
store i32 255, i32* %3
%11 = call i32 @SpiWriteAndRead(i32 0, i32* %3)
%12 = load i32, i32* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @SpiWriteAndRead(i32 0, i32* %3)
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 1, i32* %4
br label %17
17: ; preds = %31, %10
%18 = load i32, i32* %4
%19 = icmp sle i32 %18, 7
br i1 %19, label %20, label %34
20: ; preds = %17
%21 = load i32, i32* %4
%22 = icmp sle i32 %21, 4
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i32, i32* %4
br label %26
25: ; preds = %20
br label %26
26: ; preds = %25, %23
%27 = phi i32 [ %24, %23 ], [ 255, %25 ]
store i32 %27, i32* %3
%28 = call i32 @SpiWriteAndRead(i32 0, i32* %3)
%29 = load i32, i32* %3
%30 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %26
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %17
34: ; preds = %17
%35 = call i32 @SpiClosePort(i32 0)
store i32 0, i32* %1
br label %36
36: ; preds = %34, %8
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [21 x i8] c" response 0: %#x \0D\0A\00"
@.str.1 = [18 x i8] c" response %#x \0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @SpiOpenPort(i32 0)
%3 = icmp eq i32 %2, 1
br i1 %3, label %34, label %4
4: ; preds = %0
%5 = bitcast i32* %1 to i8*
store i32 255, i32* %1
%6 = call i32 @SpiWriteAndRead(i32 0, i32* %1)
%7 = load i32, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 @SpiWriteAndRead(i32 0, i32* %1)
%10 = load i32, i32* %1
%11 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 1, i32* %1
%12 = call i32 @SpiWriteAndRead(i32 0, i32* %1)
%13 = load i32, i32* %1
%14 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 2, i32* %1
%15 = call i32 @SpiWriteAndRead(i32 0, i32* %1)
%16 = load i32, i32* %1
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i32 3, i32* %1
%18 = call i32 @SpiWriteAndRead(i32 0, i32* %1)
%19 = load i32, i32* %1
%20 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 4, i32* %1
%21 = call i32 @SpiWriteAndRead(i32 0, i32* %1)
%22 = load i32, i32* %1
%23 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %22)
store i32 255, i32* %1
%24 = call i32 @SpiWriteAndRead(i32 0, i32* %1)
%25 = load i32, i32* %1
%26 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 255, i32* %1
%27 = call i32 @SpiWriteAndRead(i32 0, i32* %1)
%28 = load i32, i32* %1
%29 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i32 255, i32* %1
%30 = call i32 @SpiWriteAndRead(i32 0, i32* %1)
%31 = load i32, i32* %1
%32 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = call i32 @SpiClosePort(i32 0)
br label %34
34: ; preds = %0, %4
%35 = phi i32 [ 0, %4 ], [ 1, %0 ]
ret i32 %35
}