#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*/ OLED_init();
int SPI_init(int);
int /*<<< orphan*/ gpio_function(int, int /*<<< orphan*/);
int /*<<< orphan*/ gpio_init();
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write_c(int);
int /*<<< orphan*/ write_d(int);
int main(void) {
  int i = 0;
  gpio_init();
  gpio_function(44, 0);
  gpio_function(45, 0);
  gpio_function(43, 0);
  int ClockDivider = 0;
  printf("\n\n");
  printf("   ------------------------------------------\n");
  printf("   |               SPI Sample                |\n");
  printf("   ------------------------------------------\n");
  printf("   |   Direct Register Access SPI Sample     |\n");
  printf("   ------------------------------------------\n");
  printf(" -> Msg<- Initializing SPI port\n");
  int result = SPI_init(ClockDivider);
  printf(" -> Msg<- Result of SPI Init = %d\n", result);
  OLED_init();
  usleep(120000);
  write_c(0x8e);
  write_d(0);
  write_d(0);
  write_d(130);
  write_d(130);
  usleep(100000);
  write_c(0x92);
  write_d(0x01);
  usleep(10000);
  for (i = 0; i < 100; i++) {
    write_c(0x86);
    write_d(rand() % 130);
    write_d(rand() % 130);
    write_d(rand() % 64);
    write_d(rand());
    write_d(rand());
    write_d(rand());
    write_d(rand());
    usleep(10000);
  }
  write_c(0x5c);
  for (i = 0; i < 2000; i++) {
    write_c(0x5c);
    write_d(i);
    write_d(i);
    write_d(i);
  }
  for (;;)
    ;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1080 <gpio_init@plt>
mov    $0x2c,%edi
xor    %esi,%esi
call   1030 <gpio_function@plt>
mov    $0x2d,%edi
xor    %esi,%esi
call   1030 <gpio_function@plt>
mov    $0x2b,%edi
xor    %esi,%esi
call   1030 <gpio_function@plt>
movl   $0x0,-0xc(%rbp)
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1090 <SPI_init@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <OLED_init@plt>
mov    $0x1d4c0,%edi
call   10b0 <usleep@plt>
mov    $0x8e,%edi
call   1060 <write_c@plt>
xor    %edi,%edi
call   1070 <write_d@plt>
xor    %edi,%edi
call   1070 <write_d@plt>
mov    $0x82,%edi
call   1070 <write_d@plt>
mov    $0x82,%edi
call   1070 <write_d@plt>
mov    $0x186a0,%edi
call   10b0 <usleep@plt>
mov    $0x92,%edi
call   1060 <write_c@plt>
mov    $0x1,%edi
call   1070 <write_d@plt>
mov    $0x2710,%edi
call   10b0 <usleep@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    1368 <main+0x1d8>
mov    $0x86,%edi
call   1060 <write_c@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x82,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1070 <write_d@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x82,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1070 <write_d@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x40,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1070 <write_d@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,%edi
call   1070 <write_d@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,%edi
call   1070 <write_d@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,%edi
call   1070 <write_d@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,%edi
call   1070 <write_d@plt>
mov    $0x2710,%edi
call   10b0 <usleep@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12c2 <main+0x132>
mov    $0x5c,%edi
call   1060 <write_c@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x7d0,-0x8(%rbp)
jge    13b6 <main+0x226>
mov    $0x5c,%edi
call   1060 <write_c@plt>
mov    -0x8(%rbp),%edi
call   1070 <write_d@plt>
mov    -0x8(%rbp),%edi
call   1070 <write_d@plt>
mov    -0x8(%rbp),%edi
call   1070 <write_d@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1379 <main+0x1e9>
jmp    13bb <main+0x22b>
jmp    13bb <main+0x22b>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1090 <gpio_init@plt>
mov    $0x2c,%edi
xor    %esi,%esi
call   1030 <gpio_function@plt>
mov    $0x2d,%edi
xor    %esi,%esi
call   1030 <gpio_function@plt>
mov    $0x2b,%edi
xor    %esi,%esi
call   1030 <gpio_function@plt>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
lea    0xea2(%rip),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe99(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10a0 <SPI_init@plt>
lea    0xdd7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1050 <OLED_init@plt>
mov    $0x1d4c0,%edi
call   10c0 <usleep@plt>
mov    $0x8e,%edi
call   1070 <write_c@plt>
xor    %edi,%edi
call   1080 <write_d@plt>
xor    %edi,%edi
call   1080 <write_d@plt>
mov    $0x82,%edi
call   1080 <write_d@plt>
mov    $0x82,%edi
call   1080 <write_d@plt>
mov    $0x186a0,%edi
call   10c0 <usleep@plt>
mov    $0x92,%edi
call   1070 <write_c@plt>
mov    $0x1,%edi
call   1080 <write_d@plt>
mov    $0x2710,%edi
call   10c0 <usleep@plt>
mov    $0x64,%ebx
nopl   0x0(%rax)
mov    $0x86,%edi
call   1070 <write_c@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
movslq %eax,%rdi
imul   $0x7e07e07f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,%ecx
shl    $0x7,%ecx
lea    (%rcx,%rax,2),%eax
sub    %eax,%edi
call   1080 <write_d@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
movslq %eax,%rdi
imul   $0x7e07e07f,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,%ecx
shl    $0x7,%ecx
lea    (%rcx,%rax,2),%eax
sub    %eax,%edi
call   1080 <write_d@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
lea    0x3f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffc0,%ecx
sub    %ecx,%eax
mov    %eax,%edi
call   1080 <write_d@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
mov    %eax,%edi
call   1080 <write_d@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
mov    %eax,%edi
call   1080 <write_d@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
mov    %eax,%edi
call   1080 <write_d@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
mov    %eax,%edi
call   1080 <write_d@plt>
mov    $0x2710,%edi
call   10c0 <usleep@plt>
add    $0xffffffff,%ebx
jne    12a0 <main+0x100>
mov    $0x5c,%edi
call   1070 <write_c@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    $0x5c,%edi
call   1070 <write_c@plt>
mov    %ebx,%edi
call   1080 <write_d@plt>
mov    %ebx,%edi
call   1080 <write_d@plt>
mov    %ebx,%edi
call   1080 <write_d@plt>
add    $0x1,%ebx
cmp    $0x7d0,%ebx
jne    1380 <main+0x1e0>
nopw   0x0(%rax,%rax,1)
jmp    13b0 <main+0x210>

LLVM IR (-O0):
@.str = [3 x i8] c"\0A\0A\00"
@.str.1 = [47 x i8] c" ------------------------------------------\0A\00"
@.str.2 = [48 x i8] c" | SPI Sample |\0A\00"
@.str.3 = [48 x i8] c" | Direct Register Access SPI Sample |\0A\00"
@.str.4 = [33 x i8] c" -> Msg<- Initializing SPI port\0A\00"
@.str.5 = [35 x i8] c" -> Msg<- Result of SPI Init = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%5 = call i32 (...) @gpio_init()
%6 = call i32 @gpio_function(i32 44, i32 0)
%7 = call i32 @gpio_function(i32 45, i32 0)
%8 = call i32 @gpio_function(i32 43, i32 0)
store i32 0, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = call i32 @SPI_init(i32 %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = call i32 (...) @OLED_init()
%21 = call i32 @usleep(i32 120000)
%22 = call i32 @write_c(i32 142)
%23 = call i32 @write_d(i32 0)
%24 = call i32 @write_d(i32 0)
%25 = call i32 @write_d(i32 130)
%26 = call i32 @write_d(i32 130)
%27 = call i32 @usleep(i32 100000)
%28 = call i32 @write_c(i32 146)
%29 = call i32 @write_d(i32 1)
%30 = call i32 @usleep(i32 10000)
store i32 0, i32* %2
br label %31
31: ; preds = %54, %0
%32 = load i32, i32* %2
%33 = icmp slt i32 %32, 100
br i1 %33, label %34, label %57
34: ; preds = %31
%35 = call i32 @write_c(i32 134)
%36 = call i32 (...) @rand()
%37 = srem i32 %36, 130
%38 = call i32 @write_d(i32 %37)
%39 = call i32 (...) @rand()
%40 = srem i32 %39, 130
%41 = call i32 @write_d(i32 %40)
%42 = call i32 (...) @rand()
%43 = srem i32 %42, 64
%44 = call i32 @write_d(i32 %43)
%45 = call i32 (...) @rand()
%46 = call i32 @write_d(i32 %45)
%47 = call i32 (...) @rand()
%48 = call i32 @write_d(i32 %47)
%49 = call i32 (...) @rand()
%50 = call i32 @write_d(i32 %49)
%51 = call i32 (...) @rand()
%52 = call i32 @write_d(i32 %51)
%53 = call i32 @usleep(i32 10000)
br label %54
54: ; preds = %34
%55 = load i32, i32* %2
%56 = add nsw i32 %55, 1
store i32 %56, i32* %2
br label %31
57: ; preds = %31
%58 = call i32 @write_c(i32 92)
store i32 0, i32* %2
br label %59
59: ; preds = %70, %57
%60 = load i32, i32* %2
%61 = icmp slt i32 %60, 2000
br i1 %61, label %62, label %73
62: ; preds = %59
%63 = call i32 @write_c(i32 92)
%64 = load i32, i32* %2
%65 = call i32 @write_d(i32 %64)
%66 = load i32, i32* %2
%67 = call i32 @write_d(i32 %66)
%68 = load i32, i32* %2
%69 = call i32 @write_d(i32 %68)
br label %70
70: ; preds = %62
%71 = load i32, i32* %2
%72 = add nsw i32 %71, 1
store i32 %72, i32* %2
br label %59
73: ; preds = %59
br label %74
74: ; preds = %74, %73
br label %74
}

LLVM IR (-O2):
@.str.5 = [35 x i8] c" -> Msg<- Result of SPI Init = %d\0A\00"
@str = [2 x i8] c"\0A\00"
@str.7 = [47 x i8] c" | SPI Sample |\00"
@str.9 = [47 x i8] c" | Direct Register Access SPI Sample |\00"
@str.10 = [46 x i8] c" ------------------------------------------\00"
@str.11 = [32 x i8] c" -> Msg<- Initializing SPI port\00"
define i32 @main() {
%1 = tail call i32 (...) @gpio_init()
%2 = tail call i32 @gpio_function(i32 44, i32 0)
%3 = tail call i32 @gpio_function(i32 45, i32 0)
%4 = tail call i32 @gpio_function(i32 43, i32 0)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.10, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.7, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.10, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.9, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.10, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.11, i64 0, i64 0))
%12 = tail call i32 @SPI_init(i32 0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i32 %12)
%14 = tail call i32 (...) @OLED_init()
%15 = tail call i32 @usleep(i32 120000)
%16 = tail call i32 @write_c(i32 142)
%17 = tail call i32 @write_d(i32 0)
%18 = tail call i32 @write_d(i32 0)
%19 = tail call i32 @write_d(i32 130)
%20 = tail call i32 @write_d(i32 130)
%21 = tail call i32 @usleep(i32 100000)
%22 = tail call i32 @write_c(i32 146)
%23 = tail call i32 @write_d(i32 1)
%24 = tail call i32 @usleep(i32 10000)
br label %25
25: ; preds = %0, %25
%26 = phi i32 [ 0, %0 ], [ %46, %25 ]
%27 = tail call i32 @write_c(i32 134)
%28 = tail call i32 (...) @rand()
%29 = srem i32 %28, 130
%30 = tail call i32 @write_d(i32 %29)
%31 = tail call i32 (...) @rand()
%32 = srem i32 %31, 130
%33 = tail call i32 @write_d(i32 %32)
%34 = tail call i32 (...) @rand()
%35 = srem i32 %34, 64
%36 = tail call i32 @write_d(i32 %35)
%37 = tail call i32 (...) @rand()
%38 = tail call i32 @write_d(i32 %37)
%39 = tail call i32 (...) @rand()
%40 = tail call i32 @write_d(i32 %39)
%41 = tail call i32 (...) @rand()
%42 = tail call i32 @write_d(i32 %41)
%43 = tail call i32 (...) @rand()
%44 = tail call i32 @write_d(i32 %43)
%45 = tail call i32 @usleep(i32 10000)
%46 = add nuw nsw i32 %26, 1
%47 = icmp eq i32 %46, 100
br i1 %47, label %48, label %25
48: ; preds = %25
%49 = tail call i32 @write_c(i32 92)
br label %50
50: ; preds = %48, %50
%51 = phi i32 [ 0, %48 ], [ %56, %50 ]
%52 = tail call i32 @write_c(i32 92)
%53 = tail call i32 @write_d(i32 %51)
%54 = tail call i32 @write_d(i32 %51)
%55 = tail call i32 @write_d(i32 %51)
%56 = add nuw nsw i32 %51, 1
%57 = icmp eq i32 %56, 2000
br i1 %57, label %58, label %50
58: ; preds = %50, %58
br label %58
}