#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, scalar_t__);
void *gp2x_joystick_read();
int /*<<< orphan*/ kill_running_daemon();
int /*<<< orphan*/ nano_setup();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_FCLK(unsigned int);
scalar_t__ setsid();
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int start_daemon(unsigned int minimal_cpu_speed, unsigned int maximal_cpu_speed,
                 unsigned int start_cpu_speed, int cpu_speed_step,
                 unsigned long hotkey, unsigned long incrementkey,
                 unsigned long decrementkey, int speed_display, int foreground,
                 unsigned long delay) {
  pid_t pid, sid;
  if (!foreground) {
    kill_running_daemon();
    FILE *pidfile = fopen("/tmp/cpu_daemon.pid", "w");
    if (!pidfile) {
      printf("couldn't write pidfile\r\n");
      exit(-2);
    }
    pid = fork();
    if (pid > 0) {
      fprintf(pidfile, "%i\n", pid);
      fclose(pidfile);
    }
    if (pid != 0)
      return pid;
    fclose(pidfile);
    umask(0);
    sid = setsid();
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);
  }
  if (foreground)
    printf("daemon ready\r\n");
  nano_setup();
  unsigned int current_cpu_speed = start_cpu_speed;
  while (1) {
    usleep(delay);
    unsigned long keystate = gp2x_joystick_read();
    unsigned int last_cpu_speed = 0;
    while ((hotkey && (keystate & hotkey) == hotkey) ||
           ((!hotkey) &&
            ((incrementkey && (keystate & incrementkey) == incrementkey) ||
             (decrementkey && (keystate & decrementkey) == decrementkey)))) {
      if (foreground && !last_cpu_speed)
        printf("cpu daemon activated!\r\n");
      if (incrementkey && (keystate & incrementkey) == incrementkey) {
        current_cpu_speed += cpu_speed_step;
        while ((keystate & incrementkey) == incrementkey)
          usleep(100000), keystate = gp2x_joystick_read();
      } else if (decrementkey && (keystate & decrementkey) == decrementkey) {
        current_cpu_speed -= cpu_speed_step;
        while ((keystate & decrementkey) == decrementkey)
          usleep(100000), keystate = gp2x_joystick_read();
      }
      if (current_cpu_speed < minimal_cpu_speed)
        current_cpu_speed = minimal_cpu_speed;
      if (current_cpu_speed > maximal_cpu_speed)
        current_cpu_speed = maximal_cpu_speed;
      if (last_cpu_speed != current_cpu_speed) {
        set_FCLK(current_cpu_speed);
      }
      last_cpu_speed = current_cpu_speed;
      keystate = gp2x_joystick_read();
    }
  }
}


x86 assembly (clang, -O0):
<start_daemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
cmpl   $0x0,0x20(%rbp)
jne    12e0 <start_daemon+0x100>
mov    $0x0,%al
call   1030 <kill_running_daemon@plt>
lea    0xdde(%rip),%rdi
lea    0xdeb(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1253 <start_daemon+0x73>
lea    0xdd2(%rip),%rdi
call   1060 <printf@plt>
mov    $0xfffffffe,%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    1286 <start_daemon+0xa6>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xdb7(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     129b <start_daemon+0xbb>
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10a0 <umask@plt>
mov    $0x0,%al
call   1080 <setsid@plt>
mov    %rax,-0x30(%rbp)
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   1070 <close@plt>
cmpl   $0x0,0x20(%rbp)
je     12f6 <start_daemon+0x116>
lea    0xd42(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <nano_setup@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    0x28(%rbp),%rax
mov    %eax,%edi
call   1100 <usleep@plt>
mov    $0x0,%al
call   10c0 <gp2x_joystick_read@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1342 <start_daemon+0x162>
mov    -0x48(%rbp),%rcx
and    -0x18(%rbp),%rcx
mov    $0x1,%al
cmp    -0x18(%rbp),%rcx
mov    %al,-0x4d(%rbp)
je     13a8 <start_daemon+0x1c8>
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x4e(%rbp)
jne    13a2 <start_daemon+0x1c2>
cmpq   $0x0,-0x20(%rbp)
je     1374 <start_daemon+0x194>
mov    -0x48(%rbp),%rcx
and    -0x20(%rbp),%rcx
mov    $0x1,%al
cmp    -0x20(%rbp),%rcx
mov    %al,-0x4f(%rbp)
je     139c <start_daemon+0x1bc>
xor    %eax,%eax
cmpq   $0x0,0x10(%rbp)
mov    %al,-0x50(%rbp)
je     1396 <start_daemon+0x1b6>
mov    -0x48(%rbp),%rax
and    0x10(%rbp),%rax
cmp    0x10(%rbp),%rax
sete   %al
mov    %al,-0x50(%rbp)
mov    -0x50(%rbp),%al
mov    %al,-0x4f(%rbp)
mov    -0x4f(%rbp),%al
mov    %al,-0x4e(%rbp)
mov    -0x4e(%rbp),%al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    13b8 <start_daemon+0x1d8>
jmp    14db <start_daemon+0x2fb>
cmpl   $0x0,0x20(%rbp)
je     13d8 <start_daemon+0x1f8>
cmpl   $0x0,-0x4c(%rbp)
jne    13d8 <start_daemon+0x1f8>
lea    0xc6f(%rip),%rdi
call   1060 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
je     142f <start_daemon+0x24f>
mov    -0x48(%rbp),%rax
and    -0x20(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    142f <start_daemon+0x24f>
mov    -0x10(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x48(%rbp),%rax
and    -0x20(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    142a <start_daemon+0x24a>
mov    $0x186a0,%edi
call   1100 <usleep@plt>
mov    $0x0,%al
call   10c0 <gp2x_joystick_read@plt>
mov    %rax,-0x48(%rbp)
jmp    13fe <start_daemon+0x21e>
jmp    148d <start_daemon+0x2ad>
cmpq   $0x0,0x10(%rbp)
je     1488 <start_daemon+0x2a8>
mov    -0x48(%rbp),%rax
and    0x10(%rbp),%rax
cmp    0x10(%rbp),%rax
jne    1488 <start_daemon+0x2a8>
mov    -0x10(%rbp),%ecx
mov    -0x3c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x48(%rbp),%rax
and    0x10(%rbp),%rax
cmp    0x10(%rbp),%rax
jne    1483 <start_daemon+0x2a3>
mov    $0x186a0,%edi
call   1100 <usleep@plt>
mov    $0x0,%al
call   10c0 <gp2x_joystick_read@plt>
mov    %rax,-0x48(%rbp)
jmp    1457 <start_daemon+0x277>
jmp    1488 <start_daemon+0x2a8>
jmp    148d <start_daemon+0x2ad>
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    149f <start_daemon+0x2bf>
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jbe    14b1 <start_daemon+0x2d1>
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x3c(%rbp),%eax
je     14c5 <start_daemon+0x2e5>
mov    -0x3c(%rbp),%edi
call   10b0 <set_FCLK@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    $0x0,%al
call   10c0 <gp2x_joystick_read@plt>
mov    %rax,-0x48(%rbp)
jmp    1320 <start_daemon+0x140>
jmp    1303 <start_daemon+0x123>

x86 assembly (clang, -O2):
<start_daemon>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%rbx
mov    %r8,0x8(%rsp)
mov    %ecx,0x4(%rsp)
mov    %edx,%ebp
mov    %esi,0x14(%rsp)
mov    %edi,%r13d
cmpl   $0x0,0x60(%rsp)
je     1344 <start_daemon+0x164>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
mov    0x50(%rsp),%r14
xor    %eax,%eax
call   1050 <nano_setup@plt>
cmpq   $0x0,0x8(%rsp)
setne  0x3(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x68(%rsp),%rdi
call   1100 <usleep@plt>
xor    %r12d,%r12d
nopl   (%rax)
xor    %eax,%eax
call   10c0 <gp2x_joystick_read@plt>
mov    %rax,%r15
not    %rax
test   %rax,0x8(%rsp)
sete   %al
test   %al,0x3(%rsp)
jne    1293 <start_daemon+0xb3>
cmpq   $0x0,0x8(%rsp)
jne    1240 <start_daemon+0x60>
mov    %r15,%rax
and    %rbx,%rax
test   %rbx,%rbx
je     1283 <start_daemon+0xa3>
cmp    %rbx,%rax
je     1293 <start_daemon+0xb3>
mov    %r15,%rax
and    %r14,%rax
test   %r14,%r14
je     1240 <start_daemon+0x60>
cmp    %r14,%rax
jne    1240 <start_daemon+0x60>
cmpl   $0x0,0x60(%rsp)
je     12ab <start_daemon+0xcb>
test   %r12d,%r12d
jne    12ab <start_daemon+0xcb>
lea    0xd8c(%rip),%rdi
call   1030 <puts@plt>
test   %rbx,%rbx
je     12e0 <start_daemon+0x100>
mov    %r15,%rax
and    %rbx,%rax
cmp    %rbx,%rax
jne    12e0 <start_daemon+0x100>
add    0x4(%rsp),%ebp
nop
mov    $0x186a0,%edi
call   1100 <usleep@plt>
xor    %eax,%eax
call   10c0 <gp2x_joystick_read@plt>
not    %rax
test   %rax,%rbx
je     12c0 <start_daemon+0xe0>
jmp    1319 <start_daemon+0x139>
nopl   0x0(%rax,%rax,1)
test   %r14,%r14
je     1319 <start_daemon+0x139>
and    %r14,%r15
cmp    %r14,%r15
jne    1319 <start_daemon+0x139>
sub    0x4(%rsp),%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x186a0,%edi
call   1100 <usleep@plt>
xor    %eax,%eax
call   10c0 <gp2x_joystick_read@plt>
not    %rax
test   %rax,%r14
je     1300 <start_daemon+0x120>
cmp    %r13d,%ebp
cmovb  %r13d,%ebp
mov    0x14(%rsp),%eax
cmp    %eax,%ebp
cmova  %eax,%ebp
cmp    %ebp,%r12d
mov    %ebp,%r12d
je     1250 <start_daemon+0x70>
mov    %ebp,%edi
call   10b0 <set_FCLK@plt>
mov    %ebp,%r12d
jmp    1250 <start_daemon+0x70>
xor    %eax,%eax
call   1040 <kill_running_daemon@plt>
lea    0xcae(%rip),%rdi
lea    0xcbb(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     13ee <start_daemon+0x20e>
mov    %rax,%r14
xor    %eax,%eax
call   10f0 <fork@plt>
mov    %rax,%r15
test   %rax,%rax
jle    1395 <start_daemon+0x1b5>
lea    0xc96(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   1090 <fprintf@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
jmp    1397 <start_daemon+0x1b7>
je     13a9 <start_daemon+0x1c9>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %edi,%edi
call   10a0 <umask@plt>
xor    %eax,%eax
call   1080 <setsid@plt>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    0x2c1c(%rip),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
call   1070 <close@plt>
jmp    121a <start_daemon+0x3a>
lea    0xc25(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"/tmp/cpu_daemon.pid\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"couldn't write pidfile\0D\0A\00"
@.str.3 = [4 x i8] c"%i\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@.str.4 = [15 x i8] c"daemon ready\0D\0A\00"
@.str.5 = [24 x i8] c"cpu daemon activated!\0D\0A\00"
define i32 @start_daemon(i32 %0, i32 %1, i32 %2, i32 %3, i64 %4, i64 %5, i64 %6, i32 %7, i32 %8, i64 %9) {
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i32
%19 = alloca i32
%20 = alloca i64
%21 = alloca i64
%22 = alloca i64
%23 = alloca i32*
%24 = alloca i32
%25 = alloca i64
%26 = alloca i32
store i32 %0, i32* %11
store i32 %1, i32* %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i64 %4, i64* %15
store i64 %5, i64* %16
store i64 %6, i64* %17
store i32 %7, i32* %18
store i32 %8, i32* %19
store i64 %9, i64* %20
%27 = load i32, i32* %19
%28 = icmp ne i32 %27, 0
br i1 %28, label %64, label %29
29: ; preds = %10
%30 = call i32 (...) @kill_running_daemon()
%31 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %23
%32 = load i32*, i32** %23
%33 = icmp ne i32* %32, null
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 -2)
unreachable
37: ; preds = %29
%38 = call i64 (...) @fork()
store i64 %38, i64* %21
%39 = load i64, i64* %21
%40 = icmp sgt i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i32*, i32** %23
%43 = load i64, i64* %21
%44 = call i32 @fprintf(i32* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %43)
%45 = load i32*, i32** %23
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %41, %37
%48 = load i64, i64* %21
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i64, i64* %21
%52 = trunc i64 %51 to i32
ret i32 %52
53: ; preds = %47
%54 = load i32*, i32** %23
%55 = call i32 @fclose(i32* %54)
%56 = call i32 @umask(i32 0)
%57 = call i64 (...) @setsid()
store i64 %57, i64* %22
%58 = load i32, i32* @STDIN_FILENO
%59 = call i32 @close(i32 %58)
%60 = load i32, i32* @STDOUT_FILENO
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* @STDERR_FILENO
%63 = call i32 @close(i32 %62)
br label %64
64: ; preds = %53, %10
%65 = load i32, i32* %19
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %64
%68 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %69
69: ; preds = %67, %64
%70 = call i32 (...) @nano_setup()
%71 = load i32, i32* %13
store i32 %71, i32* %24
br label %72
72: ; preds = %69, %196
%73 = load i64, i64* %20
%74 = trunc i64 %73 to i32
%75 = call i32 @usleep(i32 %74)
%76 = call i8* (...) @gp2x_joystick_read()
%77 = ptrtoint i8* %76 to i64
store i64 %77, i64* %25
store i32 0, i32* %26
br label %78
78: ; preds = %192, %72
%79 = load i64, i64* %15
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %87
81: ; preds = %78
%82 = load i64, i64* %25
%83 = load i64, i64* %15
%84 = and i64 %82, %83
%85 = load i64, i64* %15
%86 = icmp eq i64 %84, %85
br i1 %86, label %114, label %87
87: ; preds = %81, %78
%88 = load i64, i64* %15
%89 = icmp ne i64 %88, 0
br i1 %89, label %112, label %90
90: ; preds = %87
%91 = load i64, i64* %16
%92 = icmp ne i64 %91, 0
br i1 %92, label %93, label %99
93: ; preds = %90
%94 = load i64, i64* %25
%95 = load i64, i64* %16
%96 = and i64 %94, %95
%97 = load i64, i64* %16
%98 = icmp eq i64 %96, %97
br i1 %98, label %110, label %99
99: ; preds = %93, %90
%100 = load i64, i64* %17
%101 = icmp ne i64 %100, 0
br i1 %101, label %102, label %108
102: ; preds = %99
%103 = load i64, i64* %25
%104 = load i64, i64* %17
%105 = and i64 %103, %104
%106 = load i64, i64* %17
%107 = icmp eq i64 %105, %106
br label %108
108: ; preds = %102, %99
%109 = phi i1 [ false, %99 ], [ %107, %102 ]
br label %110
110: ; preds = %108, %93
%111 = phi i1 [ true, %93 ], [ %109, %108 ]
br label %112
112: ; preds = %110, %87
%113 = phi i1 [ false, %87 ], [ %111, %110 ]
br label %114
114: ; preds = %112, %81
%115 = phi i1 [ true, %81 ], [ %113, %112 ]
br i1 %115, label %116, label %196
116: ; preds = %114
%117 = load i32, i32* %19
%118 = icmp ne i32 %117, 0
br i1 %118, label %119, label %124
119: ; preds = %116
%120 = load i32, i32* %26
%121 = icmp ne i32 %120, 0
br i1 %121, label %124, label %122
122: ; preds = %119
%123 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %124
124: ; preds = %122, %119, %116
%125 = load i64, i64* %16
%126 = icmp ne i64 %125, 0
br i1 %126, label %127, label %148
127: ; preds = %124
%128 = load i64, i64* %25
%129 = load i64, i64* %16
%130 = and i64 %128, %129
%131 = load i64, i64* %16
%132 = icmp eq i64 %130, %131
br i1 %132, label %133, label %148
133: ; preds = %127
%134 = load i32, i32* %14
%135 = load i32, i32* %24
%136 = add i32 %135, %134
store i32 %136, i32* %24
br label %137
137: ; preds = %143, %133
%138 = load i64, i64* %25
%139 = load i64, i64* %16
%140 = and i64 %138, %139
%141 = load i64, i64* %16
%142 = icmp eq i64 %140, %141
br i1 %142, label %143, label %147
143: ; preds = %137
%144 = call i32 @usleep(i32 100000)
%145 = call i8* (...) @gp2x_joystick_read()
%146 = ptrtoint i8* %145 to i64
store i64 %146, i64* %25
br label %137
147: ; preds = %137
br label %173
148: ; preds = %127, %124
%149 = load i64, i64* %17
%150 = icmp ne i64 %149, 0
br i1 %150, label %151, label %172
151: ; preds = %148
%152 = load i64, i64* %25
%153 = load i64, i64* %17
%154 = and i64 %152, %153
%155 = load i64, i64* %17
%156 = icmp eq i64 %154, %155
br i1 %156, label %157, label %172
157: ; preds = %151
%158 = load i32, i32* %14
%159 = load i32, i32* %24
%160 = sub i32 %159, %158
store i32 %160, i32* %24
br label %161
161: ; preds = %167, %157
%162 = load i64, i64* %25
%163 = load i64, i64* %17
%164 = and i64 %162, %163
%165 = load i64, i64* %17
%166 = icmp eq i64 %164, %165
br i1 %166, label %167, label %171
167: ; preds = %161
%168 = call i32 @usleep(i32 100000)
%169 = call i8* (...) @gp2x_joystick_read()
%170 = ptrtoint i8* %169 to i64
store i64 %170, i64* %25
br label %161
171: ; preds = %161
br label %172
172: ; preds = %171, %151, %148
br label %173
173: ; preds = %172, %147
%174 = load i32, i32* %24
%175 = load i32, i32* %11
%176 = icmp ult i32 %174, %175
br i1 %176, label %177, label %179
177: ; preds = %173
%178 = load i32, i32* %11
store i32 %178, i32* %24
br label %179
179: ; preds = %177, %173
%180 = load i32, i32* %24
%181 = load i32, i32* %12
%182 = icmp ugt i32 %180, %181
br i1 %182, label %183, label %185
183: ; preds = %179
%184 = load i32, i32* %12
store i32 %184, i32* %24
br label %185
185: ; preds = %183, %179
%186 = load i32, i32* %26
%187 = load i32, i32* %24
%188 = icmp ne i32 %186, %187
br i1 %188, label %189, label %192
189: ; preds = %185
%190 = load i32, i32* %24
%191 = call i32 @set_FCLK(i32 %190)
br label %192
192: ; preds = %189, %185
%193 = load i32, i32* %24
store i32 %193, i32* %26
%194 = call i8* (...) @gp2x_joystick_read()
%195 = ptrtoint i8* %194 to i64
store i64 %195, i64* %25
br label %78
196: ; preds = %114
br label %72
}

LLVM IR (-O2):
@.str = [20 x i8] c"/tmp/cpu_daemon.pid\00"
@.str.1 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%i\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@str = [24 x i8] c"couldn't write pidfile\0D\00"
@str.6 = [23 x i8] c"cpu daemon activated!\0D\00"
@str.7 = [14 x i8] c"daemon ready\0D\00"
define i32 @start_daemon(i32 %0, i32 %1, i32 %2, i32 %3, i64 %4, i64 %5, i64 %6, i32 %7, i32 %8, i64 %9) {
%11 = icmp eq i32 %8, 0
br i1 %11, label %12, label %37
12: ; preds = %10
%13 = tail call i32 (...) @kill_running_daemon()
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -2)
unreachable
19: ; preds = %12
%20 = tail call i64 (...) @fork()
%21 = icmp sgt i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = icmp eq i64 %20, 0
br i1 %23, label %27, label %106
24: ; preds = %19
%25 = tail call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %20)
%26 = tail call i32 @fclose(i32* %14)
br label %106
27: ; preds = %22
%28 = tail call i32 @fclose(i32* %14)
%29 = tail call i32 @umask(i32 0)
%30 = tail call i64 (...) @setsid()
%31 = load i32, i32* @STDIN_FILENO
%32 = tail call i32 @close(i32 %31)
%33 = load i32, i32* @STDOUT_FILENO
%34 = tail call i32 @close(i32 %33)
%35 = load i32, i32* @STDERR_FILENO
%36 = tail call i32 @close(i32 %35)
br label %39
37: ; preds = %10
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
br label %39
39: ; preds = %27, %37
%40 = tail call i32 (...) @nano_setup()
%41 = trunc i64 %9 to i32
%42 = icmp eq i64 %4, 0
%43 = xor i1 %42, true
%44 = icmp ne i64 %5, 0
%45 = icmp ne i64 %6, 0
br label %47
46: ; preds = %63, %58
br label %47
47: ; preds = %46, %39
%48 = phi i32 [ %2, %39 ], [ %51, %46 ]
%49 = tail call i32 @usleep(i32 %41)
br label %50
50: ; preds = %105, %47
%51 = phi i32 [ %48, %47 ], [ %101, %105 ]
%52 = phi i32 [ 0, %47 ], [ %101, %105 ]
%53 = tail call i8* (...) @gp2x_joystick_read()
%54 = ptrtoint i8* %53 to i64
%55 = and i64 %54, %4
%56 = icmp eq i64 %55, %4
%57 = select i1 %43, i1 %56, i1 false
br i1 %57, label %67, label %58
58: ; preds = %50
br i1 %42, label %59, label %46
59: ; preds = %58
%60 = and i64 %54, %5
%61 = icmp eq i64 %60, %5
%62 = select i1 %44, i1 %61, i1 false
br i1 %62, label %67, label %63
63: ; preds = %59
%64 = and i64 %54, %6
%65 = icmp eq i64 %64, %6
%66 = select i1 %45, i1 %65, i1 false
br i1 %66, label %67, label %46
67: ; preds = %63, %59, %50
%68 = icmp ne i32 %52, 0
%69 = select i1 %11, i1 true, i1 %68
br i1 %69, label %72, label %70
70: ; preds = %67
%71 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
br label %72
72: ; preds = %70, %67
%73 = and i64 %54, %5
%74 = icmp eq i64 %73, %5
%75 = select i1 %44, i1 %74, i1 false
br i1 %75, label %76, label %84
76: ; preds = %72
%77 = add i32 %51, %3
br label %78
78: ; preds = %76, %78
%79 = tail call i32 @usleep(i32 100000)
%80 = tail call i8* (...) @gp2x_joystick_read()
%81 = ptrtoint i8* %80 to i64
%82 = and i64 %81, %5
%83 = icmp eq i64 %82, %5
br i1 %83, label %78, label %96
84: ; preds = %72
%85 = and i64 %54, %6
%86 = icmp eq i64 %85, %6
%87 = select i1 %45, i1 %86, i1 false
br i1 %87, label %88, label %96
88: ; preds = %84
%89 = sub i32 %51, %3
br label %90
90: ; preds = %88, %90
%91 = tail call i32 @usleep(i32 100000)
%92 = tail call i8* (...) @gp2x_joystick_read()
%93 = ptrtoint i8* %92 to i64
%94 = and i64 %93, %6
%95 = icmp eq i64 %94, %6
br i1 %95, label %90, label %96
96: ; preds = %90, %78, %84
%97 = phi i32 [ %51, %84 ], [ %77, %78 ], [ %89, %90 ]
%98 = icmp ult i32 %97, %0
%99 = select i1 %98, i32 %0, i32 %97
%100 = icmp ugt i32 %99, %1
%101 = select i1 %100, i32 %1, i32 %99
%102 = icmp eq i32 %52, %101
br i1 %102, label %105, label %103
103: ; preds = %96
%104 = tail call i32 @set_FCLK(i32 %101)
br label %105
105: ; preds = %103, %96
br label %50
106: ; preds = %22, %24
%107 = trunc i64 %20 to i32
ret i32 %107
}