// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0xeac4, %rax           # imm = 0xEAC4
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
addq $0xeac4, %rax           # imm = 0xEAC4
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl %eax, 0x33c5(%rip)      # 0x51c8
movl 0x33bf(%rip), %edi      # 0x51c8
movl $0x2c, %esi
movl $0x7b6, %edx            # imm = 0x7B6
callq 0x1130
movl %eax, 0x3372(%rip)      # 0x5190
cmpl $-0x1, %eax
jne 0x1e66
leaq 0x1438(%rip), %rdi      # 0x3262
movb $0x0, %al
callq 0x1090
movl 0x3391(%rip), %edi      # 0x51c8
movl $0x2c, %esi
xorl %edx, %edx
callq 0x1130
movl %eax, 0x3347(%rip)      # 0x5190
cmpl $-0x1, %eax
jne 0x1e64
leaq 0x143e(%rip), %rdi      # 0x3293
callq 0x1100
movl $0x1, %edi
callq 0x1160
jmp 0x1e74
leaq 0x142d(%rip), %rdi      # 0x329a
movb $0x0, %al
callq 0x1090
movl 0x3316(%rip), %edi      # 0x5190
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1120
movq %rax, 0x330c(%rip)      # 0x5198
cmpq $0x0, %rax
jne 0x1ea8
leaq 0x1425(%rip), %rdi      # 0x32be
callq 0x1100
movl $0x1, %edi
callq 0x1160
movl -0x18(%rbp), %eax
movl %eax, 0x331b(%rip)      # 0x51cc
movl 0x3315(%rip), %edi      # 0x51cc
movl $0x1, %esi
movl $0x7b6, %edx            # imm = 0x7B6
callq 0x1030
movl %eax, 0x32c8(%rip)      # 0x5194
cmpl $-0x1, %eax
jne 0x1f11
leaq 0x13ec(%rip), %rdi      # 0x32c4
movb $0x0, %al
callq 0x1090
movl 0x32e7(%rip), %edi      # 0x51cc
xorl %edx, %edx
movl %edx, %esi
callq 0x1030
movl %eax, 0x32a0(%rip)      # 0x5194
cmpl $-0x1, %eax
jne 0x1f0f
leaq 0x13f0(%rip), %rdi      # 0x32f0
callq 0x1100
movl $0x1, %edi
callq 0x1160
jmp 0x1f1f
leaq 0x13df(%rip), %rdi      # 0x32f7
movb $0x0, %al
callq 0x1090
leaq 0x32aa(%rip), %rdi      # 0x51d0
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x755(%rip), %rdx      # 0x17e0
movq %rcx, %rsi
callq 0x10e0
leaq 0x328c(%rip), %rdi      # 0x51d0
addq $0x10, %rdi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x9b3(%rip), %rdx      # 0x15a0
movq %rcx, %rsi
callq 0x10e0
movl $0x1, -0x1c(%rbp)
cmpl $0x2, -0x1c(%rbp)
jge 0x1f8b
movslq -0x1c(%rbp), %rcx
leaq 0x325d(%rip), %rax      # 0x51d0
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1170
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1f62
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)