// File: /workspace/github_cpp_makefile_star2_O2/andersonfernandes[P]sm-chat/src/client.cpp
// Function: send_messages()
void send_messages() {
  while(true) {
    char text[200];
    cin.getline(text, 200);

    Message* message = new Message();
    strcpy(message->source_name, current_user.name);
    strcpy(message->text, text);

    if(strcmp(text, ":q") == 0) break;
    else if(strlen(message->text) != 0) {
      char message_mode = 'B';
      cout << endl << "Select the message mode ([U]nicast or [B]roadcast): ";
      cin >> message_mode;

      if(message_mode == 'U' || message_mode == 'u') {
        User* user_to_chat = new User();
        select_user(user_to_chat);

        message->mode = UNICAST;
        message->sent_at = time(0);

        ShmQueue* shmq = att_shmq(user_to_chat->shmq_id);
        enqueue(shmq, message);
        shmdt(shmq);
      } else {
        message->mode = BROADCAST;
        message->sent_at = time(0);

        User *users = att_users(users_shmid);
        int *users_count = att_users_count(users_count_shmid);

        for (int i = 0; i < *users_count; i++) {
          if (users[i].shmq_id == current_user.shmq_id) continue;

          ShmQueue* shmq = att_shmq(users[i].shmq_id);
          enqueue(shmq, message);
          shmdt(shmq);
        }

        shmdt(users);
        shmdt(users_count);
      }
    }

    cout << endl;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq 0x27ef(%rip), %r14      # 0x4fe0
leaq -0x100(%rbp), %r15
leaq 0x2941(%rip), %r13      # 0x5140
movl $0xc8, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2050
movl $0x108, %edi            # imm = 0x108
callq 0x2160
movq %rax, %r12
movl $0x108, %edx            # imm = 0x108
movq %rax, %rdi
xorl %esi, %esi
callq 0x2090
movq %r12, %rdi
movq %r13, %rsi
callq 0x2120
leaq 0x32(%r12), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2120
movq %r15, %rdi
leaq 0x808(%rip), %rsi       # 0x3058
pushq $0x3
popq %rdx
callq 0x2170
testl %eax, %eax
je 0x29a7
cmpb $0x0, (%rbx)
je 0x2996
movb $0x42, -0x29(%rbp)
movq 0x275c(%rip), %rdi      # 0x4fd0
callq 0x2080
movq %rax, %rdi
leaq 0x849(%rip), %rsi       # 0x30cc
callq 0x2150
movq %r14, %rdi
leaq -0x29(%rbp), %rsi
callq 0x21a0
movb -0x29(%rbp), %al
andb $-0x21, %al
cmpb $0x55, %al
jne 0x28fd
pushq $0x38
popq %rdi
callq 0x2160
movq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, 0x20(%rax)
andq $0x0, 0x30(%rax)
movq %rax, %rdi
callq 0x2a03
movb $0x55, 0xfa(%r12)
xorl %edi, %edi
callq 0x2110
movq %rax, 0x100(%r12)
movl (%rbx), %edi
callq 0x2550
movq %rax, %rbx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2472
movq %rbx, %rdi
callq 0x2200
jmp 0x2996
movb $0x42, 0xfa(%r12)
xorl %edi, %edi
callq 0x2110
movq %rax, 0x100(%r12)
movl 0x2819(%rip), %edi      # 0x5134
callq 0x2560
movq %rax, %r13
movl 0x280f(%rip), %edi      # 0x5138
callq 0x256e
movq %rax, %rbx
movq %r13, -0x38(%rbp)
xorl %r14d, %r14d
movslq (%rbx), %rax
cmpq %rax, %r14
jge 0x2970
movl (%r13), %edi
cmpl 0x27f2(%rip), %edi      # 0x513c
je 0x2967
callq 0x2550
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
callq 0x2472
movq %r15, %rdi
callq 0x2200
incq %r14
addq $0x38, %r13
jmp 0x2938
movq -0x38(%rbp), %rdi
callq 0x2200
movq %rbx, %rdi
callq 0x2200
movq 0x2658(%rip), %r14      # 0x4fe0
leaq -0x100(%rbp), %r15
leaq 0x27aa(%rip), %r13      # 0x5140
movq 0x2633(%rip), %rdi      # 0x4fd0
callq 0x2080
jmp 0x27ff
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq