// File: /workspace/github_c_makefile_star2_O1/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 $0x98, %rsp
movq %rsi, %rbx
movl %edi, %ebp
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x1100
movl %eax, %edi
callq 0x1050
leaq (%rsp,%r14), %rdi
addq $0x40, %rdi
movl $0x0, (%rdi)
xorl %esi, %esi
callq 0x1c1c
addq $0x10, %r14
cmpq $0x50, %r14
jne 0x12d3
xorl %r13d, %r13d
leaq 0x24d1(%rip), %r15      # 0x37cd
xorl %r14d, %r14d
movl %r14d, %ecx
movl %ecx, %r14d
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x1130
movb $0x1, %cl
cmpl $0x61, %eax
je 0x1302
cmpl $-0x1, %eax
je 0x1368
cmpl $0x63, %eax
jne 0x1328
movb $0x1, %r13b
jmp 0x12ff
cmpl $0x68, %eax
jne 0x138c
movq (%rbx), %rdx
movq 0x3ca1(%rip), %r14      # 0x4fd8
movq (%r14), %rdi
leaq 0x24ec(%rip), %rsi      # 0x382d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x10d0
movq (%r14), %rcx
leaq 0x24ee(%rip), %rdi      # 0x3842
movl $0x58, %esi
movl $0x1, %edx
callq 0x1160
jmp 0x1c08
testb $0x1, %r13b
je 0x13ca
testb $0x1, %r14b
je 0x13ca
movq 0x3c5d(%rip), %rax      # 0x4fd8
movq (%rax), %rcx
leaq 0x244c(%rip), %rdi      # 0x37d1
movl $0x2f, %esi
jmp 0x13b6
movq (%rbx), %rdx
movq 0x3c42(%rip), %rbx      # 0x4fd8
movq (%rbx), %rdi
leaq 0x248d(%rip), %rsi      # 0x382d
xorl %eax, %eax
callq 0x10d0
movq (%rbx), %rcx
leaq 0x2491(%rip), %rdi      # 0x3842
movl $0x58, %esi
movl $0x1, %edx
callq 0x1160
movl $0x1, %ebx
jmp 0x1c08
callq 0x1080
callq 0x1070
movq 0x3c05(%rip), %r12      # 0x4fe0
movq (%r12), %rdi
movl $0x1, %esi
callq 0x10b0
movq (%r12), %rdi
xorl %esi, %esi
callq 0x10f0
callq 0x1030
testb %al, %al
je 0x1494
testb $0x1, %r13b
jne 0x140c
callq 0x10a0
movl $0x1, %edi
movl $0x7, %esi
xorl %edx, %edx
callq 0x1120
movl $0x2, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x1120
movl $0x3, %edi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1120
movl $0x4, %edi
xorl %esi, %esi
movl $0x3, %edx
callq 0x1120
movl $0x5, %edi
xorl %esi, %esi
movl $0x4, %edx
callq 0x1120
movl $0x6, %edi
xorl %esi, %esi
movl $0x5, %edx
callq 0x1120
movl $0x7, %edi
xorl %esi, %esi
movl $0x6, %edx
callq 0x1120
movl $0x8, %edi
xorl %esi, %esi
movl $0x7, %edx
callq 0x1120
movl %r14d, %eax
notb %al
movzbl %al, %eax
andl $0x1, %eax
testb $0x1, %r14b
movl $0x20, %ecx
movl $0x7c, %edx
cmovnel %ecx, %edx
movl %edx, 0x28(%rsp)
leal 0x20(%rax,%rax,2), %eax
movl %eax, 0xc(%rsp)
movl $0x5, %r13d
movl $0x19, %ebp
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x0, 0x8(%rsp)
movq (%r12), %rdi
callq 0x1060
cmpl $0x72, %eax
jg 0x150b
cmpl $0x61, %eax
je 0x1526
cmpl $0x64, %eax
je 0x1532
cmpl $0x71, %eax
movl %ebp, 0x4(%rsp)
jne 0x156d
movb $0x1, %al
movq %rax, 0x18(%rsp)
jmp 0x156d
leal -0x102(%rax), %ecx
cmpl $0x3, %ecx
ja 0x1542
leaq 0x1b73(%rip), %rdx      # 0x3090
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
xorl %eax, %eax
cmpl $0x23, %ebp
setl %al
addl %eax, %ebp
jmp 0x153c
xorl %eax, %eax
cmpl $-0x22, %ebp
setge %al
subl %eax, %ebp
movl %ebp, 0x4(%rsp)
jmp 0x156d
cmpl $0x73, %eax
je 0x155e
cmpl $0x77, %eax
jne 0x153c
movl %ebp, 0x4(%rsp)
xorl %eax, %eax
cmpl $0x1e, %r13d
setl %al
addl %eax, %r13d
jmp 0x156d
movl %ebp, 0x4(%rsp)
xorl %eax, %eax
testl %r13d, %r13d
setg %al
subl %eax, %r13d
xorl %r15d, %r15d
movl 0x8(%rsp), %ebp
leaq (%rsp,%r15), %rbx
addq $0x40, %rbx
movl 0x8(%rbx), %eax
subl %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
addss (%rbx), %xmm0
movss %xmm0, (%rbx)
ucomiss 0x1a6c(%rip), %xmm0     # 0x3004
jbe 0x15a9
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1c1c
jmp 0x15c5
movss 0x1a57(%rip), %xmm1     # 0x3008
ucomiss %xmm0, %xmm1
jbe 0x15c5
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1c1c
incl %ebp
movss (%rbx), %xmm0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
ucomiss 0x1a37(%rip), %xmm0     # 0x300c
ja 0x16fe
movl $0x6, %eax
ucomiss 0x1a29(%rip), %xmm0     # 0x3010
ja 0x16fe
movl $0x7, %eax
ucomiss 0x1a1b(%rip), %xmm0     # 0x3014
ja 0x16fe
movl $0x8, %eax
ucomiss 0x1a0d(%rip), %xmm0     # 0x3018
ja 0x16fe
movl $0x9, %eax
ucomiss 0x19ff(%rip), %xmm0     # 0x301c
ja 0x16fe
movl $0xa, %eax
ucomiss 0x19f1(%rip), %xmm0     # 0x3020
ja 0x16fe
movl $0xb, %eax
ucomiss 0x19e3(%rip), %xmm0     # 0x3024
ja 0x16fe
movl $0xc, %eax
ucomiss 0x19d5(%rip), %xmm0     # 0x3028
ja 0x16fe
movl $0xd, %eax
ucomiss 0x19c7(%rip), %xmm0     # 0x302c
ja 0x16fe
movl $0xe, %eax
ucomiss 0x19b9(%rip), %xmm0     # 0x3030
ja 0x16fe
movl $0xf, %eax
ucomiss 0x19ab(%rip), %xmm0     # 0x3034
ja 0x16fe
movl $0x10, %eax
ucomiss 0x19a1(%rip), %xmm0     # 0x3038
ja 0x16fe
movl $0x11, %eax
ucomiss 0x1997(%rip), %xmm0     # 0x303c
ja 0x16fe
movl $0x12, %eax
ucomiss 0x198d(%rip), %xmm0     # 0x3040
ja 0x16fe
movl $0x13, %eax
ucomiss 0x1983(%rip), %xmm0     # 0x3044
ja 0x16fe
movl $0x14, %eax
ucomiss 0x198d(%rip), %xmm0     # 0x305c
ja 0x16fe
movl $0x15, %eax
ucomiss 0x196b(%rip), %xmm0     # 0x3048
ja 0x16fe
movl $0x16, %eax
ucomiss 0x1961(%rip), %xmm0     # 0x304c
ja 0x16fe
xorl %eax, %eax
ucomiss 0x195a(%rip), %xmm0     # 0x3050
setbe %al
negl %eax
orl $0x17, %eax
movl %eax, 0x44(%rsp,%r15)
addq $0x10, %r15
cmpq $0x50, %r15
jne 0x1574
movl %ebp, 0x8(%rsp)
xorl %ebx, %ebx
movl 0x4(%rsp), %ebp
movq 0x38b6(%rip), %r15      # 0x4fd8
movss 0x40(%rsp,%rbx), %xmm0
andps 0x1931(%rip), %xmm0     # 0x3060
ucomiss 0x190e(%rip), %xmm0     # 0x3044
ja 0x176f
movl 0x4c(%rsp,%rbx), %eax
subl %ebp, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0xc, %ecx
ja 0x176f
callq 0x1170
movq (%r15), %rcx
movl $0x9, %esi
movl $0x1, %edx
leaq 0x209e(%rip), %rdi      # 0x3801
callq 0x1160
movb $0x1, %al
movq %rax, 0x18(%rsp)
addq $0x10, %rbx
cmpq $0x50, %rbx
jne 0x1722
movq (%r12), %rdi
callq 0x1040
movq %r13, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x10(%rsp), %xmm1
divsd 0x18d0(%rip), %xmm0     # 0x3070
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd 0x393d(%rip), %xmm0     # 0x50ec
divsd 0x18c1(%rip), %xmm1     # 0x3078
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movaps %xmm0, %xmm1
cmpltss 0x1891(%rip), %xmm1     # 0x305c
movaps %xmm1, %xmm2
andnps %xmm0, %xmm2
movss 0x187b(%rip), %xmm0     # 0x3054
andps %xmm0, %xmm1
orps %xmm2, %xmm1
cmpltss %xmm1, %xmm0
andnps %xmm1, %xmm0
movss %xmm0, 0x38fd(%rip)     # 0x50ec
xorl %r13d, %r13d
leaq 0x18c7(%rip), %rbp      # 0x30c0
xorl %ebx, %ebx
cvttss2si 0x38e9(%rip), %eax # 0x50ec
addl %ebx, %eax
cltq
imulq $-0x49f49f49, %rax, %rcx # imm = 0xB60B60B7
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x8, %ecx
addl %edx, %ecx
imull $0x168, %ecx, %ecx      # imm = 0x168
subl %ecx, %eax
cltq
imulq $0x169, %r13, %rcx      # imm = 0x169
addq %rbp, %rcx
movsbl (%rax,%rcx), %r15d
callq 0x1030
testb %al, %al
je 0x1869
xorl %eax, %eax
cmpb $0x4d, %r15b
sete %cl
movl $0x400, %esi            # imm = 0x400
cmpb $0x2a, %r15b
je 0x185e
movb %cl, %al
orl $0x2, %eax
shll $0x8, %eax
movl %eax, %esi
movq (%r12), %rdi
xorl %edx, %edx
callq 0x10c0
movq (%r12), %rdi
movl %r13d, %esi
movl %ebx, %edx
testb $0x1, %r14b
je 0x188d
callq 0x1140
cmpl $-0x1, %eax
je 0x18a3
movq (%r12), %rdi
movl $0x20, %esi
jmp 0x189e
callq 0x1140
cmpl $-0x1, %eax
je 0x18a3
movq (%r12), %rdi
movl %r15d, %esi
callq 0x1150
callq 0x1030
testb %al, %al
je 0x18d5
xorl %eax, %eax
cmpb $0x4d, %r15b
sete %cl
movl $0x400, %esi            # imm = 0x400
cmpb $0x2a, %r15b
je 0x18ca
movb %cl, %al
orl $0x2, %eax
shll $0x8, %eax
movl %eax, %esi
movq (%r12), %rdi
xorl %edx, %edx
callq 0x1190
incl %ebx
cmpl $0x50, %ebx
jne 0x17fb
incq %r13
cmpq $0x5, %r13
jne 0x17f9
movq 0x10(%rsp), %rax
addl $0x24, %eax
movl 0x37f5(%rip), %ecx      # 0x50f0
imull 0x30(%rsp), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movl $0x88888889, %eax       # imm = 0x88888889
imulq %rax, %rcx
shrq $0x24, %rcx
movq %rcx, 0x38(%rsp)
divss 0x1737(%rip), %xmm0     # 0x3058
movss %xmm0, 0x2c(%rsp)
xorl %r13d, %r13d
movl $0x12, %eax
subl %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
mulss 0x2c(%rsp), %xmm0
cvttss2si %xmm0, %ecx
movq %rcx, 0x20(%rsp)
cmpl $-0x2, %ecx
jl 0x19be
leal 0x5(%r13), %ebx
movq 0x20(%rsp), %rax
leal 0x2(%rax), %ebp
xorl %r15d, %r15d
testl %ebp, %ebp
cmovlel %r15d, %ebp
incl %ebp
callq 0x1030
testb %al, %al
je 0x197d
movq (%r12), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x10c0
movq (%r12), %rdi
movl %ebx, %esi
movl %r15d, %edx
callq 0x1140
cmpl $-0x1, %eax
je 0x199d
movq (%r12), %rdi
movl 0xc(%rsp), %esi
callq 0x1150
callq 0x1030
testb %al, %al
je 0x19b6
movq (%r12), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x1190
incl %r15d
cmpl %r15d, %ebp
jne 0x1964
cmpl $0x2, %r13d
jb 0x1a2c
movl %r13d, %eax
xorl 0x38(%rsp), %eax
testb $0x1, %al
jne 0x1a2c
callq 0x1030
testb %al, %al
je 0x19e8
movq (%r12), %rdi
movl $0x800, %esi            # imm = 0x800
xorl %edx, %edx
callq 0x10c0
movq (%r12), %rdi
leal 0x5(%r13), %esi
movq 0x20(%rsp), %rax
leal (%rax,%r13,2), %edx
addl $0x3, %edx
callq 0x1140
cmpl $-0x1, %eax
je 0x1a13
movq (%r12), %rdi
movl 0x28(%rsp), %esi
callq 0x1150
callq 0x1030
testb %al, %al
je 0x1a2c
movq (%r12), %rdi
movl $0x800, %esi            # imm = 0x800
xorl %edx, %edx
callq 0x1190
leal (,%r13,4), %eax
movq 0x20(%rsp), %rcx
leal (%rax,%rcx), %ebx
addl $0x4, %ebx
cmpl $0x4f, %ebx
jg 0x1aa4
leal 0x5(%r13), %r15d
callq 0x1030
testb %al, %al
je 0x1a61
movq (%r12), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x10c0
movq (%r12), %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0x1140
cmpl $-0x1, %eax
je 0x1a81
movq (%r12), %rdi
movl 0xc(%rsp), %esi
callq 0x1150
callq 0x1030
testb %al, %al
je 0x1a9a
movq (%r12), %rdi
movl $0x300, %esi            # imm = 0x300
xorl %edx, %edx
callq 0x1190
leal 0x1(%rbx), %eax
cmpl $0x4f, %ebx
movl %eax, %ebx
jl 0x1a48
incl %r13d
cmpl $0x13, %r13d
jne 0x192a
incl 0x3639(%rip)            # 0x50f0
movl $0xc, %r15d
movq 0x10(%rsp), %r13
movl 0x38(%rsp,%r15), %esi
movl 0x40(%rsp,%r15), %edx
movzbl %r14b, %ebx
andl $0x1, %ebx
movl %r13d, %edi
xorl %ecx, %ecx
movl %ebx, %r8d
callq 0x1cdb
addq $0x10, %r15
cmpq $0x5c, %r15
jne 0x1ac2
movl %r13d, %edi
movl $0x14, %esi
movl 0x4(%rsp), %ebp
movl %ebp, %edx
movl $0x1, %ecx
movl %ebx, %r8d
callq 0x1cdb
movl $0x6, %edi
xorl %esi, %esi
leaq 0x1cf8(%rip), %rdx      # 0x380b
movl 0x8(%rsp), %ecx
xorl %eax, %eax
callq 0x10e0
movq 0x30(%rsp), %r13
leal (,%r13,2), %eax
leal (%rax,%rax,4), %ecx
movl $0x7, %edi
xorl %esi, %esi
leaq 0x1cd9(%rip), %rdx      # 0x3815
xorl %eax, %eax
callq 0x10e0
movq (%r12), %rdi
callq 0x1090
movl $0x4e20, %edi           # imm = 0x4E20
callq 0x11a0
xorps %xmm0, %xmm0
cvtsi2ss %r13d, %xmm0
addss 0x3592(%rip), %xmm0     # 0x50f8
movss %xmm0, 0x358a(%rip)     # 0x50f8
ucomiss 0x14bf(%rip), %xmm0     # 0x3034
movq 0x345c(%rip), %rbx      # 0x4fd8
jbe 0x1bd6
callq 0x1110
movq %rax, %rcx
movabsq $0x5555555555555556, %rdx # imm = 0x5555555555555556
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
addl %edx, %eax
leal (%rax,%rax,2), %eax
movl 0x354f(%rip), %edx      # 0x50f4
subl %ecx, %eax
leal (%rdx,%rax), %ecx
incl %ecx
movl %ecx, 0x3542(%rip)      # 0x50f4
movl $0x1e, %eax
cmpl $0x1e, %ecx
jg 0x1bc6
movl $0xffffffe2, %eax       # imm = 0xFFFFFFE2
cmpl $-0x1f, %ecx
jg 0x1bcc
movl %eax, 0x3528(%rip)      # 0x50f4
movl $0x0, 0x3522(%rip)      # 0x50f8
movl 0x3518(%rip), %eax      # 0x50f4
movq %rax, 0x10(%rsp)
testb $0x1, 0x18(%rsp)
je 0x14e1
callq 0x1170
movq (%rbx), %rdi
leaq 0x1c21(%rip), %rsi      # 0x381c
xorl %ebx, %ebx
movl 0x8(%rsp), %edx
xorl %eax, %eax
callq 0x10d0
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq