#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 /*<<< orphan*/ WINDOW;

/* Variables and functions */
int /*<<< orphan*/ clear();
int /*<<< orphan*/ getstr(char *);
scalar_t__ gpio_init();
int /*<<< orphan*/ *initscr();
int /*<<< orphan*/ mode_move();
int /*<<< orphan*/ mode_quit();
int /*<<< orphan*/ mode_scan();
int /*<<< orphan*/ mode_step();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ printw(char *);
int /*<<< orphan*/ scanner_init();
scalar_t__ strcmp(char *, char *);
int main(void) {
  scanner_init();
  if (gpio_init()) {
    mode_quit();
  }
  WINDOW *win = initscr();
  char usermode[10];
  bool error = 0;
  while (1) {
    printw("Written by Samuel Riolo 2014\n");
    printw("Raspberry PI\n");
    printw("RPI GPIO\n\n");
    printw("Choose a mode: step, move, scan or quit\n");
    if (error)
      printw("Command not found! ");
    error = 0;
    printw("> ");
    getstr(usermode);
    if (strcmp(usermode, "scan") == 0) {
      mode_scan();
    } else if (strcmp(usermode, "step") == 0) {
      mode_step();
    } else if (strcmp(usermode, "move") == 0) {
      printf("Press spacebar to move or ESC to come back to main menu");
      mode_move();
    } else if (strcmp(usermode, "quit") == 0) {
      mode_quit();
    } else {
      error = 1;
    }
    clear();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <scanner_init@plt>
mov    $0x0,%al
call   10e0 <gpio_init@plt>
cmp    $0x0,%rax
je     11ee <main+0x2e>
mov    $0x0,%al
call   1080 <mode_quit@plt>
mov    $0x0,%al
call   1070 <initscr@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xdf9(%rip),%rdi
call   10c0 <printw@plt>
lea    0xe0b(%rip),%rdi
call   10c0 <printw@plt>
lea    0xe0d(%rip),%rdi
call   10c0 <printw@plt>
lea    0xe0c(%rip),%rdi
call   10c0 <printw@plt>
cmpl   $0x0,-0x20(%rbp)
je     1246 <main+0x86>
lea    0xe1f(%rip),%rdi
call   10c0 <printw@plt>
movl   $0x0,-0x20(%rbp)
lea    0xe20(%rip),%rdi
call   10c0 <printw@plt>
lea    -0x1a(%rbp),%rdi
call   10a0 <getstr@plt>
lea    -0x1a(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    1288 <main+0xc8>
mov    $0x0,%al
call   1050 <mode_scan@plt>
jmp    131c <main+0x15c>
lea    -0x1a(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    12ae <main+0xee>
mov    $0x0,%al
call   1030 <mode_step@plt>
jmp    1317 <main+0x157>
lea    -0x1a(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    12e0 <main+0x120>
lea    0xdb7(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1090 <mode_move@plt>
jmp    1312 <main+0x152>
lea    -0x1a(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    1306 <main+0x146>
mov    $0x0,%al
call   1080 <mode_quit@plt>
jmp    130d <main+0x14d>
movl   $0x1,-0x20(%rbp)
jmp    1312 <main+0x152>
jmp    1317 <main+0x157>
jmp    131c <main+0x15c>
mov    $0x0,%al
call   10d0 <clear@plt>
jmp    1200 <main+0x40>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1040 <scanner_init@plt>
xor    %eax,%eax
call   10e0 <gpio_init@plt>
test   %rax,%rax
je     11e8 <main+0x28>
xor    %eax,%eax
call   1080 <mode_quit@plt>
xor    %eax,%eax
call   1070 <initscr@plt>
lea    0xe36(%rip),%r12
lea    0xe3a(%rip),%r13
lea    0xe70(%rip),%rbx
lea    0xe(%rsp),%rbp
lea    0xe67(%rip),%r14
xor    %r15d,%r15d
jmp    1231 <main+0x71>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %r15d,%r15d
xor    %eax,%eax
call   1050 <mode_scan@plt>
xor    %eax,%eax
call   10d0 <clear@plt>
lea    0xdc8(%rip),%rdi
call   10c0 <printw@plt>
lea    0xdda(%rip),%rdi
call   10c0 <printw@plt>
mov    %r12,%rdi
call   10c0 <printw@plt>
mov    %r13,%rdi
call   10c0 <printw@plt>
test   %r15d,%r15d
je     126a <main+0xaa>
lea    0xdfb(%rip),%rdi
call   10c0 <printw@plt>
mov    %rbx,%rdi
call   10c0 <printw@plt>
mov    %rbp,%rdi
call   10a0 <getstr@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     1220 <main+0x60>
mov    %rbp,%rdi
lea    0xde8(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     12e0 <main+0x120>
mov    %rbp,%rdi
lea    0xdd9(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     12ef <main+0x12f>
mov    %rbp,%rdi
lea    0xe02(%rip),%rsi
call   10b0 <strcmp@plt>
mov    $0x1,%r15d
test   %rax,%rax
jne    122a <main+0x6a>
xor    %r15d,%r15d
xor    %eax,%eax
call   1080 <mode_quit@plt>
jmp    122a <main+0x6a>
nop
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <mode_step@plt>
jmp    122a <main+0x6a>
lea    0xd90(%rip),%rdi
call   1060 <printf@plt>
xor    %r15d,%r15d
xor    %eax,%eax
call   1090 <mode_move@plt>
jmp    122a <main+0x6a>

LLVM IR (-O0):
@.str = [30 x i8] c"Written by Samuel Riolo 2014\0A\00"
@.str.1 = [14 x i8] c"Raspberry PI\0A\00"
@.str.2 = [11 x i8] c"RPI GPIO\0A\0A\00"
@.str.3 = [41 x i8] c"Choose a mode: step, move, scan or quit\0A\00"
@.str.4 = [20 x i8] c"Command not found! \00"
@.str.5 = [3 x i8] c"> \00"
@.str.6 = [5 x i8] c"scan\00"
@.str.7 = [5 x i8] c"step\00"
@.str.8 = [5 x i8] c"move\00"
@.str.9 = [56 x i8] c"Press spacebar to move or ESC to come back to main menu\00"
@.str.10 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [10 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @scanner_init()
%6 = call i64 (...) @gpio_init()
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (...) @mode_quit()
br label %10
10: ; preds = %8, %0
%11 = call i32* (...) @initscr()
store i32* %11, i32** %2
store i32 0, i32* %4
br label %12
12: ; preds = %10, %53
%13 = call i32 @printw(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @printw(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @printw(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @printw(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @printw(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %19, %12
store i32 0, i32* %4
%22 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%24 = call i32 @getstr(i8* %23)
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 (...) @mode_scan()
br label %53
30: ; preds = %21
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 (...) @mode_step()
br label %52
36: ; preds = %30
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.9, i64 0, i64 0))
%42 = call i32 (...) @mode_move()
br label %51
43: ; preds = %36
%44 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 (...) @mode_quit()
br label %50
49: ; preds = %43
store i32 1, i32* %4
br label %50
50: ; preds = %49, %47
br label %51
51: ; preds = %50, %40
br label %52
52: ; preds = %51, %34
br label %53
53: ; preds = %52, %28
%54 = call i32 (...) @clear()
br label %12
}

LLVM IR (-O2):
@.str = [30 x i8] c"Written by Samuel Riolo 2014\0A\00"
@.str.1 = [14 x i8] c"Raspberry PI\0A\00"
@.str.2 = [11 x i8] c"RPI GPIO\0A\0A\00"
@.str.3 = [41 x i8] c"Choose a mode: step, move, scan or quit\0A\00"
@.str.4 = [20 x i8] c"Command not found! \00"
@.str.5 = [3 x i8] c"> \00"
@.str.6 = [5 x i8] c"scan\00"
@.str.7 = [5 x i8] c"step\00"
@.str.8 = [5 x i8] c"move\00"
@.str.9 = [56 x i8] c"Press spacebar to move or ESC to come back to main menu\00"
@.str.10 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = tail call i32 (...) @scanner_init()
%3 = tail call i64 (...) @gpio_init()
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 (...) @mode_quit()
br label %7
7: ; preds = %5, %0
%8 = tail call i32* (...) @initscr()
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
br label %10
10: ; preds = %42, %7
%11 = phi i32 [ 0, %7 ], [ %43, %42 ]
%12 = call i32 @printw(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @printw(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @printw(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @printw(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i32 %11, 0
br i1 %16, label %19, label %17
17: ; preds = %10
%18 = call i32 @printw(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %17, %10
%20 = call i32 @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 @getstr(i8* %9)
%22 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (...) @mode_scan()
br label %42
26: ; preds = %19
%27 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 (...) @mode_step()
br label %42
31: ; preds = %26
%32 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.9, i64 0, i64 0))
%36 = call i32 (...) @mode_move()
br label %42
37: ; preds = %31
%38 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 (...) @mode_quit()
br label %42
42: ; preds = %37, %29, %40, %34, %24
%43 = phi i32 [ 0, %24 ], [ 0, %29 ], [ 0, %34 ], [ 0, %40 ], [ 1, %37 ]
%44 = call i32 (...) @clear()
br label %10
}