// File: bonetblai[P]mdp-engine/sailing/./sailing.h
// Function: problem_t::problem_t(int, int, int, int, int, int, float*, float*)
problem_t(int rows, int cols,
              int init_x = 0, int init_y = 0,
              int goal_x = std::numeric_limits<int>::max(),
              int goal_y = std::numeric_limits<int>::max(),
              float *wind_transition = 0, float *costs = 0)
      : Problem::problem_t<state_t>(DISCOUNT),
        rows_(rows), cols_(cols), init_(init_x, init_y), goal_(goal_x, goal_y) {

        if( (goal_x == std::numeric_limits<int>::max()) ||
            (goal_y == std::numeric_limits<int>::max()) ) {
            goal_ = state_t(rows - 1, cols - 1);
        }
        
        if( wind_transition != 0 ) {
            bcopy(wind_transition, wind_transition_, 64 * sizeof(float));
        } else {
            bcopy(default_wind_transition_, wind_transition_, 64 * sizeof(float));
        }

        // fill in sparse wind transition
        sparse_wind_transition_.reserve(8);
        for( int wind = 0; wind < 8; ++wind ) {
            std::vector<std::pair<int, float> > sparse_transition;
            for( int nwind = 0; nwind < 8; ++nwind ) {
                float p = wind_transition_[wind * 8 + nwind];
                if( p > 0 ) sparse_transition.push_back(std::make_pair(nwind, p));
            }
            sparse_wind_transition_.push_back(sparse_transition);
        }

        if( costs != 0 ) {
            bcopy(costs, costs_, 5 * sizeof(float));
        } else {
            bcopy(default_costs_, costs_, 5 * sizeof(float));
        }
    }

// Assembly:
subq $0x98, %rsp
movq 0xb0(%rsp), %rax
movq 0xa8(%rsp), %rax
movl 0xa0(%rsp), %eax
movq %rdi, 0x90(%rsp)
movl %esi, 0x8c(%rsp)
movl %edx, 0x88(%rsp)
movl %ecx, 0x84(%rsp)
movl %r8d, 0x80(%rsp)
movl %r9d, 0x7c(%rsp)
movq 0x90(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movss 0x4a45b(%rip), %xmm0    # 0x52008
movss 0x4a457(%rip), %xmm1    # 0x5200c
callq 0xb870
movq 0x28(%rsp), %rdi
leaq 0x6b052(%rip), %rax     # 0x72c18
movq %rax, (%rdi)
movl 0x8c(%rsp), %eax
movl %eax, 0x18(%rdi)
movl 0x88(%rsp), %eax
movl %eax, 0x1c(%rdi)
addq $0x134, %rdi            # imm = 0x134
movq %rdi, 0x30(%rsp)
movswl 0x84(%rsp), %esi
movswl 0x80(%rsp), %edx
xorl %ecx, %ecx
callq 0xb8c0
jmp 0x7c02
movq 0x28(%rsp), %rdi
addq $0x13a, %rdi            # imm = 0x13A
movq %rdi, 0x20(%rsp)
movswl 0x7c(%rsp), %esi
movswl 0xa0(%rsp), %edx
xorl %ecx, %ecx
callq 0xb8c0
jmp 0x7c29
movq 0x28(%rsp), %rdi
addq $0x140, %rdi            # imm = 0x140
movq %rdi, 0x10(%rsp)
callq 0xb900
movl 0x7c(%rsp), %eax
movl %eax, 0x1c(%rsp)
callq 0x7b40
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
je 0x7c74
movl 0xa0(%rsp), %eax
movl %eax, 0xc(%rsp)
callq 0x7b40
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jne 0x7d14
movl 0x8c(%rsp), %ecx
decl %ecx
movl 0x88(%rsp), %eax
decl %eax
movswl %cx, %esi
movswl %ax, %edx
leaq 0x66(%rsp), %rdi
xorl %ecx, %ecx
callq 0xb8c0
jmp 0x7c9a
movq 0x28(%rsp), %rdi
addq $0x13a, %rdi            # imm = 0x13A
leaq 0x66(%rsp), %rsi
callq 0xb910
jmp 0x7cb2
leaq 0x66(%rsp), %rdi
callq 0xb950
jmp 0x7d14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0x7ecb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0x7ec1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0x7ead
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x66(%rsp), %rdi
callq 0xb950
jmp 0x7ead
cmpq $0x0, 0xa8(%rsp)
je 0x7d3c
movq 0x28(%rsp), %rsi
movq 0xa8(%rsp), %rdi
addq $0x20, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x6370
jmp 0x7d56
movq 0x28(%rsp), %rsi
addq $0x20, %rsi
leaq 0x4a344(%rip), %rdi     # 0x52090
movl $0x100, %edx            # imm = 0x100
callq 0x6370
movq 0x28(%rsp), %rdi
addq $0x140, %rdi            # imm = 0x140
movl $0x8, %esi
callq 0xb960
jmp 0x7d6e
movl $0x0, 0x60(%rsp)
cmpl $0x8, 0x60(%rsp)
jge 0x7e5d
leaq 0x48(%rsp), %rdi
callq 0xba70
movl $0x0, 0x44(%rsp)
cmpl $0x8, 0x44(%rsp)
jge 0x7e2b
movq 0x28(%rsp), %rax
movl 0x60(%rsp), %ecx
shll $0x3, %ecx
addl 0x44(%rsp), %ecx
movslq %ecx, %rcx
movss 0x20(%rax,%rcx,4), %xmm0
movss %xmm0, 0x40(%rsp)
movss 0x40(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x7e19
leaq 0x44(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xbab0
movq %rax, (%rsp)
jmp 0x7de0
movq (%rsp), %rax
movq %rax, 0x38(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0xba80
jmp 0x7dfa
jmp 0x7e19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0xbb50
jmp 0x7ead
jmp 0x7e1b
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x7d93
movq 0x28(%rsp), %rdi
addq $0x140, %rdi            # imm = 0x140
leaq 0x48(%rsp), %rsi
callq 0xbae0
jmp 0x7e43
leaq 0x48(%rsp), %rdi
callq 0xbb50
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x7d76
cmpq $0x0, 0xb0(%rsp)
je 0x7e88
movq 0x28(%rsp), %rsi
movq 0xb0(%rsp), %rdi
addq $0x120, %rsi            # imm = 0x120
movl $0x14, %edx
callq 0x6370
jmp 0x7ea5
movq 0x28(%rsp), %rsi
addq $0x120, %rsi            # imm = 0x120
leaq 0x4a2f5(%rip), %rdi     # 0x52190
movl $0x14, %edx
callq 0x6370
addq $0x98, %rsp
retq
movq 0x10(%rsp), %rdi
callq 0xbbb0
movq 0x20(%rsp), %rdi
callq 0xb950
movq 0x30(%rsp), %rdi
callq 0xb950
movq 0x28(%rsp), %rdi
callq 0xc020
movq 0x70(%rsp), %rdi
callq 0x64a0
nop