// File: /workspace/github_cpp_makefile_star2_O2/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 0x2796
testb %al, %al
je 0x2b2a
leaq 0x8a(%rsp), %rax
xorl %ecx, %ecx
movq %r12, %rdx
cmpq $0xa, %rcx
je 0x29cb
xorl %esi, %esi
cmpq $0x10, %rsi
je 0x29be
movb (%rdx,%rsi), %dil
movb %dil, (%rax,%rsi)
incq %rsi
jmp 0x29ab
incq %rcx
addq $0x10, %rdx
addq $0x13, %rax
jmp 0x29a3
leaq 0x9a(%rsp), %rax
xorl %ecx, %ecx
pushq $-0x3
popq %rdx
cmpq $0xa, %rcx
je 0x29f9
movq %rdx, %rsi
testq %rsi, %rsi
je 0x29f0
movb $0x0, 0x3(%rax,%rsi)
incq %rsi
jmp 0x29e1
incq %rcx
addq $0x13, %rax
jmp 0x29d8
leaq 0x60(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3fa6
leaq 0x18(%rsp), %r12
leaq 0x8a(%rsp), %rsi
movq %r12, %rdi
movq %r13, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x2802
movq 0x20(%r13), %rax
movq %rax, 0x50(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq %rsp, %rdi
movq %r12, %rsi
callq 0x4102
leaq 0x8a(%rsp), %r15
leaq 0x60(%rsp), %rsi
movq %rsp, %rdx
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x3fd6
movq %rax, %r14
movq %rsp, %rdi
callq 0xa6ce
xorl %eax, %eax
cmpq $0xa, %rax
je 0x2aa0
cmpl $0x11, 0x60(%rsp,%rax,4)
leaq 0x1(%rax), %rax
jl 0x2a76
pushq $0x1
popq %rdi
callq 0x20b0
leaq 0x1122a(%rip), %rsi     # 0x13cc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2220
xorl %eax, %eax
xorl %ebp, %ebp
cmpq $0xa, %rax
je 0x2ab7
addl 0x30(%rsp,%rax,4), %ebp
subl 0x60(%rsp,%rax,4), %ebp
incq %rax
jmp 0x2aa4
leaq 0x148(%rsp), %rax
xorl %ecx, %ecx
cmpq $0xa, %rcx
je 0x2ae9
xorl %edx, %edx
cmpq $0x10, %rdx
je 0x2adc
movb (%r15,%rdx), %sil
movb %sil, (%rax,%rdx)
incq %rdx
jmp 0x2ac9
incq %rcx
addq $0x13, %r15
addq $0x10, %rax
jmp 0x2ac1
leaq 0x148(%rsp), %rsi
movl $0xa0, %edx
movq %rbx, %rdi
callq 0x2130
movl %ebp, 0xa0(%rbx)
movq %r14, 0xa4(%rbx)
leaq 0x18(%rsp), %rdi
callq 0xa6ce
movq %rbx, %rax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rdi
callq 0x20b0
leaq 0x11177(%rip), %rsi     # 0x13cb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2220
movq %rax, %rbx
movq %rsp, %rdi
callq 0xa6ce
jmp 0x2b55
jmp 0x2b52
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0xa6ce
movq %rbx, %rdi
callq 0x2250