// File: /workspace/github_cpp_makefile_star2_O3/kmyk[P]codevs-for-student-2016/Main.cpp
// Function: simulation::simulate_with_output(primitive::blocks_t<16ul, 10ul> const&, primitive::blocks_t<3ul, 3ul> const&, primitive::output_t const&)
tuple<result_t, int, field_t> simulate_with_output(field_t const & field, pack_t const & pack, output_t const & output) { // throws exceptions
        if (not is_valid_output(field, pack, output)) throw simulate_invalid_output_exception();
        blocks_t<height + pack_size, width> workspace;
        repeat (x, width) repeat (y,    height) workspace.at[x][y] = field.at[x][y];
        repeat (x, width) repeat (y, pack_size) workspace.at[x][height + y] = empty_block;
        // 1. パックの投下
        array<int,width> height_map = make_height_map(field);
        vector<point_t> modified_blocks = drop_pack(workspace, height_map, pack, output);
        const array<int,width> height_map_original = height_map;
        // simulate()
        result_t result = simulate(workspace, height_map, modified_blocks, 0);
        // result
        repeat (x, width) if (height_map[x] > height) throw simulate_gameover_exception();
        int result_erased = 0; repeat (x, width) result_erased += height_map_original[x] - height_map[x];
        field_t nfield; repeat (x, width) repeat (y, height) nfield.at[x][y] = workspace.at[x][y];
        return make_tuple(result, result_erased, nfield);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x2981
testb %al, %al
je 0x2d50
xorl %eax, %eax
movq %r12, %rcx
movups (%rcx), %xmm0
movups %xmm0, 0x8a(%rsp,%rax)
addq $0x10, %rcx
addq $0x13, %rax
cmpq $0xbe, %rax
jne 0x2bb0
movl $0x10, %eax
movb $0x0, 0x8c(%rsp,%rax)
movw $0x0, 0x8a(%rsp,%rax)
addq $0x13, %rax
cmpq $0xce, %rax
jne 0x2bd0
xorl %eax, %eax
xorl %ecx, %ecx
cmpb $0x0, (%r12,%rcx)
je 0x2c07
incq %rcx
cmpq $0x10, %rcx
jne 0x2bf2
movl $0x10, %ecx
movl %ecx, 0x38(%rsp,%rax,4)
incq %rax
addq $0x10, %r12
cmpq $0xa, %rax
jne 0x2bf0
leaq 0x20(%rsp), %r12
leaq 0x8a(%rsp), %rsi
leaq 0x38(%rsp), %r13
movq %r12, %rdi
movq %r13, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x29f4
movq 0x20(%r13), %rax
movq %rax, 0x80(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movaps %xmm1, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x48f0
leaq 0x8a(%rsp), %r15
leaq 0x38(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x4739
movq %rax, %r14
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2c9e
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
xorl %eax, %eax
cmpl $0x11, 0x38(%rsp,%rax,4)
jge 0x2d35
incq %rax
cmpq $0xa, %rax
jne 0x2ca0
xorl %eax, %eax
xorl %ebp, %ebp
addl 0x60(%rsp,%rax,4), %ebp
subl 0x38(%rsp,%rax,4), %ebp
incq %rax
cmpq $0xa, %rax
jne 0x2cb8
xorl %eax, %eax
movups (%r15), %xmm0
movups %xmm0, 0x148(%rsp,%rax)
addq $0x13, %r15
addq $0x10, %rax
cmpq $0xa0, %rax
jne 0x2ccb
leaq 0x148(%rsp), %rsi
movl $0xa0, %edx
movq %rbx, %rdi
callq 0x2120
movl %ebp, 0xa0(%rbx)
movq %r14, 0xa4(%rbx)
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2d20
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x20b0
leaq 0x11f8a(%rip), %rsi     # 0x14cd0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2200
movl $0x1, %edi
callq 0x20b0
leaq 0x11f5f(%rip), %rsi     # 0x14cc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2200
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x2d8c
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
jmp 0x2d8c
jmp 0x2d89
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2da3
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2230