// File: /workspace/github_cpp_makefile_star2_O1/miklhh[P]tetris/src/game.cpp
// Function: block_spawn(int, int, int, int)
block_t* block_spawn(block_type_t block_type, int start_x, int start_y, color_t color)
{
    /* Decide what to spawn. */
    block_type_t block_to_spawn;
    if (block_type == BLOCK_RANDOM)
        block_to_spawn = (block_type_t)random_int(BLOCK_RANDOM);
    else
        block_to_spawn = block_type;


    /* Spawn the block. */
    block_t* block      = new block_t;
    block->block_type   = block_to_spawn;
    switch (block_to_spawn)
    {
    case BLOCK_I:
        block->structure = block_ref_i.structure;
        break;

    case BLOCK_J:
        block->structure = block_ref_j.structure;
        break;

    case BLOCK_L:
        block->structure = block_ref_l.structure;
        break;

    case BLOCK_O:
        block->structure = block_ref_o.structure;
        break;

    case BLOCK_Z:
        block->structure = block_ref_z.structure;
        break;

    case BLOCK_T:
        block->structure = block_ref_t.structure;
        break;

    case BLOCK_S:
        block->structure = block_ref_s.structure;
        break;
    }

    /* Set the block position, color and return the block-pointer. */
    if (color == COLOR_RANDOM)
    {
        block->color = random_int(COLOR_RANDOM);
    }
    else
    {
        block->color = color;
    }
    block->position.x = start_x;
    block->position.y = start_y;
   
    return block;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %ecx, %r14d
movl %edx, %ebx
movl %esi, %ebp
movl %edi, %r12d
cmpl $0x7, %edi
jne 0x281b
movl $0x7, %edi
callq 0x26f4
movl %eax, %r12d
movl $0x50, %edi
callq 0x21d0
movq %rax, %r15
movl %r12d, 0x4(%rax)
cmpl $0x6, %r12d
ja 0x2993
movl %r12d, %eax
leaq 0x180c(%rip), %rcx      # 0x404c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movups 0x1878(%rip), %xmm0     # 0x40c8
movups %xmm0, 0x40(%r15)
movups 0x185c(%rip), %xmm0     # 0x40b8
movups %xmm0, 0x30(%r15)
movups 0x1840(%rip), %xmm0     # 0x40a8
movups %xmm0, 0x20(%r15)
movups 0x1824(%rip), %xmm0     # 0x4098
jmp 0x298e
movups 0x1988(%rip), %xmm0     # 0x4208
movups %xmm0, 0x40(%r15)
movups 0x196c(%rip), %xmm0     # 0x41f8
movups %xmm0, 0x30(%r15)
movups 0x1950(%rip), %xmm0     # 0x41e8
movups %xmm0, 0x20(%r15)
movups 0x1934(%rip), %xmm0     # 0x41d8
jmp 0x298e
movups 0x18b8(%rip), %xmm0     # 0x4168
movups %xmm0, 0x40(%r15)
movups 0x189c(%rip), %xmm0     # 0x4158
movups %xmm0, 0x30(%r15)
movups 0x1880(%rip), %xmm0     # 0x4148
movups %xmm0, 0x20(%r15)
movups 0x1864(%rip), %xmm0     # 0x4138
jmp 0x298e
movups 0x18d8(%rip), %xmm0     # 0x41b8
movups %xmm0, 0x40(%r15)
movups 0x18bc(%rip), %xmm0     # 0x41a8
movups %xmm0, 0x30(%r15)
movups 0x18a0(%rip), %xmm0     # 0x4198
movups %xmm0, 0x20(%r15)
movups 0x1884(%rip), %xmm0     # 0x4188
jmp 0x298e
movups 0x1808(%rip), %xmm0     # 0x4118
movups %xmm0, 0x40(%r15)
movups 0x17ec(%rip), %xmm0     # 0x4108
movups %xmm0, 0x30(%r15)
movups 0x17d0(%rip), %xmm0     # 0x40f8
movups %xmm0, 0x20(%r15)
movups 0x17b4(%rip), %xmm0     # 0x40e8
jmp 0x298e
movups 0x191b(%rip), %xmm0     # 0x4258
movups %xmm0, 0x40(%r15)
movups 0x18ff(%rip), %xmm0     # 0x4248
movups %xmm0, 0x30(%r15)
movups 0x18e3(%rip), %xmm0     # 0x4238
movups %xmm0, 0x20(%r15)
movups 0x18c7(%rip), %xmm0     # 0x4228
jmp 0x298e
movups 0x193e(%rip), %xmm0     # 0x42a8
movups %xmm0, 0x40(%r15)
movups 0x1922(%rip), %xmm0     # 0x4298
movups %xmm0, 0x30(%r15)
movups 0x1906(%rip), %xmm0     # 0x4288
movups %xmm0, 0x20(%r15)
movups 0x18ea(%rip), %xmm0     # 0x4278
movups %xmm0, 0x10(%r15)
cmpl $0x3, %r14d
jne 0x29a6
movl $0x3, %edi
callq 0x26f4
movl %eax, %r14d
movl %r14d, (%r15)
movl %ebp, 0x8(%r15)
movl %ebx, 0xc(%r15)
movq %r15, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq