#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*/ ArduCAM(int);
int /*<<< orphan*/ InitCAM();
int /*<<< orphan*/ InitLCD();
int /*<<< orphan*/ UTFT();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rdSensorReg8_8(int, int *);
int read_reg(int);
int /*<<< orphan*/ set_format(int /*<<< orphan*/);
int /*<<< orphan*/ write_reg(int, int);
void setup() {
  uint8_t vid, pid;
  uint8_t temp;
  UTFT();
  ArduCAM(5);
  printf("ArduCAM Start!\n");
  write_reg(0x00, 0x55);
  temp = read_reg(0x00);
  if (temp != 0x55) {
    printf("SPI interface Error!\n");
    while (1)
      ;
  }
  write_reg(0x02, 0x00);
  InitLCD();
  rdSensorReg8_8(0x0A, &vid);
  rdSensorReg8_8(0x0B, &pid);
  if ((vid != 0x26) || (pid != 0x42))
    printf("Can't find OV2640 module!\n");
  else
    printf("OV2640 detected\n");
  set_format(0);
  InitCAM();
}


x86 assembly (clang, -O0):
<setup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1090 <UTFT@plt>
mov    $0x5,%edi
call   1070 <ArduCAM@plt>
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
mov    $0x55,%esi
call   1030 <write_reg@plt>
xor    %edi,%edi
call   1060 <read_reg@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x55,-0xc(%rbp)
je     11e6 <setup+0x56>
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
jmp    11e1 <setup+0x51>
mov    $0x2,%edi
xor    %esi,%esi
call   1030 <write_reg@plt>
mov    $0x0,%al
call   10b0 <InitLCD@plt>
mov    $0xa,%edi
lea    -0x4(%rbp),%rsi
call   1050 <rdSensorReg8_8@plt>
mov    $0xb,%edi
lea    -0x8(%rbp),%rsi
call   1050 <rdSensorReg8_8@plt>
cmpl   $0x26,-0x4(%rbp)
jne    1229 <setup+0x99>
cmpl   $0x42,-0x8(%rbp)
je     123a <setup+0xaa>
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
jmp    1246 <setup+0xb6>
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <set_format@plt>
mov    $0x0,%al
call   1080 <InitCAM@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup>:
push   %rax
xor    %eax,%eax
call   1090 <UTFT@plt>
mov    $0x5,%edi
call   1070 <ArduCAM@plt>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
mov    $0x55,%esi
call   1040 <write_reg@plt>
xor    %edi,%edi
call   1060 <read_reg@plt>
cmp    $0x55,%eax
jne    122b <setup+0x9b>
mov    $0x2,%edi
xor    %esi,%esi
call   1040 <write_reg@plt>
xor    %eax,%eax
call   10b0 <InitLCD@plt>
lea    0x4(%rsp),%rsi
mov    $0xa,%edi
call   1050 <rdSensorReg8_8@plt>
mov    %rsp,%rsi
mov    $0xb,%edi
call   1050 <rdSensorReg8_8@plt>
mov    0x4(%rsp),%eax
xor    $0x26,%eax
mov    (%rsp),%ecx
xor    $0x42,%ecx
lea    0xe16(%rip),%rdx
lea    0xdff(%rip),%rdi
or     %eax,%ecx
cmovne %rdx,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <set_format@plt>
xor    %eax,%eax
call   1080 <InitCAM@plt>
pop    %rax
ret
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
nopw   0x0(%rax,%rax,1)
jmp    1240 <setup+0xb0>

LLVM IR (-O0):
@.str = [16 x i8] c"ArduCAM Start!\0A\00"
@.str.1 = [22 x i8] c"SPI interface Error!\0A\00"
@.str.2 = [27 x i8] c"Can't find OV2640 module!\0A\00"
@.str.3 = [17 x i8] c"OV2640 detected\0A\00"
define void @setup() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @UTFT()
%5 = call i32 @ArduCAM(i32 5)
%6 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @write_reg(i32 0, i32 85)
%8 = call i32 @read_reg(i32 0)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 85
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %13
br label %13
14: ; preds = %0
%15 = call i32 @write_reg(i32 2, i32 0)
%16 = call i32 (...) @InitLCD()
%17 = call i32 @rdSensorReg8_8(i32 10, i32* %1)
%18 = call i32 @rdSensorReg8_8(i32 11, i32* %2)
%19 = load i32, i32* %1
%20 = icmp ne i32 %19, 38
br i1 %20, label %24, label %21
21: ; preds = %14
%22 = load i32, i32* %2
%23 = icmp ne i32 %22, 66
br i1 %23, label %24, label %26
24: ; preds = %21, %14
%25 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %28
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %24
%29 = call i32 @set_format(i32 0)
%30 = call i32 (...) @InitCAM()
ret void
}

LLVM IR (-O2):
@str = [15 x i8] c"ArduCAM Start!\00"
@str.4 = [16 x i8] c"OV2640 detected\00"
@str.5 = [26 x i8] c"Can't find OV2640 module!\00"
@str.6 = [21 x i8] c"SPI interface Error!\00"
define void @setup() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (...) @UTFT()
%6 = tail call i32 @ArduCAM(i32 5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @write_reg(i32 0, i32 85)
%9 = tail call i32 @read_reg(i32 0)
%10 = icmp eq i32 %9, 85
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
br label %13
13: ; preds = %13, %11
br label %13
14: ; preds = %0
%15 = tail call i32 @write_reg(i32 2, i32 0)
%16 = tail call i32 (...) @InitLCD()
%17 = call i32 @rdSensorReg8_8(i32 10, i32* %1)
%18 = call i32 @rdSensorReg8_8(i32 11, i32* %2)
%19 = load i32, i32* %1
%20 = icmp ne i32 %19, 38
%21 = load i32, i32* %2
%22 = icmp ne i32 %21, 66
%23 = select i1 %20, i1 true, i1 %22
%24 = select i1 %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0)
%25 = call i32 @puts(i8* dereferenceable(1) %24)
%26 = call i32 @set_format(i32 0)
%27 = call i32 (...) @InitCAM()
ret void
}