// File: /workspace/github_cpp_makefile_star2_O2/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 0x2768
pushq $0x7
popq %rdi
callq 0x2674
movl %eax, %r12d
pushq $0x50
popq %rdi
callq 0x21a0
movq %rax, %r15
movl %r12d, 0x4(%rax)
cmpl $0x6, %r12d
ja 0x28de
movl %r12d, %eax
leaq 0x18c1(%rip), %rcx      # 0x404c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movups 0x192d(%rip), %xmm0     # 0x40c8
movups %xmm0, 0x40(%r15)
movups 0x1911(%rip), %xmm0     # 0x40b8
movups %xmm0, 0x30(%r15)
movups 0x18f5(%rip), %xmm0     # 0x40a8
movups %xmm0, 0x20(%r15)
movups 0x18d9(%rip), %xmm0     # 0x4098
jmp 0x28d9
movups 0x1a3d(%rip), %xmm0     # 0x4208
movups %xmm0, 0x40(%r15)
movups 0x1a21(%rip), %xmm0     # 0x41f8
movups %xmm0, 0x30(%r15)
movups 0x1a05(%rip), %xmm0     # 0x41e8
movups %xmm0, 0x20(%r15)
movups 0x19e9(%rip), %xmm0     # 0x41d8
jmp 0x28d9
movups 0x196d(%rip), %xmm0     # 0x4168
movups %xmm0, 0x40(%r15)
movups 0x1951(%rip), %xmm0     # 0x4158
movups %xmm0, 0x30(%r15)
movups 0x1935(%rip), %xmm0     # 0x4148
movups %xmm0, 0x20(%r15)
movups 0x1919(%rip), %xmm0     # 0x4138
jmp 0x28d9
movups 0x198d(%rip), %xmm0     # 0x41b8
movups %xmm0, 0x40(%r15)
movups 0x1971(%rip), %xmm0     # 0x41a8
movups %xmm0, 0x30(%r15)
movups 0x1955(%rip), %xmm0     # 0x4198
movups %xmm0, 0x20(%r15)
movups 0x1939(%rip), %xmm0     # 0x4188
jmp 0x28d9
movups 0x18bd(%rip), %xmm0     # 0x4118
movups %xmm0, 0x40(%r15)
movups 0x18a1(%rip), %xmm0     # 0x4108
movups %xmm0, 0x30(%r15)
movups 0x1885(%rip), %xmm0     # 0x40f8
movups %xmm0, 0x20(%r15)
movups 0x1869(%rip), %xmm0     # 0x40e8
jmp 0x28d9
movups 0x19d0(%rip), %xmm0     # 0x4258
movups %xmm0, 0x40(%r15)
movups 0x19b4(%rip), %xmm0     # 0x4248
movups %xmm0, 0x30(%r15)
movups 0x1998(%rip), %xmm0     # 0x4238
movups %xmm0, 0x20(%r15)
movups 0x197c(%rip), %xmm0     # 0x4228
jmp 0x28d9
movups 0x19f3(%rip), %xmm0     # 0x42a8
movups %xmm0, 0x40(%r15)
movups 0x19d7(%rip), %xmm0     # 0x4298
movups %xmm0, 0x30(%r15)
movups 0x19bb(%rip), %xmm0     # 0x4288
movups %xmm0, 0x20(%r15)
movups 0x199f(%rip), %xmm0     # 0x4278
movups %xmm0, 0x10(%r15)
cmpl $0x3, %r14d
jne 0x28ef
pushq $0x3
popq %rdi
callq 0x2674
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