// File: kobanium[P]Ray/src/learn/PatternAnalyzer.cpp
// Function: OutputTargetPattern(std::unique_ptr<int [], std::default_delete<int []>>&, std::unique_ptr<hash_table_t, std::default_delete<hash_table_t>>&, std::unique_ptr<hash_table_t, std::default_delete<hash_table_t>>&, std::unique_ptr<hash_table_t, std::default_delete<hash_table_t>>&)
static void
OutputTargetPattern( std::unique_ptr<int[]> &md2_count,
                     std::unique_ptr<hash_table_t> &md3_count,
                     std::unique_ptr<hash_table_t> &md4_count,
                     std::unique_ptr<hash_table_t> &md5_count )
{
  const std::string result_path = GetWorkingDirectory() + PATH_SEPARATOR +
    LEARNING_RESULT_DIR_NAME + PATH_SEPARATOR +
    PATTERN_TARGET_DIR_NAME + PATH_SEPARATOR;
  std::ofstream md2_ofs(result_path + MD2_TARGET_FILE_NAME);
  std::ofstream md3_ofs(result_path + MD3_TARGET_FILE_NAME);
  std::ofstream md4_ofs(result_path + MD4_TARGET_FILE_NAME);
  std::ofstream md5_ofs(result_path + MD5_TARGET_FILE_NAME);

  for (int i = 0; i < MD2_MAX; i++) {
    if (md2_count[i] >= APPEARANCE_MIN) {
      md2_ofs << i << std::endl;
    }
  }

  for (int i = 0; i < HASH_TABLE_MAX; i++) {
    if (md3_count->data[i].hash_flag == PatternHashStatus::Registered &&
        md3_count->data[i].count >= APPEARANCE_MIN) {
      md3_ofs << md3_count->data[i].hash << std::endl;
    }
  }

  for (int i = 0; i < HASH_TABLE_MAX; i++) {
    if (md4_count->data[i].hash_flag == PatternHashStatus::Registered &&
        md4_count->data[i].count >= APPEARANCE_MIN) {
      md4_ofs << md4_count->data[i].hash << std::endl;
    }
  }

  for (int i = 0; i < HASH_TABLE_MAX; i++) {
    if (md5_count->data[i].hash_flag == PatternHashStatus::Registered &&
        md5_count->data[i].count >= APPEARANCE_MIN) {
      md5_ofs << md5_count->data[i].hash << std::endl;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x9b0, %rsp            # imm = 0x9B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x988(%rbp)
callq 0x2ccc0
movq -0x988(%rbp), %rsi
leaq 0x6ba7c(%rip), %rdx     # 0xeb7c8
leaq -0xc0(%rbp), %rdi
callq 0x632c0
jmp 0x7fd5a
leaq 0x2f11f(%rip), %rdx     # 0xaee80
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x63310
jmp 0x7fd76
leaq 0x6ba4b(%rip), %rdx     # 0xeb7c8
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x632c0
jmp 0x7fd8f
leaq 0x2f0fa(%rip), %rdx     # 0xaee90
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x63310
jmp 0x7fda5
leaq 0x6ba1c(%rip), %rdx     # 0xeb7c8
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x632c0
jmp 0x7fdbb
leaq -0x60(%rbp), %rdi
callq 0x7ae8
leaq -0x80(%rbp), %rdi
callq 0x7ae8
leaq -0xa0(%rbp), %rdi
callq 0x7ae8
leaq -0xc0(%rbp), %rdi
callq 0x7ae8
leaq -0xe0(%rbp), %rdi
callq 0x7ae8
leaq 0x2f0a7(%rip), %rdx     # 0xaee9f
leaq -0x310(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x63360
jmp 0x7fe0a
leaq -0x2f0(%rbp), %rdi
leaq -0x310(%rbp), %rsi
movl $0x10, %edx
callq 0x7a90
jmp 0x7fe24
leaq -0x310(%rbp), %rdi
callq 0x7ae8
leaq 0x2f076(%rip), %rdx     # 0xaeead
leaq -0x530(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x63360
jmp 0x7fe49
leaq -0x510(%rbp), %rdi
leaq -0x530(%rbp), %rsi
movl $0x10, %edx
callq 0x7a90
jmp 0x7fe63
leaq -0x530(%rbp), %rdi
callq 0x7ae8
leaq 0x2f045(%rip), %rdx     # 0xaeebb
leaq -0x750(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x63360
jmp 0x7fe88
leaq -0x730(%rbp), %rdi
leaq -0x750(%rbp), %rsi
movl $0x10, %edx
callq 0x7a90
jmp 0x7fea2
leaq -0x750(%rbp), %rdi
callq 0x7ae8
leaq 0x2f014(%rip), %rdx     # 0xaeec9
leaq -0x970(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x63360
jmp 0x7fec7
leaq -0x950(%rbp), %rdi
leaq -0x970(%rbp), %rsi
movl $0x10, %edx
callq 0x7a90
jmp 0x7fee1
leaq -0x970(%rbp), %rdi
callq 0x7ae8
movl $0x0, -0x974(%rbp)
cmpl $0x1000000, -0x974(%rbp) # imm = 0x1000000
jge 0x80123
movq -0x8(%rbp), %rdi
movslq -0x974(%rbp), %rsi
callq 0x80810
movq %rax, -0x990(%rbp)
jmp 0x7ff20
movq -0x990(%rbp), %rax
cmpl $0xa, (%rax)
jl 0x8010d
movl -0x974(%rbp), %esi
leaq -0x2f0(%rbp), %rdi
callq 0x7980
movq %rax, -0x998(%rbp)
jmp 0x7ff4b
movq -0x998(%rbp), %rdi
movq 0x6700f(%rip), %rsi     # 0xe6f68
callq 0x75b0
jmp 0x7ff60
jmp 0x8010d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x7fff1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x7ffe5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x7ffd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x7ffd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x7ae8
leaq -0x80(%rbp), %rdi
callq 0x7ae8
leaq -0xa0(%rbp), %rdi
callq 0x7ae8
leaq -0xc0(%rbp), %rdi
callq 0x7ae8
leaq -0xe0(%rbp), %rdi
callq 0x7ae8
jmp 0x803a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x8039f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x310(%rbp), %rdi
callq 0x7ae8
jmp 0x8039f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x80393
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x530(%rbp), %rdi
callq 0x7ae8
jmp 0x80393
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x80387
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x750(%rbp), %rdi
callq 0x7ae8
jmp 0x80387
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x8037b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x970(%rbp), %rdi
callq 0x7ae8
jmp 0x8037b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x950(%rbp), %rdi
callq 0x7820
jmp 0x8037b
jmp 0x8010f
movl -0x974(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x974(%rbp)
jmp 0x7fef7
movl $0x0, -0x978(%rbp)
cmpl $0x1000000, -0x978(%rbp) # imm = 0x1000000
jge 0x801d5
movq -0x10(%rbp), %rdi
callq 0x80910
movslq -0x978(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x28(%rax)
jne 0x801bf
movq -0x10(%rbp), %rdi
callq 0x80910
movslq -0x978(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpl $0xa, 0x20(%rax)
jl 0x801bf
movq -0x10(%rbp), %rdi
callq 0x80910
movslq -0x978(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rsi
leaq -0x510(%rbp), %rdi
callq 0x74c0
movq %rax, -0x9a0(%rbp)
jmp 0x801a8
movq -0x9a0(%rbp), %rdi
movq 0x66db2(%rip), %rsi     # 0xe6f68
callq 0x75b0
jmp 0x801bd
jmp 0x801bf
jmp 0x801c1
movl -0x978(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x978(%rbp)
jmp 0x8012d
movl $0x0, -0x97c(%rbp)
cmpl $0x1000000, -0x97c(%rbp) # imm = 0x1000000
jge 0x80287
movq -0x18(%rbp), %rdi
callq 0x80910
movslq -0x97c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x28(%rax)
jne 0x80271
movq -0x18(%rbp), %rdi
callq 0x80910
movslq -0x97c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpl $0xa, 0x20(%rax)
jl 0x80271
movq -0x18(%rbp), %rdi
callq 0x80910
movslq -0x97c(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rsi
leaq -0x730(%rbp), %rdi
callq 0x74c0
movq %rax, -0x9a8(%rbp)
jmp 0x8025a
movq -0x9a8(%rbp), %rdi
movq 0x66d00(%rip), %rsi     # 0xe6f68
callq 0x75b0
jmp 0x8026f
jmp 0x80271
jmp 0x80273
movl -0x97c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x97c(%rbp)
jmp 0x801df
movl $0x0, -0x980(%rbp)
cmpl $0x1000000, -0x980(%rbp) # imm = 0x1000000
jge 0x80339
movq -0x20(%rbp), %rdi
callq 0x80910
movslq -0x980(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x28(%rax)
jne 0x80323
movq -0x20(%rbp), %rdi
callq 0x80910
movslq -0x980(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpl $0xa, 0x20(%rax)
jl 0x80323
movq -0x20(%rbp), %rdi
callq 0x80910
movslq -0x980(%rbp), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rsi
leaq -0x950(%rbp), %rdi
callq 0x74c0
movq %rax, -0x9b0(%rbp)
jmp 0x8030c
movq -0x9b0(%rbp), %rdi
movq 0x66c4e(%rip), %rsi     # 0xe6f68
callq 0x75b0
jmp 0x80321
jmp 0x80323
jmp 0x80325
movl -0x980(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x980(%rbp)
jmp 0x80291
leaq -0x950(%rbp), %rdi
callq 0x7820
leaq -0x730(%rbp), %rdi
callq 0x7820
leaq -0x510(%rbp), %rdi
callq 0x7820
leaq -0x2f0(%rbp), %rdi
callq 0x7820
leaq -0x40(%rbp), %rdi
callq 0x7ae8
addq $0x9b0, %rsp            # imm = 0x9B0
popq %rbp
retq
leaq -0x730(%rbp), %rdi
callq 0x7820
leaq -0x510(%rbp), %rdi
callq 0x7820
leaq -0x2f0(%rbp), %rdi
callq 0x7820
leaq -0x40(%rbp), %rdi
callq 0x7ae8
movq -0xe8(%rbp), %rdi
callq 0x79b0
nopw %cs:(%rax,%rax)