// File: /workspace/github_c_makefile_star2_O2/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, 0x26f0(%rip)      # 0x41c8
pushq $0x2c
popq %rsi
movl $0x7b6, %edx            # imm = 0x7B6
callq 0x1130
movl %eax, 0x26a5(%rip)      # 0x4190
cmpl $-0x1, %eax
je 0x1b04
leaq 0x782(%rip), %rdi       # 0x2279
callq 0x1060
movl 0x268e(%rip), %edi      # 0x4190
jmp 0x1b31
leaq 0x791(%rip), %rdi       # 0x229c
callq 0x1060
movl 0x26b2(%rip), %edi      # 0x41c8
pushq $0x2c
popq %rsi
xorl %edx, %edx
callq 0x1130
movl %eax, %edi
movl %eax, 0x2668(%rip)      # 0x4190
cmpl $-0x1, %eax
je 0x1bef
xorl %esi, %esi
xorl %edx, %edx
callq 0x1120
movq %rax, 0x2657(%rip)      # 0x4198
testq %rax, %rax
je 0x1be6
addl $0xeac5, %ebx           # imm = 0xEAC5
movl %ebx, 0x2676(%rip)      # 0x41cc
pushq $0x1
popq %rsi
movl %ebx, %edi
movl $0x7b6, %edx            # imm = 0x7B6
callq 0x1030
movl %eax, 0x2629(%rip)      # 0x4194
cmpl $-0x1, %eax
je 0x1b7e
leaq 0x755(%rip), %rdi       # 0x22cc
callq 0x1060
jmp 0x1ba4
leaq 0x765(%rip), %rdi       # 0x22ea
callq 0x1060
movl 0x263c(%rip), %edi      # 0x41cc
xorl %esi, %esi
xorl %edx, %edx
callq 0x1030
movl %eax, 0x25f5(%rip)      # 0x4194
cmpl $-0x1, %eax
je 0x1bf8
leaq 0x262d(%rip), %rdi      # 0x41d8
leaq -0x553(%rip), %rdx      # 0x165f
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x10e0
leaq 0x261e(%rip), %rdi      # 0x41e0
leaq -0x75d(%rip), %rdx      # 0x146c
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x10e0
movq 0x25ff(%rip), %rdi      # 0x41d8
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1170
leaq 0x4f7(%rip), %rdi       # 0x20e4
jmp 0x1bff
leaq 0x4e7(%rip), %rdi       # 0x20dd
jmp 0x1bff
leaq 0x4eb(%rip), %rdi       # 0x20ea
callq 0x1100
pushq $0x1
popq %rdi
callq 0x1160