// File: /workspace/github_c_makefile_star2_O2/PARKINHYO[P]BlackjackGame/shm/shm_client.c
// Function: send_msg
void* send_msg(void *x)
{
  //sleep(0.2);
  int choice;
  char strChoice[10];
  while(1){
    /* 게임 종료시그널을 받으면 전송 스레드도 종료*/
    if(pstShm2->finalcheck){break;}

    /*HIT STAND를 보내야 할 상황일 때*/
    if(pstShm2->check2){
      printf("\n");
      printf("1. Hit\n");
      printf("2. Stand\n");
      printf("Please choose 1 or 2: ");
      fflush(stdout);

      /*문자열 제한 get*/
      fgets(strChoice, sizeof(strChoice), stdin);
      choice = atoi(strChoice);
      /*HIT을 선택할 경우*/
      if (choice == 1)
      {
        /*임계영역*/
        if( semop(gnSemID2, &mysem_open, 1) == -1 )
        {
              perror("semop");
              exit(1);
        }
        strcpy(buffer, HIT);
        printf("Sending: %s\n", buffer);
        /* HIT send */
        strncpy(pstShm2->data, buffer, BUFFER_SIZE);
        pstShm2->check2 = 0;
        semop(gnSemID2, &mysem_close, 1);
        /*임계영역*/
        sleep(1);
      }
      /*STAND를 선택한 경우*/
      else if (choice == 2)
      {
        /*임계영역*/
        if( semop(gnSemID2, &mysem_open, 1) == -1 )
        {
              perror("semop");
              exit(1);
        }
        strcpy(buffer, STAND);
        printf("Sending: %s\n", buffer);
        strncpy(pstShm2->data, buffer, BUFFER_SIZE);
        pstShm2->check2 = 0;
        pstShm2->check = 0;
        semop(gnSemID2, &mysem_close, 1);
        /*임계영역*/
        break;
      }
      else
        printf("Unrecognized choice. Choose again.\n");
      /*문자열 초기화*/
      strChoice[strlen(strChoice)-1] = '\0';
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
pushq $0xa
popq %rbx
leaq 0xd07(%rip), %r14       # 0x218e
leaq 0xbdb(%rip), %r15       # 0x2069
movq 0x2b3b(%rip), %r13      # 0x3fd0
movq 0x2cfc(%rip), %rax      # 0x4198
cmpl $0x0, 0x8(%rax)
jne 0x163c
cmpl $0x0, 0x4(%rax)
je 0x1495
movl %ebx, %edi
callq 0x1040
leaq 0xccd(%rip), %rdi       # 0x2187
callq 0x1060
movq %r14, %rdi
callq 0x1060
movq %r15, %rdi
xorl %eax, %eax
callq 0x1090
movq (%r13), %rdi
callq 0x10d0
movq 0x2af7(%rip), %rax      # 0x3fd8
movq (%rax), %rdx
leaq -0x32(%rbp), %r12
movq %r12, %rdi
movl %ebx, %esi
callq 0x10a0
movq %r12, %rdi
callq 0x1140
cmpl $0x1, %eax
je 0x1519
cmpl $0x2, %eax
je 0x15c8
leaq 0xc88(%rip), %rdi       # 0x2197
callq 0x1060
jmp 0x15b1
movl %ebx, %r13d
movq %r15, %rbx
movq %r14, %r15
movl 0x2c6c(%rip), %edi      # 0x4194
leaq 0x2c41(%rip), %rsi      # 0x4170
pushq $0x1
popq %r14
movq %r14, %rdx
callq 0x1150
cmpl $-0x1, %eax
je 0x164b
movl $0x544948, 0x2c52(%rip) # imm = 0x544948
leaq 0xb31(%rip), %rdi       # 0x2086
leaq 0x2c44(%rip), %rsi      # 0x41a0
xorl %eax, %eax
callq 0x1090
movq 0x2c2e(%rip), %r12      # 0x4198
leaq 0xc(%r12), %rdi
leaq 0x2c2a(%rip), %rsi      # 0x41a0
pushq $0x20
popq %rdx
callq 0x1050
andl $0x0, 0x4(%r12)
movl 0x2c0a(%rip), %edi      # 0x4194
leaq 0x2be5(%rip), %rsi      # 0x4176
movq %r14, %rdx
callq 0x1150
pushq $0x1
popq %rdi
callq 0x1180
movq %r15, %r14
movq %rbx, %r15
movl %r13d, %ebx
movq 0x2a1f(%rip), %r13      # 0x3fd0
leaq -0x32(%rbp), %r12
movq %r12, %rdi
callq 0x1080
movb $0x0, -0x1(%rax,%r12)
jmp 0x1495
movl 0x2bc6(%rip), %edi      # 0x4194
leaq 0x2b9b(%rip), %rsi      # 0x4170
pushq $0x1
popq %rdx
callq 0x1150
cmpl $-0x1, %eax
je 0x164b
movw $0x44, 0x2bb9(%rip)     # 0x41a4
movl $0x4e415453, 0x2bab(%rip) # imm = 0x4E415453
leaq 0x2ba4(%rip), %rbx      # 0x41a0
leaq 0xa83(%rip), %rdi       # 0x2086
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1090
movq 0x2b84(%rip), %r14      # 0x4198
leaq 0xc(%r14), %rdi
pushq $0x20
popq %rdx
movq %rbx, %rsi
callq 0x1050
andq $0x0, (%r14)
movl 0x2b67(%rip), %edi      # 0x4194
leaq 0x2b42(%rip), %rsi      # 0x4176
pushq $0x1
popq %rdx
callq 0x1150
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa2e(%rip), %rdi       # 0x2080
callq 0x1100
pushq $0x1
popq %rdi
callq 0x1160