// File: /workspace/github_c_makefile_star2_O0/kieselsteini[P]PiXL-old/pixl.c
// Function: px_create_texture
static void px_create_texture(lua_State *L, int width, int height) {
  SDL_DisplayMode display_mode;

  // create new texture
  if (texture) SDL_DestroyTexture(texture);
  texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, width, height);
  if (!texture) luaL_error(L, "SDL_CreateTexture() failed: %s", SDL_GetError());
  if (SDL_RenderSetLogicalSize(renderer, width, height)) luaL_error(L, "SDL_RenderSetLogicalSize() failed: %s", SDL_GetError());
  screen_width = width; screen_height = height;

  // determine the best window size and center it
  if (SDL_GetDesktopDisplayMode(0, &display_mode)) luaL_error(L, "SDL_GetDesktopDisplayMode() failed: %s", SDL_GetError());
  width = (display_mode.w - PX_WINDOW_PADDING) / screen_width;
  height = (display_mode.h - PX_WINDOW_PADDING) / screen_height;
  if (width < height) {
    height = screen_height * width;
    width = screen_width * width;
  } 
  else {
    width = screen_width * height;
    height = screen_height * height;
  }
  SDL_SetWindowSize(window, width, height);
  SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
cmpq $0x0, 0x12436(%rip)     # 0x644f0
je 0x520c8
movq 0x1242d(%rip), %rdi     # 0x644f0
callq 0x6380
movq 0x12419(%rip), %rdi     # 0x644e8
movl -0xc(%rbp), %ecx
movl -0x10(%rbp), %r8d
movl $0x16462004, %esi       # imm = 0x16462004
movl $0x1, %edx
callq 0x6850
movq %rax, 0x12404(%rip)     # 0x644f0
cmpq $0x0, 0x123fc(%rip)     # 0x644f0
jne 0x52118
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
callq 0x6390
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0x5f88(%rip), %rsi      # 0x58099
movb $0x0, %al
callq 0xe880
movq 0x123c9(%rip), %rdi     # 0x644e8
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x61d0
cmpl $0x0, %eax
je 0x52151
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
callq 0x6390
movq -0x38(%rbp), %rdi
movq %rax, %rdx
leaq 0x5f6e(%rip), %rsi      # 0x580b8
movb $0x0, %al
callq 0xe880
movl -0xc(%rbp), %eax
movl %eax, 0x1123be(%rip)    # 0x164518
movl -0x10(%rbp), %eax
movl %eax, 0x1123b9(%rip)    # 0x16451c
xorl %edi, %edi
leaq -0x28(%rbp), %rsi
callq 0x6710
cmpl $0x0, %eax
je 0x52195
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
callq 0x6390
movq -0x40(%rbp), %rdi
movq %rax, %rdx
leaq 0x5f50(%rip), %rsi      # 0x580de
movb $0x0, %al
callq 0xe880
movl -0x24(%rbp), %eax
subl $0x20, %eax
cltd
idivl 0x112376(%rip)          # 0x164518
movl %eax, -0xc(%rbp)
movl -0x20(%rbp), %eax
subl $0x20, %eax
cltd
idivl 0x11236a(%rip)          # 0x16451c
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x521d9
movl 0x112359(%rip), %eax    # 0x16451c
imull -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
movl 0x112348(%rip), %eax    # 0x164518
imull -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0x521f3
movl 0x112339(%rip), %eax    # 0x164518
imull -0x10(%rbp), %eax
movl %eax, -0xc(%rbp)
movl 0x112330(%rip), %eax    # 0x16451c
imull -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movq 0x122e6(%rip), %rdi     # 0x644e0
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x6750
movq 0x122d4(%rip), %rdi     # 0x644e0
movl $0x2fff0000, %edx       # imm = 0x2FFF0000
movl %edx, %esi
callq 0x6090
addq $0x40, %rsp
popq %rbp
retq
nop