// File: murry2018[P]mogazi/kakaotalk_chat.cpp
// Function: kakaotalk::chat::analyse()
void chat::analyse() {
    static const regex pattern_common("\
^(\\d+)년 (\\d+)월 (\\d+)일 (오전|오후) (\\d+):(\\d+), ((?:.|\\n)*)");
    static const regex pattern_in("(?:([^:]*)님이 들어왔습니다\\.((?:.|\\n)*)|(?:[^:]*)님이 ([^:]*)님을 초대했습니다\\.)");
    static const regex pattern_out("([^:]*)님(이 나갔습니다|을 내보냈습니다)\\.");
    static const regex pattern_talk("(?:([^:]*) : ?)((?:.|\\n)*)");
    static const string pattern_extra1("삭제된 메시지입니다.");
    static const string pattern_extra2("채팅방 관리자가 메시지를 가렸습니다.");
    
    std::smatch m_common;
    if (regex_match(full_content, m_common, pattern_common)) {
      string chat_content = m_common[7];
      std::smatch m_content;
      if (regex_match(chat_content, m_content, pattern_talk)) {
        /* 떠드는 패턴인 경우: 

           '2019년 5월 27일 오전 12:22, 악성유저 : 악성유저님이 나갔습니다.'

           이와 같은 특수 케이스로부터 방어하기 위해 떠드는 패턴을
           우선적으로 체크한다. */
        type = chat::TALK;
        _name = m_content[1], _content = m_content[2];
      } else if (regex_match(chat_content, m_content, pattern_in)) {
        // 들어온 패턴인 경우 (나가는 패턴과의 확인 순서는 중요치 않다)
        type = chat::IN;
        _name = m_content[1];
        if (m_content[2] != "") {
          /* 들어온 사람이 자기자신인지 확인: 자기 자신은 들어올땐
             이름으로 표시되고 떠들땐 회원님이라 표시되기 때문에 이를
             구분해주지 않으면 가만히 있는 사람 한명이 더 생긴다. */
          _myself = true;
        } else {
          _myself = false;
        }
      } else if (regex_match(chat_content, m_content, pattern_out)) {
        // 나가는 패턴인 경우
        type = chat::OUT;
        _name = m_content[1];
      } else if (chat_content == pattern_extra1
                 || chat_content == pattern_extra2) {
        type = chat::EXTRA;
      } else {
        // '2019년 5월 27일 오전 12:22, 이런시발' 과 같은 잘못된 형식인 경우
        std::cout << chat_content << std::endl;
        throw runtime_error("Unexpected Chat Pattern");
      }
    } else {
      /* 채팅 내용이 아닌 패턴 */
      type = chat::EXTRA;
    }
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x100(%rbp)
cmpb $0x0, 0x453df(%rip)     # 0x4f800
jne 0xa474
leaq 0x453d6(%rip), %rdi     # 0x4f800
callq 0x56e0
cmpl $0x0, %eax
je 0xa474
leaq 0x453a5(%rip), %rdi     # 0x4f7e0
leaq 0x2ae29(%rip), %rsi     # 0x3526b
movl $0x10, %edx
callq 0xae50
jmp 0xa44e
leaq 0xa9b(%rip), %rdi       # 0xaef0
leaq 0x45384(%rip), %rsi     # 0x4f7e0
leaq 0x44f55(%rip), %rdx     # 0x4f3b8
callq 0x53a0
leaq 0x45391(%rip), %rdi     # 0x4f800
callq 0x52d0
cmpb $0x0, 0x453ad(%rip)     # 0x4f828
jne 0xa4ce
leaq 0x453a4(%rip), %rdi     # 0x4f828
callq 0x56e0
cmpl $0x0, %eax
je 0xa4ce
leaq 0x45373(%rip), %rdi     # 0x4f808
leaq 0x2ae14(%rip), %rsi     # 0x352b0
movl $0x10, %edx
callq 0xae50
jmp 0xa4a8
leaq 0xa41(%rip), %rdi       # 0xaef0
leaq 0x45352(%rip), %rsi     # 0x4f808
leaq 0x44efb(%rip), %rdx     # 0x4f3b8
callq 0x53a0
leaq 0x4535f(%rip), %rdi     # 0x4f828
callq 0x52d0
cmpb $0x0, 0x4537b(%rip)     # 0x4f850
jne 0xa528
leaq 0x45372(%rip), %rdi     # 0x4f850
callq 0x56e0
cmpl $0x0, %eax
je 0xa528
leaq 0x45341(%rip), %rdi     # 0x4f830
leaq 0x2ae1f(%rip), %rsi     # 0x35315
movl $0x10, %edx
callq 0xae50
jmp 0xa502
leaq 0x9e7(%rip), %rdi       # 0xaef0
leaq 0x45320(%rip), %rsi     # 0x4f830
leaq 0x44ea1(%rip), %rdx     # 0x4f3b8
callq 0x53a0
leaq 0x4532d(%rip), %rdi     # 0x4f850
callq 0x52d0
cmpb $0x0, 0x45349(%rip)     # 0x4f878
jne 0xa582
leaq 0x45340(%rip), %rdi     # 0x4f878
callq 0x56e0
cmpl $0x0, %eax
je 0xa582
leaq 0x4530f(%rip), %rdi     # 0x4f858
leaq 0x2adfe(%rip), %rsi     # 0x3534e
movl $0x10, %edx
callq 0xae50
jmp 0xa55c
leaq 0x98d(%rip), %rdi       # 0xaef0
leaq 0x452ee(%rip), %rsi     # 0x4f858
leaq 0x44e47(%rip), %rdx     # 0x4f3b8
callq 0x53a0
leaq 0x452fb(%rip), %rdi     # 0x4f878
callq 0x52d0
cmpb $0x0, 0x45317(%rip)     # 0x4f8a0
jne 0xa5f7
leaq 0x4530e(%rip), %rdi     # 0x4f8a0
callq 0x56e0
cmpl $0x0, %eax
je 0xa5f7
leaq -0x15(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x56b0
movq -0x108(%rbp), %rdx
leaq 0x452c6(%rip), %rdi     # 0x4f880
leaq 0x2ada8(%rip), %rsi     # 0x35369
callq 0x6700
jmp 0xa5c8
leaq -0x15(%rbp), %rdi
callq 0x5470
movq 0x44998(%rip), %rdi     # 0x4ef70
leaq 0x452a1(%rip), %rsi     # 0x4f880
leaq 0x44dd2(%rip), %rdx     # 0x4f3b8
callq 0x53a0
leaq 0x452ae(%rip), %rdi     # 0x4f8a0
callq 0x52d0
cmpb $0x0, 0x452ca(%rip)     # 0x4f8c8
jne 0xa66c
leaq 0x452c1(%rip), %rdi     # 0x4f8c8
callq 0x56e0
cmpl $0x0, %eax
je 0xa66c
leaq -0x16(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x56b0
movq -0x110(%rbp), %rdx
leaq 0x45279(%rip), %rdi     # 0x4f8a8
leaq 0x2ad51(%rip), %rsi     # 0x35387
callq 0x6700
jmp 0xa63d
leaq -0x16(%rbp), %rdi
callq 0x5470
movq 0x44923(%rip), %rdi     # 0x4ef70
leaq 0x45254(%rip), %rsi     # 0x4f8a8
leaq 0x44d5d(%rip), %rdx     # 0x4f3b8
callq 0x53a0
leaq 0x45261(%rip), %rdi     # 0x4f8c8
callq 0x52d0
leaq -0x38(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0xaf20
movq -0x100(%rbp), %rdi
movq -0x120(%rbp), %rsi
leaq 0x4514f(%rip), %rdx     # 0x4f7e0
xorl %ecx, %ecx
callq 0xaf60
movb %al, -0x111(%rbp)
jmp 0xa6a0
movb -0x111(%rbp), %al
testb $0x1, %al
jne 0xa6af
jmp 0xab3d
leaq -0x38(%rbp), %rdi
movl $0x7, %esi
callq 0xafc0
movq %rax, -0x128(%rbp)
jmp 0xa6c6
movq -0x128(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0xb030
jmp 0xa6d8
leaq -0x78(%rbp), %rdi
callq 0xaf20
jmp 0xa6e3
leaq 0x4516e(%rip), %rdx     # 0x4f858
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
xorl %ecx, %ecx
callq 0xaf60
movb %al, -0x129(%rbp)
jmp 0xa701
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0xa710
jmp 0xa8d1
movq -0x100(%rbp), %rax
movl $0x2, 0x20(%rax)
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0xafc0
movq %rax, -0x138(%rbp)
jmp 0xa735
movq -0x138(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0xb030
jmp 0xa74a
movq -0x100(%rbp), %rdi
addq $0x48, %rdi
leaq -0x98(%rbp), %rsi
callq 0x5510
leaq -0x78(%rbp), %rdi
movl $0x2, %esi
callq 0xafc0
movq %rax, -0x140(%rbp)
jmp 0xa778
movq -0x140(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0xb030
jmp 0xa78d
movq -0x100(%rbp), %rdi
addq $0x28, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x5510
leaq -0xb8(%rbp), %rdi
callq 0x5768
leaq -0x98(%rbp), %rdi
callq 0x5768
jmp 0xab15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq 0x4502c(%rip), %rdi     # 0x4f800
callq 0x52b0
jmp 0xab66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq 0x45037(%rip), %rdi     # 0x4f828
callq 0x52b0
jmp 0xab66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq 0x45042(%rip), %rdi     # 0x4f850
callq 0x52b0
jmp 0xab66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq 0x4504d(%rip), %rdi     # 0x4f878
callq 0x52b0
jmp 0xab66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x15(%rbp), %rdi
callq 0x5470
leaq 0x4504f(%rip), %rdi     # 0x4f8a0
callq 0x52b0
jmp 0xab66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x16(%rbp), %rdi
callq 0x5470
leaq 0x45051(%rip), %rdi     # 0x4f8c8
callq 0x52b0
jmp 0xab66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0xab5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0xab32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0xab29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x5768
jmp 0xab29
leaq 0x44f30(%rip), %rdx     # 0x4f808
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
xorl %ecx, %ecx
callq 0xaf60
movb %al, -0x141(%rbp)
jmp 0xa8ef
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0xa8fe
jmp 0xa9bd
movq -0x100(%rbp), %rax
movl $0x0, 0x20(%rax)
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0xafc0
movq %rax, -0x150(%rbp)
jmp 0xa923
movq -0x150(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0xb030
jmp 0xa938
movq -0x100(%rbp), %rdi
addq $0x48, %rdi
leaq -0xd8(%rbp), %rsi
movq %rsi, -0x160(%rbp)
callq 0x5510
movq -0x160(%rbp), %rdi
callq 0x5768
leaq -0x78(%rbp), %rdi
movl $0x2, %esi
callq 0xafc0
movq %rax, -0x158(%rbp)
jmp 0xa979
movq -0x158(%rbp), %rdi
leaq 0x2aada(%rip), %rsi     # 0x35461
callq 0xb060
movb %al, -0x161(%rbp)
jmp 0xa994
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0xa9a0
jmp 0xa9ad
movq -0x100(%rbp), %rax
movb $0x1, 0x68(%rax)
jmp 0xa9b8
movq -0x100(%rbp), %rax
movb $0x0, 0x68(%rax)
jmp 0xab13
leaq 0x44e6c(%rip), %rdx     # 0x4f830
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rsi
xorl %ecx, %ecx
callq 0xaf60
movb %al, -0x162(%rbp)
jmp 0xa9db
movb -0x162(%rbp), %al
testb $0x1, %al
jne 0xa9e7
jmp 0xaa49
movq -0x100(%rbp), %rax
movl $0x1, 0x20(%rax)
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0xafc0
movq %rax, -0x170(%rbp)
jmp 0xaa0c
movq -0x170(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0xb030
jmp 0xaa21
movq -0x100(%rbp), %rdi
addq $0x48, %rdi
leaq -0xf8(%rbp), %rsi
callq 0x5510
leaq -0xf8(%rbp), %rdi
callq 0x5768
jmp 0xab11
leaq -0x58(%rbp), %rdi
leaq 0x44e2c(%rip), %rsi     # 0x4f880
callq 0xb090
testb $0x1, %al
jne 0xaa73
leaq -0x58(%rbp), %rdi
leaq 0x44e40(%rip), %rsi     # 0x4f8a8
callq 0xb090
testb $0x1, %al
jne 0xaa73
jmp 0xaa86
movq -0x100(%rbp), %rax
movl $0x3, 0x20(%rax)
jmp 0xab0f
movq 0x4451b(%rip), %rdi     # 0x4efa8
leaq -0x58(%rbp), %rsi
callq 0x53b0
movq %rax, -0x178(%rbp)
jmp 0xaa9f
movq -0x178(%rbp), %rdi
movq 0x444b3(%rip), %rsi     # 0x4ef60
callq 0x5450
jmp 0xaab4
movl $0x10, %edi
callq 0x51d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x180(%rbp)
leaq 0x2a8ea(%rip), %rsi     # 0x353bc
callq 0x5150
jmp 0xaad9
movq -0x180(%rbp), %rdi
movq 0x44501(%rip), %rsi     # 0x4efe8
movq 0x444a2(%rip), %rdx     # 0x4ef90
callq 0x5660
jmp 0xab6f
movq -0x180(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
callq 0x5330
jmp 0xab29
jmp 0xab11
jmp 0xab13
jmp 0xab15
leaq -0x78(%rbp), %rdi
callq 0xb120
leaq -0x58(%rbp), %rdi
callq 0x5768
jmp 0xab4b
leaq -0x78(%rbp), %rdi
callq 0xb120
leaq -0x58(%rbp), %rdi
callq 0x5768
jmp 0xab5d
movq -0x100(%rbp), %rax
movl $0x3, 0x20(%rax)
leaq -0x38(%rbp), %rdi
callq 0xb120
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0xb120
movq -0x10(%rbp), %rdi
callq 0x56a0
nop