// File: /workspace/github_cpp_makefile_star2_O1/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 0x3560(%rip), %edi      # 0x6154
callq 0x25f0
movq %rax, %r15
movl 0x3556(%rip), %edi      # 0x6158
callq 0x25fe
movq %rax, %rbx
cmpl $0x1, (%rax)
jne 0x2c80
movq 0x33ba(%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 0x1449(%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 0x2e1d
movq %r14, -0x38(%rbp)
movl 0x34ca(%rip), %edi      # 0x6154
callq 0x25f0
movq %rax, -0x30(%rbp)
movq 0x3336(%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 0x13d5(%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
cmpl $0x0, (%rbx)
jle 0x2d94
movq -0x30(%rbp), %r13
addq $0x4, %r13
xorl %r12d, %r12d
leaq 0x1394(%rip), %r14      # 0x40ae
movl -0x4(%r13), %eax
cmpl 0x3438(%rip), %eax      # 0x615c
je 0x2d85
movq 0x32a3(%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
incq %r12
movslq (%rbx), %rax
addq $0x38, %r13
cmpq %rax, %r12
jl 0x2d1a
movq 0x3235(%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 0x12e9(%rip), %rsi      # 0x40b2
movl $0x19, %edx
movq %rax, %rdi
callq 0x21a0
movq 0x3203(%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