// File: /workspace/github_cpp_makefile_star2_O3/andersonfernandes[P]sm-chat/src/client.cpp
// Function: select_user(User*)
void select_user(User* user_to_chat) {
  User *users = att_users(users_shmid);
  int *users_count = att_users_count(users_count_shmid);

  if(*users_count == 1) {
    cout << endl << "0 Users online!" << endl;
  } else {
    users = att_users(users_shmid);

    cout << endl << "Online users:" << endl;
    for (int i = 0; i < (*users_count); i++) {
      if (users[i].shmq_id == current_user.shmq_id) continue;
      cout << i << " - " << users[i].name << endl;
    }

    int user_to_chat_index;
    cout << endl << "Select the user to chat: ";
    cin >> user_to_chat_index;

    memcpy(user_to_chat, &users[user_to_chat_index], sizeof(User));
  }

  shmdt(users);
  shmdt(users_count);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movl 0x356b(%rip), %edi      # 0x6154
callq 0x25ec
movq %rax, %r15
movl 0x3561(%rip), %edi      # 0x6158
callq 0x25fa
movq %rax, %rbx
cmpl $0x1, (%rax)
jne 0x2c75
movq 0x33c5(%rip), %r14      # 0x5fd0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq %rax, %r14
leaq 0x1454(%rip), %rsi      # 0x4090
movl $0xf, %edx
movq %rax, %rdi
callq 0x21a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
jmp 0x2e1b
movq %r14, -0x38(%rbp)
movl 0x34d5(%rip), %edi      # 0x6154
callq 0x25ec
movq %rax, -0x30(%rbp)
movq 0x3341(%rip), %r14      # 0x5fd0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq %rax, %r14
leaq 0x13e0(%rip), %rsi      # 0x40a0
movl $0xd, %edx
movq %rax, %rdi
callq 0x21a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movl (%rbx), %eax
testl %eax, %eax
jle 0x2d92
movl 0x3458(%rip), %ecx      # 0x615c
movq -0x30(%rbp), %r13
addq $0x4, %r13
xorl %r12d, %r12d
leaq 0x1398(%rip), %r14      # 0x40ae
cmpl %ecx, -0x4(%r13)
je 0x2d83
movq 0x32ad(%rip), %rdi      # 0x5fd0
movl %r12d, %esi
callq 0x2200
movq %rax, %r15
movl $0x3, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x2070
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x21a0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movl 0x33db(%rip), %ecx      # 0x615c
movl (%rbx), %eax
incq %r12
movslq %eax, %rdx
addq $0x38, %r13
cmpq %rdx, %r12
jl 0x2d16
movq 0x3237(%rip), %r14      # 0x5fd0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x12eb(%rip), %rsi      # 0x40b2
movl $0x19, %edx
movq %rax, %rdi
callq 0x21a0
movq 0x3205(%rip), %rdi      # 0x5fe0
leaq -0x3c(%rbp), %r14
movq %r14, %rsi
callq 0x20c0
movslq (%r14), %rax
imulq $0x38, %rax, %rax
movq -0x30(%rbp), %r15
movq 0x30(%r15,%rax), %rcx
movq -0x38(%rbp), %rdx
movq %rcx, 0x30(%rdx)
movups (%r15,%rax), %xmm0
movups 0x10(%r15,%rax), %xmm1
movups 0x20(%r15,%rax), %xmm2
movups %xmm2, 0x20(%rdx)
movups %xmm1, 0x10(%rdx)
movups %xmm0, (%rdx)
movq %r15, %rdi
callq 0x2230
movq %rbx, %rdi
callq 0x2230
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq