// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/src/startgtk_game.c
// Function: populate_video_modes
static void populate_video_modes(gboolean firsttime)
{
    int i, mode3d = -1;
    int xdim = 0, ydim = 0, bpp = 0, fullscreen = 0;
    char modestr[64];
    int cd[] = { 32, 24, 16, 15, 8, 0 };
    GtkTreeIter iter;

    if (firsttime) {
        getvalidmodes();
        xdim = settings->xdim3d;
        ydim = settings->ydim3d;
        bpp  = settings->bpp3d;
        fullscreen = settings->fullscreen;
    } else {
        // Read back the current resolution information selected in the combobox.
        fullscreen = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(controls.fullscreencheck));
        if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(controls.vmode3dcombo), &iter)) {
            gtk_tree_model_get(GTK_TREE_MODEL(controls.vmode3dlist), &iter, 1 /*index*/, &mode3d, -1);
        }
        if (mode3d >= 0) {
            xdim = validmode[mode3d].xdim;
            ydim = validmode[mode3d].ydim;
            bpp = validmode[mode3d].bpp;
        }
    }

    // Find an ideal match.
    mode3d = checkvideomode(&xdim, &ydim, bpp, fullscreen, 1);
    if (mode3d < 0) {
        for (i=0; cd[i]; ) { if (cd[i] >= bpp) i++; else break; }
        for ( ; cd[i]; i++) {
            mode3d = checkvideomode(&xdim, &ydim, cd[i], fullscreen, 1);
            if (mode3d < 0) continue;
            break;
        }
    }

    // Repopulate the list.
    gtk_list_store_clear(controls.vmode3dlist);
    for (i = 0; i < validmodecnt; i++) {
        if (validmode[i].fs != fullscreen) continue;

        sprintf(modestr, "%d \xc3\x97 %d %d-bpp",
            validmode[i].xdim, validmode[i].ydim, validmode[i].bpp);
        gtk_list_store_insert_with_values(controls.vmode3dlist,
            &iter, -1,
            0, modestr, 1, i, -1);
        if (i == mode3d) {
            gtk_combo_box_set_active_iter(GTK_COMBO_BOX(controls.vmode3dcombo), &iter);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, 0x8(%rsp)
movl %eax, 0x4(%rsp)
testl %edi, %edi
je 0x315c3
callq 0x7f58c
movq 0x2fa945(%rip), %rax    # 0x32bef0
movl 0x4(%rax), %ecx
movl %ecx, 0x8(%rsp)
movl 0x8(%rax), %ecx
movl %ecx, 0x4(%rsp)
movl (%rax), %ebx
movl 0xc(%rax), %ebp
jmp 0x3166c
movq 0x2fa8d6(%rip), %rbx    # 0x32bea0
callq 0x90f0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x8160
movq %rax, %rdi
callq 0x8400
movl %eax, %ebx
movq 0x2fa8a5(%rip), %r14    # 0x32be90
callq 0x88d0
movq %r14, %rdi
movq %rax, %rsi
callq 0x8160
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x91b0
testl %eax, %eax
je 0x31640
movq 0x2fa885(%rip), %r14    # 0x32be98
callq 0x85c0
movq %r14, %rdi
movq %rax, %rsi
callq 0x8160
leaq 0x10(%rsp), %rsi
movq %rsp, %rcx
movq %rax, %rdi
movl $0x1, %edx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
xorl %eax, %eax
callq 0x8970
movslq (%rsp), %rax
testq %rax, %rax
js 0x3166a
shlq $0x4, %rax
leaq 0x5b865c(%rip), %rcx    # 0x5e9cb0
movl (%rcx,%rax), %edx
movl 0x4(%rcx,%rax), %esi
movl %edx, 0x8(%rsp)
movl %esi, 0x4(%rsp)
movzbl 0x8(%rcx,%rax), %ebp
jmp 0x3166c
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
movl %ebp, %edx
movl %ebx, %ecx
movl $0x1, %r8d
callq 0x318b0
movl %eax, (%rsp)
testl %eax, %eax
jns 0x316f4
leaq 0x70e5d(%rip), %rcx     # 0xa24f0
xorl %eax, %eax
cmpl %ebp, (%rcx)
jl 0x316ab
incq %rax
addq $0x4, %rcx
cmpq $0x5, %rax
jne 0x31695
movl $0x5, %eax
cmpl $0x5, %eax
je 0x316f4
movl %eax, %r12d
shlq $0x2, %r12
leaq 0x70e32(%rip), %r13     # 0xa24f0
leaq 0x8(%rsp), %r14
leaq 0x4(%rsp), %r15
movl (%r12,%r13), %edx
movq %r14, %rdi
movq %r15, %rsi
movl %ebx, %ecx
movl $0x1, %r8d
callq 0x318b0
movl %eax, (%rsp)
testl %eax, %eax
jns 0x316f4
leaq 0x4(%r12), %rax
cmpq $0x10, %r12
movq %rax, %r12
jne 0x316c8
movq 0x2fa79d(%rip), %rdi    # 0x32be98
callq 0x84e0
leaq 0x4da009(%rip), %rbp    # 0x50b710
cmpl $0x0, (%rbp)
jle 0x317d6
leaq 0x5b8598(%rip), %r14    # 0x5e9cb0
addq $0x9, %r14
leaq 0x70c63(%rip), %r13     # 0xa2386
leaq 0x30(%rsp), %r15
xorl %r12d, %r12d
movl %ebx, 0xc(%rsp)
movzbl (%r14), %eax
cmpl %eax, %ebx
jne 0x317c2
movl -0x9(%r14), %edx
movl -0x5(%r14), %ecx
movzbl -0x1(%r14), %r8d
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x8f20
movq 0x2fa73c(%rip), %rdi    # 0x32be98
leaq 0x10(%rsp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movq %r15, %r8
movl $0x1, %r9d
xorl %eax, %eax
pushq $-0x1
pushq %r12
callq 0x8aa0
addq $0x10, %rsp
movl (%rsp), %eax
cmpq %rax, %r12
jne 0x317c2
movq %r15, %rbx
movq %rbp, %r15
movq %r13, %rbp
movq 0x2fa6f8(%rip), %r13    # 0x32be90
callq 0x88d0
movq %r13, %rdi
movq %rbp, %r13
movq %r15, %rbp
movq %rbx, %r15
movl 0xc(%rsp), %ebx
movq %rax, %rsi
callq 0x8160
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x8730
incq %r12
movslq (%rbp), %rax
addq $0x10, %r14
cmpq %rax, %r12
jl 0x3172f
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq