// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/map.c
// Function: save_map
void save_map(char const * const fn) {
    assert(global_map);
    if(global_map->flags & MAP_PRESENT && !(global_map->flags & MAP_SAVED)) {
        FILE *file = fopen(fn, "wb");
        if(!file) {
            PRINTWARN("Could not save heightmap")
            return;
        }
        CALLEXIT(!(fwrite(&global_map->dim, sizeof global_map->dim, 1, file)))
        CALLEXIT(!(fwrite(&global_map->flags, sizeof global_map->flags, 1, file)))
        CALLEXIT(!(fwrite(&global_map->water_level, sizeof global_map->water_level, 1, file)))

        int dim = global_map->dim;

        size_t nmemb = (size_t) (dim * dim);
        CALLEXIT(fwrite(global_map->heightmap, sizeof *global_map->heightmap, nmemb, file) != nmemb)

        nmemb = (size_t) (dim * dim);
        CALLEXIT(fwrite(global_map->m_ent, sizeof *global_map->m_ent, nmemb, file) != nmemb)

        CALLEXIT(!(fwrite(&global_map->town_count, sizeof global_map->town_count, 1, file)))
        for (int i = 0; i < global_map->town_count; i++) {
            CALLEXIT(fwrite(global_map->towns[i].matdistr, sizeof *global_map->towns[i].matdistr, MAT_COUNT, file) !=
                     MAT_COUNT)
            CALLEXIT(!(fwrite(&(global_map->towns[i].entitiy_count), sizeof global_map->towns[i].entitiy_count, 1,
                              file)))
            for (int j = 0; j < global_map->towns[i].entitiy_count; j++) {
                struct Location e_pos = entity_location(global_map->towns[i].t_ent[0]);
                CALLEXIT(!(fwrite(&e_pos, sizeof e_pos, 1, file)))
            }
        }

        printf(INFO "Saved map\n");
        fclose(file);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, 0x18acc(%rip)     # 0x26290
je 0xd7c8
jmp 0xd7e7
leaq 0x10f81(%rip), %rdi     # 0x1e750
leaq 0x10f85(%rip), %rsi     # 0x1e75b
movl $0x84, %edx
leaq 0x10f83(%rip), %rcx     # 0x1e765
callq 0x2100
movq 0x18aa2(%rip), %rax     # 0x26290
movl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xdb1c
movq 0x18a8c(%rip), %rax     # 0x26290
movl 0x24(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0xdb1c
movq -0x8(%rbp), %rdi
leaq 0x10f68(%rip), %rsi     # 0x1e786
callq 0x2230
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xd83f
leaq 0x10f54(%rip), %rdi     # 0x1e789
callq 0x2190
jmp 0xdb1c
movq 0x18a4a(%rip), %rdi     # 0x26290
addq $0x20, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2470
cmpq $0x0, %rax
jne 0xd879
leaq 0x10f5a(%rip), %rdi     # 0x1e7c4
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq 0x18a10(%rip), %rdi     # 0x26290
addq $0x24, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2470
cmpq $0x0, %rax
jne 0xd8b3
leaq 0x10f7f(%rip), %rdi     # 0x1e823
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq 0x189d6(%rip), %rdi     # 0x26290
addq $0x1c, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2470
cmpq $0x0, %rax
jne 0xd8ed
leaq 0x10fa8(%rip), %rdi     # 0x1e886
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq 0x1899c(%rip), %rax     # 0x26290
movl 0x20(%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cltq
movq %rax, -0x20(%rbp)
movq 0x18982(%rip), %rax     # 0x26290
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rcx
movl $0x4, %esi
callq 0x2470
cmpq -0x20(%rbp), %rax
je 0xd93f
leaq 0x10fc5(%rip), %rdi     # 0x1e8f5
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cltq
movq %rax, -0x20(%rbp)
movq 0x1893d(%rip), %rax     # 0x26290
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rcx
movl $0x8, %esi
callq 0x2470
cmpq -0x20(%rbp), %rax
je 0xd985
leaq 0x10ff4(%rip), %rdi     # 0x1e96a
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq 0x18904(%rip), %rdi     # 0x26290
addq $0x18, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2470
cmpq $0x0, %rax
jne 0xd9bf
leaq 0x11027(%rip), %rdi     # 0x1e9d7
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq 0x188c0(%rip), %rcx     # 0x26290
cmpl 0x18(%rcx), %eax
jge 0xdb05
movq 0x188b0(%rip), %rax     # 0x26290
movq 0x10(%rax), %rdi
movslq -0x24(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x8, %edx
callq 0x2470
cmpq $0x8, %rax
je 0xda1e
leaq 0x11035(%rip), %rdi     # 0x1ea44
callq 0x2190
movl $0x1, %edi
callq 0x2260
movq 0x1886b(%rip), %rax     # 0x26290
movq 0x10(%rax), %rdi
movslq -0x24(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
addq $0x28, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2470
cmpq $0x0, %rax
jne 0xda67
leaq 0x11079(%rip), %rdi     # 0x1ead1
callq 0x2190
movl $0x1, %edi
callq 0x2260
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq 0x18818(%rip), %rcx     # 0x26290
movq 0x10(%rcx), %rcx
movslq -0x24(%rbp), %rdx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x28(%rcx), %eax
jge 0xdaf5
movq 0x187fd(%rip), %rax     # 0x26290
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rax
movq (%rax), %rdi
callq 0xdb30
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rcx
leaq -0x30(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x2470
cmpq $0x0, %rax
jne 0xdae5
leaq 0x11082(%rip), %rdi     # 0x1eb58
callq 0x2190
movl $0x1, %edi
callq 0x2260
jmp 0xdae7
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xda6e
jmp 0xdaf7
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xd9c6
leaq 0x11097(%rip), %rdi     # 0x1eba3
movb $0x0, %al
callq 0x2040
movq -0x10(%rbp), %rdi
callq 0x21f0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)