// File: 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
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x250(%rbp)
movq %rdi, %rax
movq %rax, -0x248(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x2df0
testb $0x1, %al
jne 0x32ee
movl $0x1, %edi
callq 0x20d0
movq %rax, %rdi
leaq 0x3498b(%rip), %rsi     # 0x37c70
xorl %eax, %eax
movl %eax, %edx
callq 0x22c0
movl $0x0, -0xe4(%rbp)
cmpl $0xa, -0xe4(%rbp)
jge 0x3390
movl $0x0, -0xe8(%rbp)
cmpl $0x10, -0xe8(%rbp)
jge 0x337a
movq -0x10(%rbp), %rdi
movslq -0xe4(%rbp), %rsi
callq 0x68e0
movq %rax, %rdi
movslq -0xe8(%rbp), %rsi
callq 0x6910
movb (%rax), %al
movb %al, -0x251(%rbp)
leaq -0xde(%rbp), %rdi
movslq -0xe4(%rbp), %rsi
callq 0x6790
movq %rax, %rdi
movslq -0xe8(%rbp), %rsi
callq 0x67c0
movb -0x251(%rbp), %cl
movb %cl, (%rax)
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0x330f
jmp 0x337c
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x32f8
movl $0x0, -0xec(%rbp)
cmpl $0xa, -0xec(%rbp)
jge 0x3404
movl $0x0, -0xf0(%rbp)
cmpl $0x3, -0xf0(%rbp)
jge 0x33f1
leaq -0xde(%rbp), %rdi
movslq -0xec(%rbp), %rsi
callq 0x6790
movq %rax, %rdi
movl -0xf0(%rbp), %eax
addl $0x10, %eax
movslq %eax, %rsi
callq 0x67c0
movb $0x0, (%rax)
movl -0xf0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf0(%rbp)
jmp 0x33ad
jmp 0x33f3
movl -0xec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xec(%rbp)
jmp 0x339a
movq -0x10(%rbp), %rsi
leaq -0x118(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x6940
movq -0x268(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq -0x130(%rbp), %rdi
movq %rdi, -0x260(%rbp)
leaq -0xde(%rbp), %rsi
callq 0x2f00
movq -0x260(%rbp), %rsi
movq -0xf8(%rbp), %rax
movq %rax, -0x140(%rbp)
movups -0x118(%rbp), %xmm0
movups -0x108(%rbp), %xmm1
movaps %xmm1, -0x150(%rbp)
movaps %xmm0, -0x160(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x6b70
jmp 0x3483
leaq -0xde(%rbp), %rdi
leaq -0x118(%rbp), %rsi
leaq -0x180(%rbp), %rdx
xorl %ecx, %ecx
callq 0x69f0
movq %rax, -0x270(%rbp)
jmp 0x34a8
movq -0x270(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x6850
movl $0x0, -0x190(%rbp)
cmpl $0xa, -0x190(%rbp)
jge 0x3563
movslq -0x190(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x67f0
cmpl $0x10, (%rax)
jle 0x354d
movl $0x1, %edi
callq 0x20d0
movq %rax, %rdi
leaq 0x3477b(%rip), %rsi     # 0x37c80
xorl %eax, %eax
movl %eax, %edx
callq 0x22c0
jmp 0x36d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x188(%rbp)
movl %eax, -0x18c(%rbp)
jmp 0x36ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x188(%rbp)
movl %eax, -0x18c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x6850
jmp 0x36ba
jmp 0x354f
movl -0x190(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x190(%rbp)
jmp 0x34cc
movl $0x0, -0x194(%rbp)
movl $0x0, -0x198(%rbp)
cmpl $0xa, -0x198(%rbp)
jge 0x35d6
movslq -0x198(%rbp), %rsi
leaq -0x160(%rbp), %rdi
callq 0x6c60
movl (%rax), %eax
movl %eax, -0x274(%rbp)
movslq -0x198(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x67f0
movq %rax, %rcx
movl -0x274(%rbp), %eax
subl (%rcx), %eax
addl -0x194(%rbp), %eax
movl %eax, -0x194(%rbp)
movl -0x198(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x198(%rbp)
jmp 0x3577
movl $0x0, -0x23c(%rbp)
cmpl $0xa, -0x23c(%rbp)
jge 0x367b
movl $0x0, -0x240(%rbp)
cmpl $0x10, -0x240(%rbp)
jge 0x3665
leaq -0xde(%rbp), %rdi
movslq -0x23c(%rbp), %rsi
callq 0x6790
movq %rax, %rdi
movslq -0x240(%rbp), %rsi
callq 0x67c0
movb (%rax), %al
movb %al, -0x275(%rbp)
leaq -0x238(%rbp), %rdi
movslq -0x23c(%rbp), %rsi
callq 0x6c90
movq %rax, %rdi
movslq -0x240(%rbp), %rsi
callq 0x6cc0
movb -0x275(%rbp), %cl
movb %cl, (%rax)
movl -0x240(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x240(%rbp)
jmp 0x35f7
jmp 0x3667
movl -0x23c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x35e0
movq -0x250(%rbp), %rdi
leaq -0x168(%rbp), %rsi
leaq -0x194(%rbp), %rdx
leaq -0x238(%rbp), %rcx
callq 0x6cf0
jmp 0x369e
leaq -0x130(%rbp), %rdi
callq 0x6850
movq -0x248(%rbp), %rax
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
leaq -0x130(%rbp), %rdi
callq 0x6850
movq -0x188(%rbp), %rdi
callq 0x22f0
nopw %cs:(%rax,%rax)