// File: /workspace/github_c_makefile_star2_O0/kieselsteini[P]PiXL-old/pixl.c
// Function: px_lua_init
static int px_lua_init(lua_State *L) {
  SDL_AudioSpec want, have;
  int i, flags;
  const char *str;

  // setup some hints
  str = px_check_arg("-video");
  if (str) SDL_SetHint(SDL_HINT_RENDER_DRIVER, str);

  // check for fullscreen
  if (px_check_parm("-window")) { fullscreen = SDL_FALSE; flags = SDL_WINDOW_RESIZABLE; }
  else { fullscreen = SDL_TRUE; flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_FULLSCREEN_DESKTOP; }

  // init network
  net_initialize(L);

  // init SDL
  if (SDL_Init(SDL_INIT_EVERYTHING)) luaL_error(L, "SDL_Init() failed: %s", SDL_GetError());

  // create window + texture
  window = SDL_CreateWindow(PX_WINDOW_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, PX_SCREEN_WIDTH, PX_SCREEN_HEIGHT, flags);
  if (!window) luaL_error(L, "SDL_CreateWindow() failed: %s", SDL_GetError());
  renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
  if (!renderer) luaL_error(L, "SDL_CreateRenderer() failed: %s", SDL_GetError());
  px_create_texture(L, PX_SCREEN_WIDTH, PX_SCREEN_HEIGHT);
  SDL_ShowCursor(0);

  // audio init
  if (!px_check_parm("-nosound")) {
    SDL_zero(want); SDL_zero(have);
    want.callback = px_audio_mixer_callback;
    want.channels = 1;
    want.format = AUDIO_S8;
    want.freq = PX_AUDIO_FREQUENCY;
    want.samples = 1024 * 4;
    str = px_check_arg("-audio");
    audio_device = SDL_OpenAudioDevice(str, SDL_FALSE, &want, &have, 0);
    if (have.format != AUDIO_S8) luaL_error(L, "SDL_OpenAudioDevice() didn't provide AUDIO_S8 format");
    if (have.channels != 1) luaL_error(L, "SDL_OpenAudioDevice() didn't provide a mono channel");
    if (!audio_device) luaL_error(L, "SDL_OpenAudioDevice() failed: %s", SDL_GetError());
    mixing_frequency = (float)have.freq;
    SDL_PauseAudioDevice(audio_device, SDL_FALSE);
  }

  // init some stuff
  px_randomseed(4096); for (i = 0; i < PX_AUDIO_NOISE; ++i) audio_noise[i] = px_rand() % 8 - 4;
  for (i = 0; i < PX_AUDIO_CHANNELS; ++i) SDL_zerop(&channels[i]);
  running = SDL_TRUE;
  SDL_zero(inputs); SDL_zero(translation);
  px_open_controllers(L);
  px_randomseed(47 * 1024); // reset prng

  // load the Lua script
  str = px_check_arg("-file");
  if (luaL_loadfile(L, str ? str : "game.lua")) lua_error(L);
  lua_call(L, 0, 0);

  // run main loop
  px_run_main_loop(L);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x7c08(%rip), %rdi      # 0x5815e
callq 0x52270
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x50576
movq -0x58(%rbp), %rsi
leaq 0x7bf4(%rip), %rdi      # 0x58165
callq 0x6790
leaq 0x7bfa(%rip), %rdi      # 0x58177
callq 0x522d0
cmpl $0x0, %eax
je 0x5059a
movl $0x0, 0x1145c3(%rip)    # 0x164b54
movl $0x20, -0x50(%rbp)
jmp 0x505ab
movl $0x1, 0x1145b0(%rip)    # 0x164b54
movl $0x1021, -0x50(%rbp)    # imm = 0x1021
movq -0x8(%rbp), %rdi
callq 0x52330
movl $0xf231, %edi           # imm = 0xF231
callq 0x6460
cmpl $0x0, %eax
je 0x505e5
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
callq 0x6390
movq -0x60(%rbp), %rdi
movq %rax, %rdx
leaq 0x7ba1(%rip), %rsi      # 0x5817f
movb $0x0, %al
callq 0xe880
movl -0x50(%rbp), %r9d
leaq 0x7ba5(%rip), %rdi      # 0x58195
movl $0x2fff0000, %edx       # imm = 0x2FFF0000
movl $0x100, %ecx            # imm = 0x100
movl $0xf0, %r8d
movl %edx, %esi
callq 0x6070
movq %rax, 0x13ed2(%rip)     # 0x644e0
cmpq $0x0, 0x13eca(%rip)     # 0x644e0
jne 0x5063a
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
callq 0x6390
movq -0x68(%rbp), %rdi
movq %rax, %rdx
leaq 0x7b6e(%rip), %rsi      # 0x581a1
movb $0x0, %al
callq 0xe880
movq 0x13e9f(%rip), %rdi     # 0x644e0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x6, %edx
callq 0x6050
movq %rax, 0x13e91(%rip)     # 0x644e8
cmpq $0x0, 0x13e89(%rip)     # 0x644e8
jne 0x50683
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
callq 0x6390
movq -0x70(%rbp), %rdi
movq %rax, %rdx
leaq 0x7b43(%rip), %rsi      # 0x581bf
movb $0x0, %al
callq 0xe880
movq -0x8(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
movl $0xf0, %edx
callq 0x520a0
xorl %edi, %edi
callq 0x68b0
leaq 0x7b3b(%rip), %rdi      # 0x581df
callq 0x522d0
cmpl $0x0, %eax
jne 0x5079e
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x6240
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x6240
leaq 0x1c77(%rip), %rax      # 0x52350
movq %rax, -0x18(%rbp)
movb $0x1, -0x22(%rbp)
movw $0x8008, -0x24(%rbp)    # imm = 0x8008
movl $0xac44, -0x28(%rbp)    # imm = 0xAC44
movw $0x1000, -0x20(%rbp)    # imm = 0x1000
leaq 0x7aed(%rip), %rdi      # 0x581e8
callq 0x52270
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
xorl %r8d, %r8d
leaq -0x28(%rbp), %rdx
leaq -0x48(%rbp), %rcx
movl %r8d, %esi
callq 0x65b0
movl %eax, 0x13dd7(%rip)     # 0x644f8
movzwl -0x44(%rbp), %eax
cmpl $0x8008, %eax           # imm = 0x8008
je 0x5073e
movq -0x8(%rbp), %rdi
leaq 0x7ab8(%rip), %rsi      # 0x581ef
movb $0x0, %al
callq 0xe880
movzbl -0x42(%rbp), %eax
cmpl $0x1, %eax
je 0x50759
movq -0x8(%rbp), %rdi
leaq 0x7ad2(%rip), %rsi      # 0x58224
movb $0x0, %al
callq 0xe880
cmpl $0x0, 0x13d98(%rip)     # 0x644f8
jne 0x50784
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
callq 0x6390
movq -0x78(%rbp), %rdi
movq %rax, %rdx
leaq 0x7adb(%rip), %rsi      # 0x58258
movb $0x0, %al
callq 0xe880
cvtsi2ssl -0x48(%rbp), %xmm0
movss %xmm0, 0x11434f(%rip)   # 0x164ae0
movl 0x13d61(%rip), %edi     # 0x644f8
xorl %esi, %esi
callq 0x6610
movl $0x1000, %edi           # imm = 0x1000
callq 0x51ff0
movl $0x0, -0x4c(%rbp)
cmpl $0x400, -0x4c(%rbp)     # imm = 0x400
jge 0x507de
callq 0x52050
andl $0x7, %eax
subl $0x4, %eax
movb %al, %dl
movslq -0x4c(%rbp), %rcx
leaq 0x113f10(%rip), %rax    # 0x1646e0
movb %dl, (%rax,%rcx)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x507af
movl $0x0, -0x4c(%rbp)
cmpl $0x8, -0x4c(%rbp)
jge 0x50814
movslq -0x4c(%rbp), %rax
leaq 0x113d2a(%rip), %rdi    # 0x164520
imulq $0x38, %rax, %rax
addq %rax, %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x6240
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x507e5
movl $0x1, 0x114332(%rip)    # 0x164b50
leaq 0x1142cb(%rip), %rdi    # 0x164af0
xorl %esi, %esi
movl $0x60, %edx
callq 0x6240
leaq 0x113cd8(%rip), %rdi    # 0x164510
xorl %esi, %esi
movl $0x8, %edx
callq 0x6240
movq -0x8(%rbp), %rdi
callq 0x52660
movl $0xbc00, %edi           # imm = 0xBC00
callq 0x51ff0
leaq 0x7a1b(%rip), %rdi      # 0x58279
callq 0x52270
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x50883
movq -0x58(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x50893
leaq 0x79f5(%rip), %rax      # 0x5827f
movq %rax, -0x88(%rbp)
jmp 0x50893
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xf950
cmpl $0x0, %eax
je 0x508b5
movq -0x8(%rbp), %rdi
callq 0xcbd0
movq -0x8(%rbp), %rdi
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %r8d
movl %edx, %esi
movq %r8, %rcx
callq 0xbfb0
movq -0x8(%rbp), %rdi
callq 0x526e0
xorl %eax, %eax
addq $0x90, %rsp
popq %rbp
retq
nop