// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/voxel_space.c
// Function: init
static bool init(terrain_t *terrain, camera_t *camera) {
    scg_image_t *color_map = scg_image_new_from_bmp("assets/color_map.bmp");
    if (color_map == NULL) {
        return false;
    }

    scg_image_t *height_map = scg_image_new_from_bmp("assets/height_map.bmp");
    if (height_map == NULL) {
        return false;
    }

    if (color_map->width != height_map->width ||
        color_map->height != height_map->height) {
        scg_log_error("color map dimensions must match height map dimenstions");
        return false;
    }

    int map_w = height_map->width;
    int map_h = height_map->height;

    // Convert the heightmap to greyscale values between 0..255
    for (int y = 0; y < map_h; y++) {
        for (int x = 0; x < map_w; x++) {
            int i = scg_pixel_index_from_xy(x, y, map_w);

            scg_pixel_t color = scg_pixel_new_uint32(height_map->pixels[i]);
            color.packed = color.data.r;

            height_map->pixels[i] = color.packed;
        }
    }

    terrain->map_w = map_w;
    terrain->map_h = map_h;
    terrain->color_map = color_map;
    terrain->height_map = height_map;

    camera->x = 512.0f;
    camera->y = 800.0f;
    camera->angle = 0.0f;
    camera->height = 78.0f;
    camera->horizon = 120.0f;
    camera->max_distance = 400.0f;

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x2701(%rip), %rdi      # 0x91c8
callq 0x2c20
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x6ae0
movb $0x0, -0x1(%rbp)
jmp 0x6c62
leaq 0x26f6(%rip), %rdi      # 0x91dd
callq 0x2c20
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x6b00
movb $0x0, -0x1(%rbp)
jmp 0x6c62
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x6b1e
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x6b52
xorl %edi, %edi
leaq 0x1599(%rip), %rsi      # 0x80c0
leaq 0x18b2(%rip), %rdx      # 0x83e0
leaq 0x26be(%rip), %rcx      # 0x91f3
movl $0x27, %r8d
leaq 0x26c8(%rip), %r9       # 0x920a
movb $0x0, %al
callq 0x22e0
movb $0x0, -0x1(%rbp)
jmp 0x6c62
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x6bd3
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x6bc6
movl -0x34(%rbp), %eax
imull -0x2c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
movzbl -0x3e(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x6b7b
jmp 0x6bc8
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6b6c
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movss 0x1442(%rip), %xmm0     # 0x804c
movss %xmm0, (%rax)
movq -0x18(%rbp), %rax
movss 0x142e(%rip), %xmm0     # 0x8048
movss %xmm0, 0x4(%rax)
movq -0x18(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rax)
movq -0x18(%rbp), %rax
movss 0x140d(%rip), %xmm0     # 0x8044
movss %xmm0, 0xc(%rax)
movq -0x18(%rbp), %rax
movss 0x13f4(%rip), %xmm0     # 0x803c
movss %xmm0, 0x10(%rax)
movq -0x18(%rbp), %rax
movss 0x13e7(%rip), %xmm0     # 0x8040
movss %xmm0, 0x14(%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)