// File: /workspace/github_c_makefile_star2_O2/kobolt[P]curses-collection/racer/racer.c
// Function: main
int main(int argc, char *argv[])
{
  int c;
  bool disable_color = false;
  bool disable_ascii = false;
  int ch;
  int player_speed = 5;
  int player_hpos = 25;
  int cars_passed = 0;
  int curve = 0;
  bool quit = false;
  car_t cars[CARS_MAX];

  srandom(time(NULL));

  /* Initialize: */
  for (int i = 0; i < CARS_MAX; i++) {
    cars[i].distance = 0;
    car_init(&cars[i], false);
  }

  while ((c = getopt(argc, argv, "hca")) != -1) {
    switch (c) {
    case 'h':
      display_help(argv[0]);
      return EXIT_SUCCESS;

    case 'c':
      disable_color = true;
      break;

    case 'a':
      disable_ascii = true;
      break;

    case '?':
    default:
      display_help(argv[0]);
      return EXIT_FAILURE;
    }
  }

  if (disable_color && disable_ascii) {
    fprintf(stdout, "Disabling both color and ASCII makes no sense!\n");
    return EXIT_FAILURE;
  }

  initscr();
  noecho();
  keypad(stdscr, TRUE);
  timeout(0);

  if (has_colors()) {
    if (! disable_color) {
      start_color();
    }
    init_pair(COL_BLACK,   COLOR_WHITE, COLOR_BLACK);
    init_pair(COL_RED,     COLOR_BLACK, COLOR_RED);
    init_pair(COL_GREEN,   COLOR_BLACK, COLOR_GREEN);
    init_pair(COL_YELLOW,  COLOR_BLACK, COLOR_YELLOW);
    init_pair(COL_BLUE,    COLOR_BLACK, COLOR_BLUE);
    init_pair(COL_MAGENTA, COLOR_BLACK, COLOR_MAGENTA);
    init_pair(COL_CYAN,    COLOR_BLACK, COLOR_CYAN);
    init_pair(COL_WHITE,   COLOR_BLACK, COLOR_WHITE);
  }

  while (! quit) {
    /* Player input: */
    ch = getch();
    switch (ch) {
    case KEY_LEFT:
    case 'a':
      if (player_hpos < HPOS_MAX) {
        player_hpos++;
      }
      break;

    case KEY_RIGHT:
    case 'd':
      if (player_hpos > HPOS_MIN) {
        player_hpos--;
      }
      break;

    case KEY_UP:
    case 'w':
      if (player_speed < SPEED_MAX) {
        player_speed++;
      }
      break;

    case KEY_DOWN:
    case 's':
      if (player_speed > SPEED_MIN) {
        player_speed--;
      }
      break;

    case 'q':
      quit = true;
      break;

    default:
      break;
    }

    /* Position update of other cars: */
    for (int i = 0; i < CARS_MAX; i++) {
      cars[i].distance += (cars[i].speed - player_speed);

      /* Re-spawn car if it goes out of range: */
      if (cars[i].distance > 6000) {
        car_init(&cars[i], true);
      } else if (cars[i].distance < -100) {
        car_init(&cars[i], true);
        cars_passed++;
      }

      car_row_update(&cars[i]);
    }

    /* Collision check: */
    for (int i = 0; i < CARS_MAX; i++) {
      if (car_collision(&cars[i], player_hpos)) {
        endwin();
        fprintf(stdout, "Crashed!\n");
        quit = true;
      }
    }

    /* Draw screen: */
    erase();
    draw_horizon(curve, player_speed, disable_ascii);
    draw_road(curve, player_speed, disable_ascii);
    for (int i = 0; i < CARS_MAX; i++) {
      draw_car(curve, cars[i].row, cars[i].hpos, false, disable_ascii);
    }
    draw_car(curve, 20, player_hpos, true, disable_ascii); /* The player */
    mvprintw(6, 0, "Score: %d", cars_passed);
    mvprintw(7, 0, "%dkm/h", player_speed * 10);
    refresh();

    usleep(20000);

    /* Trajectory and road change: */
    curve = curve_ahead(player_speed);
  }

  endwin();
  fprintf(stdout, "Final score: %d\n", cars_passed);
  return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %rbx
movl %edi, %ebp
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x1100
movl %eax, %edi
callq 0x1050
cmpq $0x50, %r14
je 0x12f1
leaq (%rsp,%r14), %rdi
addq $0x30, %rdi
andl $0x0, (%rdi)
xorl %esi, %esi
callq 0x1b46
addq $0x10, %r14
jmp 0x12d3
xorl %r15d, %r15d
leaq 0x24d2(%rip), %r14      # 0x37cd
xorl %ecx, %ecx
movl %ecx, %r12d
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1130
movb $0x1, %cl
cmpl $0x61, %eax
je 0x12fd
cmpl $-0x1, %eax
je 0x132b
cmpl $0x68, %eax
je 0x1355
cmpl $0x63, %eax
jne 0x1364
movb $0x1, %r15b
movl %r12d, %ecx
jmp 0x12fd
testb $0x1, %r15b
je 0x1374
testb $0x1, %r12b
je 0x1374
movq 0x3c9a(%rip), %rax      # 0x4fd8
movq (%rax), %rcx
leaq 0x2489(%rip), %rdi      # 0x37d1
pushq $0x2f
popq %rsi
pushq $0x1
popq %rdx
callq 0x1160
jmp 0x136c
movq (%rbx), %rdi
callq 0x1bc9
xorl %ebx, %ebx
jmp 0x1b32
movq (%rbx), %rdi
callq 0x1bc9
pushq $0x1
popq %rbx
jmp 0x1b32
callq 0x1080
callq 0x1070
movq 0x3c5b(%rip), %rbp      # 0x4fe0
movq (%rbp), %rdi
pushq $0x1
popq %rsi
callq 0x10b0
movq (%rbp), %rdi
xorl %esi, %esi
callq 0x10f0
callq 0x1030
testb %al, %al
je 0x1434
testb $0x1, %r15b
jne 0x13b4
callq 0x10a0
pushq $0x1
popq %r15
pushq $0x7
popq %rbx
movl %r15d, %edi
movl %ebx, %esi
xorl %edx, %edx
callq 0x1120
pushq $0x2
popq %r14
movl %r14d, %edi
xorl %esi, %esi
movl %r15d, %edx
callq 0x1120
pushq $0x3
popq %r15
movl %r15d, %edi
xorl %esi, %esi
movl %r14d, %edx
callq 0x1120
pushq $0x4
popq %r14
movl %r14d, %edi
xorl %esi, %esi
movl %r15d, %edx
callq 0x1120
pushq $0x5
popq %r15
movl %r15d, %edi
xorl %esi, %esi
movl %r14d, %edx
callq 0x1120
pushq $0x6
popq %r14
movl %r14d, %edi
xorl %esi, %esi
movl %r15d, %edx
callq 0x1120
movl %ebx, %edi
xorl %esi, %esi
movl %r14d, %edx
callq 0x1120
pushq $0x8
popq %rdi
xorl %esi, %esi
movl %ebx, %edx
callq 0x1120
movl %r12d, %eax
notb %al
movzbl %al, %eax
andl $0x1, %eax
leal (%rax,%rax,2), %ebx
addl $0x20, %ebx
testb $0x1, %r12b
pushq $0x20
popq %rax
pushq $0x7c
popq %rcx
cmovnel %eax, %ecx
movl %ecx, 0x1c(%rsp)
pushq $0x19
popq %r13
pushq $0x5
popq %rax
movl %eax, 0x4(%rsp)
movq 0x3b70(%rip), %r15      # 0x4fd8
movl $0x0, 0xc(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x0, (%rsp)
movb %r12b, 0xb(%rsp)
testb $0x1, (%rsp)
jne 0x1b16
movq (%rbp), %rdi
callq 0x1060
leal -0x102(%rax), %ecx
cmpl $0x3, %ecx
jbe 0x14c2
cmpl $0x77, %eax
je 0x14ef
cmpl $0x64, %eax
je 0x1503
cmpl $0x71, %eax
je 0x1b0c
cmpl $0x73, %eax
je 0x14d2
cmpl $0x61, %eax
je 0x14e1
jmp 0x150f
leaq 0x1bc7(%rip), %rdx      # 0x3090
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
xorl %eax, %eax
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
setg %al
subl %eax, %ecx
jmp 0x14fd
xorl %eax, %eax
cmpl $0x23, %r13d
setl %al
addl %eax, %r13d
jmp 0x150f
xorl %eax, %eax
movl 0x4(%rsp), %ecx
cmpl $0x1e, %ecx
setl %al
addl %eax, %ecx
movl %ecx, 0x4(%rsp)
jmp 0x150f
xorl %eax, %eax
cmpl $-0x22, %r13d
setge %al
subl %eax, %r13d
movl $0x0, (%rsp)
xorl %r15d, %r15d
cmpq $0x50, %r15
je 0x168f
leaq (%rsp,%r15), %r14
addq $0x30, %r14
movl 0x8(%r14), %eax
subl 0x4(%rsp), %eax
cvtsi2ss %eax, %xmm0
addss (%r14), %xmm0
movss %xmm0, (%r14)
ucomiss 0x1abc(%rip), %xmm0     # 0x3004
jbe 0x1557
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x1b46
jmp 0x1573
movss 0x1aa9(%rip), %xmm1     # 0x3008
ucomiss %xmm0, %xmm1
jbe 0x1578
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x1b46
incl 0xc(%rsp)
movss (%r14), %xmm0
ucomiss 0x1a8d(%rip), %xmm0     # 0x300c
pushq $-0x1
popq %rax
ja 0x1681
ucomiss 0x1a81(%rip), %xmm0     # 0x3010
pushq $0x6
popq %rax
ja 0x1681
ucomiss 0x1a75(%rip), %xmm0     # 0x3014
pushq $0x7
popq %rax
ja 0x1681
ucomiss 0x1a69(%rip), %xmm0     # 0x3018
pushq $0x8
popq %rax
ja 0x1681
ucomiss 0x1a5d(%rip), %xmm0     # 0x301c
pushq $0x9
popq %rax
ja 0x1681
ucomiss 0x1a51(%rip), %xmm0     # 0x3020
pushq $0xa
popq %rax
ja 0x1681
ucomiss 0x1a45(%rip), %xmm0     # 0x3024
pushq $0xb
popq %rax
ja 0x1681
ucomiss 0x1a39(%rip), %xmm0     # 0x3028
pushq $0xc
popq %rax
ja 0x1681
ucomiss 0x1a2d(%rip), %xmm0     # 0x302c
pushq $0xd
popq %rax
ja 0x1681
ucomiss 0x1a25(%rip), %xmm0     # 0x3030
pushq $0xe
popq %rax
ja 0x1681
ucomiss 0x1a1d(%rip), %xmm0     # 0x3034
pushq $0xf
popq %rax
ja 0x1681
ucomiss 0x1a15(%rip), %xmm0     # 0x3038
pushq $0x10
popq %rax
ja 0x1681
ucomiss 0x1a0d(%rip), %xmm0     # 0x303c
pushq $0x11
popq %rax
ja 0x1681
ucomiss 0x1a05(%rip), %xmm0     # 0x3040
pushq $0x12
popq %rax
ja 0x1681
ucomiss 0x19fd(%rip), %xmm0     # 0x3044
pushq $0x13
popq %rax
ja 0x1681
ucomiss 0x1a09(%rip), %xmm0     # 0x305c
pushq $0x14
popq %rax
ja 0x1681
ucomiss 0x19e9(%rip), %xmm0     # 0x3048
pushq $0x15
popq %rax
ja 0x1681
ucomiss 0x19e1(%rip), %xmm0     # 0x304c
pushq $0x16
popq %rax
ja 0x1681
xorl %eax, %eax
ucomiss 0x19d7(%rip), %xmm0     # 0x3050
setbe %al
negl %eax
orl $0x17, %eax
movl %eax, 0x34(%rsp,%r15)
addq $0x10, %r15
jmp 0x1519
pushq $0xc
popq %r14
movq 0x393e(%rip), %r15      # 0x4fd8
cmpq $0x5c, %r14
je 0x16f0
movss 0x24(%rsp,%r14), %xmm0
andps 0x19b2(%rip), %xmm0     # 0x3060
ucomiss 0x198f(%rip), %xmm0     # 0x3044
ja 0x16ea
movl 0x30(%rsp,%r14), %eax
subl %r13d, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0xc, %ecx
ja 0x16ea
callq 0x1170
movq (%r15), %rcx
leaq 0x2127(%rip), %rdi      # 0x3801
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x1160
movb $0x1, %al
movl %eax, (%rsp)
addq $0x10, %r14
jmp 0x169a
movl %r13d, 0x18(%rsp)
movq (%rbp), %rdi
callq 0x1040
cvtsi2sdl 0x4(%rsp), %xmm0
movq 0x10(%rsp), %rax
cvtsi2sd %eax, %xmm1
divsd 0x195b(%rip), %xmm0     # 0x3070
mulsd %xmm0, %xmm1
cvtss2sd 0x39cb(%rip), %xmm0     # 0x50ec
divsd 0x194f(%rip), %xmm1     # 0x3078
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, %xmm1
cmpltss 0x191f(%rip), %xmm1     # 0x305c
movaps %xmm1, %xmm2
andnps %xmm0, %xmm2
movss 0x1909(%rip), %xmm0     # 0x3054
andps %xmm0, %xmm1
orps %xmm2, %xmm1
cmpltss %xmm1, %xmm0
andnps %xmm1, %xmm0
movss %xmm0, 0x398b(%rip)     # 0x50ec
xorl %r15d, %r15d
cmpq $0x5, %r15
je 0x1854
xorl %r13d, %r13d
cmpl $0x50, %r13d
je 0x1847
cvttss2si 0x3969(%rip), %eax # 0x50ec
addl %r13d, %eax
cltd
movl $0x168, %ecx            # imm = 0x168
idivl %ecx
movslq %edx, %rax
imulq $0x169, %r15, %rcx      # imm = 0x169
leaq 0x1921(%rip), %rdx      # 0x30c0
addq %rdx, %rcx
movsbl (%rax,%rcx), %r14d
callq 0x1030
testb %al, %al
je 0x17d9
xorl %eax, %eax
cmpb $0x4d, %r14b
sete %cl
movl $0x400, %esi            # imm = 0x400
cmpb $0x2a, %r14b
je 0x17ce
movb %cl, %al
orl $0x2, %eax
shll $0x8, %eax
movl %eax, %esi
movq (%rbp), %rdi
xorl %edx, %edx
callq 0x10c0
movq (%rbp), %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x1140
testb $0x1, %r12b
je 0x17fc
cmpl $-0x1, %eax
je 0x180d
movq (%rbp), %rdi
pushq $0x20
popq %rsi
jmp 0x1808
cmpl $-0x1, %eax
je 0x180d
movq (%rbp), %rdi
movl %r14d, %esi
callq 0x1150
callq 0x1030
testb %al, %al
je 0x183f
xorl %eax, %eax
cmpb $0x4d, %r14b
sete %cl
movl $0x400, %esi            # imm = 0x400
cmpb $0x2a, %r14b
je 0x1834
movb %cl, %al
orl $0x2, %eax
shll $0x8, %eax
movl %eax, %esi
movq (%rbp), %rdi
xorl %edx, %edx
callq 0x1190
incl %r13d
jmp 0x1771
incq %r15
movq 0x10(%rsp), %rax
jmp 0x1764
leal 0x24(%rax), %ecx
movl 0x3893(%rip), %eax      # 0x50f0
imull 0x4(%rsp), %eax
xorl %r13d, %r13d
cvtsi2ss %ecx, %xmm0
xorl %edx, %edx
pushq $0x1e
popq %rcx
divl %ecx
movl %eax, 0x20(%rsp)
divss 0x17dc(%rip), %xmm0     # 0x3058
movss %xmm0, 0x24(%rsp)
cmpl $0x13, %r13d
je 0x19f6
pushq $0x12
popq %rax
subl %r13d, %eax
cvtsi2ss %eax, %xmm0
mulss 0x24(%rsp), %xmm0
cvttss2si %xmm0, %eax
leal 0x5(%r13), %r15d
cmpl $-0x2, %eax
pushq $-0x3
popq %r12
movq %rax, 0x28(%rsp)
cmovgel %eax, %r12d
addl $0x3, %r12d
xorl %r14d, %r14d
cmpl %r14d, %r12d
je 0x1916
callq 0x1030
testb %al, %al
je 0x18d9
movq (%rbp), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x10c0
movq (%rbp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x1140
cmpl $-0x1, %eax
je 0x18f8
movq (%rbp), %rdi
movl %ebx, %esi
callq 0x1150
callq 0x1030
testb %al, %al
je 0x1911
movq (%rbp), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x1190
incl %r14d
jmp 0x18bb
cmpl $0x2, %r13d
movq 0x28(%rsp), %r14
jb 0x1983
movl %r13d, %eax
xorl 0x20(%rsp), %eax
testb $0x1, %al
jne 0x1983
callq 0x1030
testb %al, %al
je 0x1945
movq (%rbp), %rdi
movl $0x800, %esi            # imm = 0x800
xorl %edx, %edx
callq 0x10c0
movq (%rbp), %rdi
leal (%r14,%r13,2), %edx
addl $0x3, %edx
movl %r15d, %esi
callq 0x1140
cmpl $-0x1, %eax
je 0x196a
movq (%rbp), %rdi
movl 0x1c(%rsp), %esi
callq 0x1150
callq 0x1030
testb %al, %al
je 0x1983
movq (%rbp), %rdi
movl $0x800, %esi            # imm = 0x800
xorl %edx, %edx
callq 0x1190
leal (,%r13,4), %eax
addl %eax, %r14d
addl $0x4, %r14d
cmpl $0x4f, %r14d
jg 0x19ee
callq 0x1030
testb %al, %al
je 0x19b1
movq (%rbp), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x10c0
movq (%rbp), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x1140
cmpl $-0x1, %eax
je 0x19d0
movq (%rbp), %rdi
movl %ebx, %esi
callq 0x1150
callq 0x1030
testb %al, %al
je 0x19e9
movq (%rbp), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x1190
incl %r14d
jmp 0x1992
incl %r13d
jmp 0x1882
incl 0x36f4(%rip)            # 0x50f0
pushq $0xc
popq %r14
movb 0xb(%rsp), %r12b
movl 0x18(%rsp), %r13d
movq 0x35c7(%rip), %r15      # 0x4fd8
movzbl %r12b, %r8d
cmpq $0x5c, %r14
je 0x1a3b
movl 0x28(%rsp,%r14), %esi
movl 0x30(%rsp,%r14), %edx
andl $0x1, %r8d
movq 0x10(%rsp), %rdi
xorl %ecx, %ecx
callq 0x1bfb
addq $0x10, %r14
jmp 0x1a11
andl $0x1, %r8d
movq 0x10(%rsp), %rdi
pushq $0x14
popq %rsi
movl %r13d, %edx
pushq $0x1
popq %rcx
callq 0x1bfb
pushq $0x6
popq %rdi
xorl %esi, %esi
leaq 0x1dad(%rip), %rdx      # 0x380b
movl 0xc(%rsp), %ecx
xorl %eax, %eax
callq 0x10e0
movl 0x4(%rsp), %r14d
imull $0xa, %r14d, %ecx
pushq $0x7
popq %rdi
xorl %esi, %esi
leaq 0x1d97(%rip), %rdx      # 0x3815
xorl %eax, %eax
callq 0x10e0
movq (%rbp), %rdi
callq 0x1090
movl $0x4e20, %edi           # imm = 0x4E20
callq 0x11a0
cvtsi2ss %r14d, %xmm0
addss 0x3653(%rip), %xmm0     # 0x50f8
movss %xmm0, 0x364b(%rip)     # 0x50f8
ucomiss 0x1580(%rip), %xmm0     # 0x3034
jbe 0x1afc
callq 0x1110
cqto
pushq $0x3
popq %rcx
idivq %rcx
movl 0x362b(%rip), %ecx      # 0x50f4
subl %edx, %ecx
incl %ecx
movl %ecx, 0x3621(%rip)      # 0x50f4
pushq $0x1e
popq %rax
cmpl $0x1e, %ecx
jg 0x1ae3
pushq $-0x1e
popq %rax
cmpl $-0x1f, %ecx
jg 0x1aeb
movl %eax, 0x360b(%rip)      # 0x50f4
movl %eax, %ecx
movq %rcx, 0x10(%rsp)
andl $0x0, 0x3601(%rip)      # 0x50f8
jmp 0x1485
movl 0x35f2(%rip), %eax      # 0x50f4
movq %rax, 0x10(%rsp)
jmp 0x1485
movb $0x1, %al
movl %eax, (%rsp)
jmp 0x1516
callq 0x1170
movq (%r15), %rdi
leaq 0x1cf7(%rip), %rsi      # 0x381c
xorl %ebx, %ebx
movl 0xc(%rsp), %edx
xorl %eax, %eax
callq 0x10d0
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq