// File: /workspace/github_c_makefile_star2_O0/skeeto[P]goblin-com/src/game.c
// Function: game_build
bool
game_build(game_t *game, uint16_t building, int x, int y)
{
    if (building == C_NONE) {
        /* Erase */
        if (game->map->high[x][y].building != C_NONE) {
            game->map->high[x][y].building = C_NONE;
            return true;
        }
    }
    if (x < 0 || x >= MAP_WIDTH || y < 0 || y >= MAP_HEIGHT ||
        game->map->high[x][y].building != C_NONE) {
        return false;
    }

    bool valid = false;
    if (x > 0 && game->map->high[x - 1][y].building != C_NONE)
        valid = true;
    else if (y > 0 && game->map->high[x][y - 1].building != C_NONE)
        valid = true;
    else if (x + 1 < MAP_WIDTH && game->map->high[x + 1][y].building != C_NONE)
        valid = true;
    else if (y + 1 < MAP_HEIGHT && game->map->high[x][y + 1].building != C_NONE)
        valid = true;
    if (valid) {
        valid = false;
        enum map_base base = game->map->high[x][y].base;
        switch (building) {
        case C_NONE:
        case C_CASTLE:
        case C_ROAD:
            valid = base != BASE_OCEAN && base != BASE_COAST;
            break;
        case C_LUMBERYARD:
            valid = base == BASE_FOREST;
            break;
        case C_STABLE:
            valid = base == BASE_GRASSLAND;
            game->max_hero += STABLE_INC;
            break;
        case C_HAMLET:
            valid =
                base == BASE_GRASSLAND ||
                base == BASE_FOREST ||
                base == BASE_HILL;
            if (valid)
                add_population(game, HAMLET_INC);
            break;
        case C_MINE:
            valid = base == BASE_HILL;
            break;
            break;
        case C_FARM:
            valid = base == BASE_GRASSLAND || base == BASE_FOREST;
            break;
        }
    }
    if (valid) {
        yield_t cost = building_cost(building);
        game->food -= cost.food;
        game->wood -= cost.wood;
        game->gold -= cost.gold;
        game->map->high[x][y].building = building;
        if (building == C_ROAD)
            game->map->high[x][y].building_age = 0;
        else
            game->map->high[x][y].building_age = INIT_BUILDING_AGE;
    }
    return valid;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movw %si, %ax
movq %rdi, -0x10(%rbp)
movw %ax, -0x12(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movzwl -0x12(%rbp), %eax
cmpl $0x0, %eax
jne 0x679e
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x679c
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movw $0x0, 0x2(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x6b51
jmp 0x679e
cmpl $0x0, -0x18(%rbp)
jl 0x67e0
cmpl $0x3c, -0x18(%rbp)
jge 0x67e0
cmpl $0x0, -0x1c(%rbp)
jl 0x67e0
cmpl $0x18, -0x1c(%rbp)
jge 0x67e0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x67e9
movb $0x0, -0x1(%rbp)
jmp 0x6b51
movb $0x0, -0x1d(%rbp)
cmpl $0x0, -0x18(%rbp)
jle 0x682b
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x682b
movb $0x1, -0x1d(%rbp)
jmp 0x68ed
cmpl $0x0, -0x1c(%rbp)
jle 0x6869
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x6869
movb $0x1, -0x1d(%rbp)
jmp 0x68eb
movl -0x18(%rbp), %eax
addl $0x1, %eax
cmpl $0x3c, %eax
jge 0x68a9
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x68a9
movb $0x1, -0x1d(%rbp)
jmp 0x68e9
movl -0x1c(%rbp), %eax
addl $0x1, %eax
cmpl $0x18, %eax
jge 0x68e7
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzwl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x68e7
movb $0x1, -0x1d(%rbp)
jmp 0x68e9
jmp 0x68eb
jmp 0x68ed
testb $0x1, -0x1d(%rbp)
je 0x6a54
movb $0x0, -0x1d(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movslq -0x18(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x7, %rax
addq %rax, %rcx
movslq -0x1c(%rbp), %rax
shlq $0x4, %rax
movzwl (%rax,%rcx), %eax
movl %eax, -0x24(%rbp)
movzwl -0x12(%rbp), %eax
movl %eax, -0x44(%rbp)
testl %eax, %eax
je 0x6983
jmp 0x692e
movl -0x44(%rbp), %eax
subl $0x2b, %eax
je 0x6983
jmp 0x6938
movl -0x44(%rbp), %eax
subl $0x43, %eax
je 0x6983
jmp 0x6942
movl -0x44(%rbp), %eax
subl $0x46, %eax
je 0x6a32
jmp 0x6950
movl -0x44(%rbp), %eax
subl $0x48, %eax
je 0x69dd
jmp 0x695e
movl -0x44(%rbp), %eax
subl $0x4d, %eax
je 0x6a21
jmp 0x696c
movl -0x44(%rbp), %eax
subl $0x53, %eax
je 0x69bc
jmp 0x6976
movl -0x44(%rbp), %eax
subl $0x57, %eax
je 0x69a8
jmp 0x6a52
xorl %eax, %eax
cmpl $0x20, -0x24(%rbp)
movb %al, -0x45(%rbp)
je 0x699b
cmpl $0x2248, -0x24(%rbp)    # imm = 0x2248
setne %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
andb $0x1, %al
movb %al, -0x1d(%rbp)
jmp 0x6a52
cmpl $0x2663, -0x24(%rbp)    # imm = 0x2663
sete %al
andb $0x1, %al
movb %al, -0x1d(%rbp)
jmp 0x6a52
cmpl $0x2e, -0x24(%rbp)
sete %al
andb $0x1, %al
movb %al, -0x1d(%rbp)
movq -0x10(%rbp), %rax
movl 0x3c8(%rax), %ecx
addl $0x2, %ecx
movl %ecx, 0x3c8(%rax)
jmp 0x6a52
movb $0x1, %al
cmpl $0x2e, -0x24(%rbp)
movb %al, -0x46(%rbp)
je 0x6a03
movb $0x1, %al
cmpl $0x2663, -0x24(%rbp)    # imm = 0x2663
movb %al, -0x46(%rbp)
je 0x6a03
cmpl $0x2229, -0x24(%rbp)    # imm = 0x2229
sete %al
movb %al, -0x46(%rbp)
movb -0x46(%rbp), %al
andb $0x1, %al
movb %al, -0x1d(%rbp)
testb $0x1, -0x1d(%rbp)
je 0x6a1f
movq -0x10(%rbp), %rdi
movl $0xc8, %esi
callq 0x6b60
jmp 0x6a52
cmpl $0x2229, -0x24(%rbp)    # imm = 0x2229
sete %al
andb $0x1, %al
movb %al, -0x1d(%rbp)
jmp 0x6a52
movb $0x1, %al
cmpl $0x2e, -0x24(%rbp)
movb %al, -0x47(%rbp)
je 0x6a4a
cmpl $0x2663, -0x24(%rbp)    # imm = 0x2663
sete %al
movb %al, -0x47(%rbp)
movb -0x47(%rbp), %al
andb $0x1, %al
movb %al, -0x1d(%rbp)
jmp 0x6a54
testb $0x1, -0x1d(%rbp)
je 0x6b49
movzwl -0x12(%rbp), %edi
callq 0x6bf0
movl %edx, -0x38(%rbp)
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x28(%rbp)
cvtsi2sdl -0x2c(%rbp), %xmm1
movq -0x10(%rbp), %rax
movsd 0x28(%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rax)
cvtsi2sdl -0x28(%rbp), %xmm1
movq -0x10(%rbp), %rax
movsd 0x20(%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rax)
cvtsi2sdl -0x30(%rbp), %xmm1
movq -0x10(%rbp), %rax
movsd 0x18(%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rax)
movw -0x12(%rbp), %cx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x18(%rbp), %rdx
imulq $0x180, %rdx, %rdx      # imm = 0x180
addq %rdx, %rax
movslq -0x1c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movw %cx, 0x2(%rax)
movzwl -0x12(%rbp), %eax
cmpl $0x2b, %eax
jne 0x6b1e
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
jmp 0x6b47
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $-0x15180, 0x8(%rax)    # imm = 0xFFFEAE80
jmp 0x6b49
movb -0x1d(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)