// File: /workspace/github_c_makefile_star2_O1/PARKINHYO[P]BlackjackGame/shm/shm_client.c
// Function: play_game
void* play_game(void * id)
{

  int shmId;
  int semId;
  /*공유메모리와 세마포어의 키값을 클라이언트 ID에 맞춰 생성*/
  shmId = (intptr_t)id + 60100;
  semId = (intptr_t)id+1 +60100;
  keyShm = (key_t)shmId;
  /* 공유 메모리 세그먼트를 연다 - 필요하면 만든다. */
  if( (gnShmID2 = shmget( keyShm, SEGSIZE, IPC_CREAT | IPC_EXCL | 0666 )) == -1 )
  {
          printf("Shared memory segment exist - opening as client\n");
          /* 세그먼트가 이미 존재한다면 - try as a client */
          if( (gnShmID2 = shmget( keyShm, SEGSIZE, 0 )) == -1 )
          {
                  perror("shmget");
                  exit(1);
          }
  }
  else
  {
          printf("Creating new shared memory segment\n");
  }

  /* 현재 프로세스에 공유 메모리 세그먼트를 연결한다. */
  if( (pstShm2 = (_ST_SHM *)shmat(gnShmID2, 0, 0)) == NULL )
  {
          perror("shmat");
          exit(1);
  }

  /* Semapore 키값을 생성한다. */
  keySem = (key_t)semId;

  /* 공유 Semapore 세그먼트를 연다 - 필요하면 만든다. */
  if( (gnSemID2 = semget( keySem, 1, IPC_CREAT | IPC_EXCL | 0666 )) == -1 )
  {
          printf("Semapore segment exist - opening as client\n");
          /* 세그먼트가 이미 존재한다면 - try as a client */
          if( (gnSemID2 = semget( keySem, 0, 0 )) == -1 )
          {
                  perror("semget");
                  exit(1);
          }
  }
  else
  {
          printf("Creating new semapore segment\n");
  }
  /*recv_msg, send_msg 스레드 생성*/
  pthread_create(&threads[1], NULL, recv_msg, NULL);
  pthread_create(&threads[2], NULL, send_msg, NULL);
  int tid;
  /*스레드들 끝날때까지 대기후 삭제*/
  for (tid = 1; tid < 2; ++tid)
    pthread_join(threads[tid], NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
addl $0xeac4, %edi           # imm = 0xEAC4
movl %edi, 0x24cf(%rip)      # 0x41c8
movl $0x2c, %esi
movl $0x7b6, %edx            # imm = 0x7B6
callq 0x1130
movl %eax, 0x2482(%rip)      # 0x4190
cmpl $-0x1, %eax
je 0x1d21
leaq 0x55f(%rip), %rdi       # 0x2279
callq 0x1060
jmp 0x1d4e
leaq 0x574(%rip), %rdi       # 0x229c
callq 0x1060
movl 0x2495(%rip), %edi      # 0x41c8
movl $0x2c, %esi
xorl %edx, %edx
callq 0x1130
movl %eax, 0x244b(%rip)      # 0x4190
cmpl $-0x1, %eax
je 0x1e10
movl 0x243c(%rip), %edi      # 0x4190
xorl %esi, %esi
xorl %edx, %edx
callq 0x1120
movq %rax, 0x2434(%rip)      # 0x4198
testq %rax, %rax
je 0x1e0b
addl $0xeac5, %ebx           # imm = 0xEAC5
movl %ebx, 0x2453(%rip)      # 0x41cc
movl %ebx, %edi
movl $0x1, %esi
movl $0x7b6, %edx            # imm = 0x7B6
callq 0x1030
movl %eax, 0x2404(%rip)      # 0x4194
cmpl $-0x1, %eax
je 0x1da3
leaq 0x530(%rip), %rdi       # 0x22cc
callq 0x1060
jmp 0x1dc9
leaq 0x540(%rip), %rdi       # 0x22ea
callq 0x1060
movl 0x2417(%rip), %edi      # 0x41cc
xorl %esi, %esi
xorl %edx, %edx
callq 0x1030
movl %eax, 0x23d0(%rip)      # 0x4194
cmpl $-0x1, %eax
je 0x1e15
leaq 0x2408(%rip), %rdi      # 0x41d8
leaq -0x665(%rip), %rdx      # 0x1772
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x10e0
leaq 0x23f9(%rip), %rdi      # 0x41e0
leaq -0x888(%rip), %rdx      # 0x1566
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x10e0
movq 0x23da(%rip), %rdi      # 0x41d8
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1170
callq 0x1260
callq 0x1278
callq 0x1248