// File: /workspace/github_c_makefile_star2_O0/moefh[P]hed/src/file_sel.c
// Function: draw_main_screen
static void draw_main_screen(struct file_sel *fs)
{
  struct hed_screen *scr = &fs->editor->screen;

  if (scr->window_changed) {
    reset_color();
    clear_screen();
    scr->window_changed = false;
  }

  draw_header(fs);
  draw_footer(fs);

  struct file_item *file = fs->dir_list;
  for (size_t i = 0; i < fs->top_line && file != NULL; i++)
    file = file->next;

  int line = 0;
  int col_len = (fs->max_filename_len+1 > INT_MAX) ? INT_MAX : (int)(fs->max_filename_len+1);
  if (col_len > scr->w - 20)
    col_len = scr->w - 20;
  while (file != NULL && line + 1 + EDITOR_BORDER_LINES < scr->h) {
    if (file == fs->sel)
      set_color(FG_BLACK, BG_GRAY);
    else
      reset_color();
    move_cursor(1, line + 1 + EDITOR_HEADER_LINES);

    // filename
    size_t filename_len = utf8_len(file->filename);
    //fprintf(stderr, "utf8_len('%s') = %zu\n", file->filename, filename_len);
    if (filename_len > (size_t) col_len)
      out("%.*s", col_len, file->filename);
    else
      out("%s", file->filename);
    for (size_t i = filename_len; i < (size_t)col_len; i++)
      out(" ");

    // size
    if (file->is_file)
      out("%14" PRIu64 " bytes", (uint64_t) file->size);
    else
      out("               (dir)");

    // clear rest of line
    if (file == fs->sel)
      reset_color();
    clear_eol();
        
    file = file->next;
    line++;
  }

  while (line + 1 + EDITOR_BORDER_LINES < scr->h) {
    reset_color();
    move_cursor(1, line + 1 + EDITOR_HEADER_LINES);
    clear_eol();
    line++;
  }
  
  hed_scr_flush();
  scr->redraw_needed = false;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq (%rax), %rax
addq $0x108, %rax            # imm = 0x108
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
testb $0x1, 0xc(%rax)
je 0x523a
callq 0x3d40
callq 0x3e40
movq 0x38(%rsp), %rax
movb $0x0, 0xc(%rax)
movq 0x40(%rsp), %rdi
callq 0x5d10
movq 0x40(%rsp), %rdi
callq 0x5dc0
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rcx
movq 0x40(%rsp), %rdx
xorl %eax, %eax
cmpq 0x30(%rdx), %rcx
movb %al, 0xf(%rsp)
jae 0x5288
cmpq $0x0, 0x30(%rsp)
setne %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x5292
jmp 0x52af
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x5265
movl $0x0, 0x24(%rsp)
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
addq $0x1, %rax
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jbe 0x52d7
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, 0x8(%rsp)
jmp 0x52e8
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
addq $0x1, %rax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %eax
movq 0x38(%rsp), %rcx
movl 0x4(%rcx), %ecx
subl $0x14, %ecx
cmpl %ecx, %eax
jle 0x5312
movq 0x38(%rsp), %rax
movl 0x4(%rax), %eax
subl $0x14, %eax
movl %eax, 0x20(%rsp)
jmp 0x5314
xorl %eax, %eax
cmpq $0x0, 0x30(%rsp)
movb %al, 0x7(%rsp)
je 0x533b
movl 0x24(%rsp), %eax
addl $0x1, %eax
addl $0x5, %eax
movq 0x38(%rsp), %rcx
cmpl 0x8(%rcx), %eax
setl %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x5348
jmp 0x5478
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rcx
cmpq 0x28(%rcx), %rax
jne 0x5369
movl $0x1e, %edi
movl $0x2f, %esi
callq 0x3c80
jmp 0x536e
callq 0x3d40
movl 0x24(%rsp), %esi
addl $0x1, %esi
addl $0x2, %esi
movl $0x1, %edi
callq 0x3d80
movq 0x30(%rsp), %rdi
addq $0x28, %rdi
callq 0x4da0
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movslq 0x20(%rsp), %rcx
cmpq %rcx, %rax
jbe 0x53c1
movl 0x20(%rsp), %esi
movq 0x30(%rsp), %rdx
addq $0x28, %rdx
leaq 0x610f(%rip), %rdi      # 0xb4c7
movb $0x0, %al
callq 0x3850
jmp 0x53d8
movq 0x30(%rsp), %rsi
addq $0x28, %rsi
leaq 0x6394(%rip), %rdi      # 0xb765
movb $0x0, %al
callq 0x3850
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movslq 0x20(%rsp), %rcx
cmpq %rcx, %rax
jae 0x540f
leaq 0x621f(%rip), %rdi      # 0xb617
movb $0x0, %al
callq 0x3850
movq 0x10(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10(%rsp)
jmp 0x53e2
movq 0x30(%rsp), %rax
testb $0x1, 0x18(%rax)
je 0x5433
movq 0x30(%rsp), %rax
movq 0x20(%rax), %rsi
leaq 0x6076(%rip), %rdi      # 0xb4a0
movb $0x0, %al
callq 0x3850
jmp 0x5441
leaq 0x6072(%rip), %rdi      # 0xb4ac
movb $0x0, %al
callq 0x3850
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rcx
cmpq 0x28(%rcx), %rax
jne 0x5456
callq 0x3d40
callq 0x3d60
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x5314
jmp 0x547a
movl 0x24(%rsp), %eax
addl $0x1, %eax
addl $0x5, %eax
movq 0x38(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x54b9
callq 0x3d40
movl 0x24(%rsp), %esi
addl $0x1, %esi
addl $0x2, %esi
movl $0x1, %edi
callq 0x3d80
callq 0x3d60
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x547a
callq 0x3790
movq 0x38(%rsp), %rax
movb $0x0, 0xd(%rax)
addq $0x48, %rsp
retq
nopl (%rax)