#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*/ cdc_init();
int /*<<< orphan*/ is_external_clock_avail();
int /*<<< orphan*/ jtag_init();
int /*<<< orphan*/ led_init();
int /*<<< orphan*/ np_handler();
int /*<<< orphan*/ np_init();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ uart_init();
int /*<<< orphan*/ usb_init();
int main() {
  uart_init();
  printf("\r\nNAND programmer ver: %d.%d.%d\r\n", 3, 4, 1);
  if (!is_external_clock_avail())
    printf("External clock not detected. Fallback to internal clock.\r\n");
  printf("JTAG init...");
  jtag_init();
  printf("done.\r\n");
  printf("LED init...");
  led_init();
  printf("done.\r\n");
  printf("USB init...");
  usb_init();
  printf("done.\r\n");
  printf("CDC init...");
  cdc_init();
  printf("done.\r\n");
  printf("Programmer init...");
  np_init();
  printf("done.\r\n");
  while (1)
    np_handler();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <uart_init@plt>
lea    0xe53(%rip),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
mov    $0x1,%ecx
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <is_external_clock_avail@plt>
cmp    $0x0,%eax
jne    11e1 <main+0x51>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10b0 <jtag_init@plt>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <led_init@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <usb_init@plt>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <cdc_init@plt>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10a0 <np_init@plt>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <np_handler@plt>
jmp    1290 <main+0x100>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1050 <uart_init@plt>
lea    0xe51(%rip),%rdi
mov    $0x3,%esi
mov    $0x4,%edx
mov    $0x1,%ecx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1090 <is_external_clock_avail@plt>
test   %eax,%eax
jne    11dc <main+0x3c>
lea    0xe8f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10c0 <jtag_init@plt>
lea    0xea8(%rip),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe28(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <led_init@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10a0 <usb_init@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <cdc_init@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xdf5(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   10b0 <np_init@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <np_handler@plt>
jmp    1280 <main+0xe0>

LLVM IR (-O0):
@.str = [34 x i8] c"\0D\0ANAND programmer ver: %d.%d.%d\0D\0A\00"
@.str.1 = [59 x i8] c"External clock not detected. Fallback to internal clock.\0D\0A\00"
@.str.2 = [13 x i8] c"JTAG init...\00"
@.str.3 = [8 x i8] c"done.\0D\0A\00"
@.str.4 = [12 x i8] c"LED init...\00"
@.str.5 = [12 x i8] c"USB init...\00"
@.str.6 = [12 x i8] c"CDC init...\00"
@.str.7 = [19 x i8] c"Programmer init...\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (...) @uart_init()
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 3, i32 4, i32 1)
%4 = call i32 (...) @is_external_clock_avail()
%5 = icmp ne i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (...) @jtag_init()
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 (...) @led_init()
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 (...) @usb_init()
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%19 = call i32 (...) @cdc_init()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%22 = call i32 (...) @np_init()
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %8, %24
%25 = call i32 (...) @np_handler()
br label %24
}

LLVM IR (-O2):
@.str = [34 x i8] c"\0D\0ANAND programmer ver: %d.%d.%d\0D\0A\00"
@.str.2 = [13 x i8] c"JTAG init...\00"
@.str.4 = [12 x i8] c"LED init...\00"
@.str.5 = [12 x i8] c"USB init...\00"
@.str.6 = [12 x i8] c"CDC init...\00"
@.str.7 = [19 x i8] c"Programmer init...\00"
@str = [58 x i8] c"External clock not detected. Fallback to internal clock.\0D\00"
@str.12 = [7 x i8] c"done.\0D\00"
define i32 @main() {
%1 = tail call i32 (...) @uart_init()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 3, i32 4, i32 1)
%3 = tail call i32 (...) @is_external_clock_avail()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 (...) @jtag_init()
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i32 (...) @led_init()
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.12, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%15 = tail call i32 (...) @usb_init()
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.12, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%18 = tail call i32 (...) @cdc_init()
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.12, i64 0, i64 0))
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%21 = tail call i32 (...) @np_init()
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.12, i64 0, i64 0))
br label %23
23: ; preds = %7, %23
%24 = tail call i32 (...) @np_handler()
br label %23
}