// File: /workspace/github_c_makefile_star2_O0/PARKINHYO[P]BlackjackGame/shm/shm_server.c
// Function: play_game_one
void* play_game_one(void *data)
{
  int gnShmID2;      /* Shared Memory Indicator */
  int gnSemID2;      /* Semapore Indicator */
  int id = (intptr_t)data;
  int shmId = (intptr_t)data + 60100;
  int semId = (intptr_t)data+1 +60100;
  char buffer[BUFFER_SIZE];
  int nwritten;
  int player_sum, dealer_sum;
  int *player_hand_values = players_hand_values[id], *dealer_hand_values = dealers_hand_values[id];
  int *player_hand_suits = players_hand_suits[id], *dealer_hand_suits = dealers_hand_suits[id];
  int i;

  /* Shared Memory */
  key_t keyShm;       /* Shared Memory Key */
  _ST_SHM *shared_data;      /* 공용 메모리 구조체 */

  /* Semapore */
  key_t keySem;       /* Semapore Key */
  union semun sem_union;
  struct sembuf mysem_open  = {0, -1, SEM_UNDO}; // 세마포어 얻기
  struct sembuf mysem_close = {0, 1, SEM_UNDO};  // 세마포어 돌려주기

  /* Shared Memory의 키값을 생성한다. */
  keyShm = (key_t)shmId;
  /* Semapore 키값을 생성한다. */
  keySem = (key_t)semId;
  /* 공유 메모리 세그먼트를 연다 - 필요하면 만든다. */
  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((shared_data = (_ST_SHM *)shmat(gnShmID2, 0, 0)) == NULL)
  {
    perror("shmat");
    exit(1);
  }
  /* 공유 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");
  }

  /* 공유 메모리 초기화 */
  shared_data->check = 0;
  shared_data->check2 = 0;
  shared_data->finalcheck=0;
  /* Semapore 초기화 */
  sem_union.val = 1;
  semctl( gnSemID2, 0, SETVAL, sem_union );

  /*첫 카드 뽑기*/
  nplayers[id] = 0;
	ndealers[id] = 0;
  /*딜러들의 카드덱은 공유 - mutex로 raceCondition 제어*/
  pthread_mutex_lock(&card_mutex);
	{
		for (i = 0; i < 2; ++i)
		{
			player_hand_values[nplayers[id]] = card_values[ncard];
			player_hand_suits[nplayers[id]] = card_suits[ncard];
			++ncard;
			++nplayers[id];
		}

		dealer_hand_values[ndealers[id]] = card_values[ncard];
		dealer_hand_suits[ndealers[id]] = card_suits[ncard];
		++ncard;
		++ndealers[id];
	}
	pthread_mutex_unlock(&card_mutex);

  buffer[0] = value_codes[player_hand_values[0]];
	buffer[1] = suit_codes[player_hand_suits[0]];
	buffer[2] = value_codes[player_hand_values[1]];
	buffer[3] = suit_codes[player_hand_suits[1]];
	buffer[4] = value_codes[dealer_hand_values[0]];
	buffer[5] = suit_codes[dealer_hand_suits[0]];
	buffer[6] = 0;

  /******* 임계영역 *******/
  if( semop(gnSemID2, &mysem_open, 1) == -1 )
	{
		perror("semop");
		exit(1);
	}
  /* shared memory 전송 */
  strncpy(shared_data->data, buffer, BUFFER_SIZE);
	printf("send: first cardset\n");
  shared_data->check = 1;
  semop(gnSemID2, &mysem_close, 1);
  /******* 임계영역 *******/

  while(shared_data->check) {
     sleep(1);
     printf("waiting...\n");
   }
  /* 첫 카드를 주고서*/
  printf("\n");
  printf("Player %d Hand: ", id );
  display_state(player_hand_values, player_hand_suits, nplayers[id]);
  printf("Dealer Hand with player %d: ", id);
  display_state(dealer_hand_values, dealer_hand_suits, ndealers[id]);

  while(TRUE){
    if(!shared_data->check2){
      if( semop(gnSemID2, &mysem_open, 1) == -1 ) // 대기상태
      {
        perror("semop");
        exit(1);
      }
    }
    /* HIT, STAND signal 빋기*/
    if(!shared_data->check2)
    {
      strncpy(buffer, shared_data->data, BUFFER_SIZE);
      shared_data->check2=1;
      printf("I received from player %d: %s\n", id, buffer);
      strncpy(shared_data->data, "\0", BUFFER_SIZE);

      /* HIT 결과 전송 */

      if (strcmp(buffer, HIT) == 0)
      {
        pthread_mutex_lock(&card_mutex);
        {
          player_hand_values[nplayers[id]] = card_values[ncard];
          player_hand_suits[nplayers[id]] = card_suits[ncard];

          buffer[0] = value_codes[player_hand_values[nplayers[id]]];
          buffer[1] = suit_codes[player_hand_suits[nplayers[id]]];
          buffer[2] = 0;

          ++ncard;
          ++nplayers[id];
        }
        pthread_mutex_unlock(&card_mutex);

        strncpy(shared_data->data, buffer, BUFFER_SIZE);
        printf("I send to player %d: %s\n", id, buffer);
        shared_data->check=2;
        buffer[0] = '\0';
        semop(gnSemID2, &mysem_close, 1);

        /* 플레이어 결과가 21이 넘을 경우*/
        if (calc_sum(player_hand_values, nplayers[id]) > 21)
        {
          printf("Player %d busted. Dealer wins.\n", id);
          break;
        }
        /* 플레이어 결과가 21일 경우 이기기 때문에 break */
        else if (calc_sum(player_hand_values, nplayers[id]) == 21)
          break;
      }
      /* 플레이어의 signal이 STAND인 경우 stop*/
      else if (strcmp(buffer, STAND) == 0){
        //shared_data->finalcheck=1;
        shared_data->check=0;
        semop(gnSemID2, &mysem_close, 1);
        break;
      }
    }
  }
  i=0;
  while (calc_sum(dealer_hand_values, ndealers[id]) < 17)
  {
    dealer_hand_values[ndealers[id]] = card_values[ncard];
    dealer_hand_suits[ndealers[id]] = card_suits[ncard];
    buffer[i++] = value_codes[dealer_hand_values[ndealers[id]]];
    buffer[i++] = suit_codes[dealer_hand_suits[ndealers[id]]];
    ++ncard;
    ++ndealers[id];
  }
  buffer[i] = 0;

  printf("\n");
  printf("Player %d Hand: ", id);
  display_state(player_hand_values, player_hand_suits, nplayers[id]);
  printf("Dealer %d Hand: ", id);
  display_state(dealer_hand_values, dealer_hand_suits, ndealers[id]);

  if( semop(gnSemID2, &mysem_open, 1) == -1 )
  {
          perror("semop");
          exit(1);
  }
  strncpy(shared_data->data, buffer, BUFFER_SIZE);
  shared_data->finalcheck=1;
  semop(gnSemID2, &mysem_close, 1);

  player_sum = calc_sum(player_hand_values, nplayers[id]);
  dealer_sum = calc_sum(dealer_hand_values, ndealers[id]);

  if (dealer_sum > 21)
    printf("\nDealer busted! Player %d wins!\n", id);
  else if (player_sum == dealer_sum)
    printf("\nPlayer %d and dealer have the same score. It's a push!\n", id);
  else if (player_sum < dealer_sum)
    printf("\nDealer has a higher score than player %d. Dealer wins!\n", id);
  else
    printf("\nPlayer %d has a higher score. Player wins!\n", id);


    /* 세마포어, shared memory 제거*/
  if(shmdt(shared_data) == -1) {
     perror("shmdt failed");
     exit(1);
  }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
addq $0xeac4, %rax           # imm = 0xEAC4
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x1, %rax
addq $0xeac4, %rax           # imm = 0xEAC4
movl %eax, -0x24(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x3941(%rip), %rax      # 0x5350
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x3a6b(%rip), %rax      # 0x5490
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x3b95(%rip), %rax      # 0x55d0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x3cbf(%rip), %rax      # 0x5710
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl 0x1908(%rip), %eax      # 0x336a
movl %eax, -0xa6(%rbp)
movw 0x18ff(%rip), %ax       # 0x336e
movw %ax, -0xa2(%rbp)
movl 0x18f4(%rip), %eax      # 0x3370
movl %eax, -0xac(%rbp)
movw 0x18eb(%rip), %ax       # 0x3374
movw %ax, -0xa8(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x88(%rbp), %edi
movl $0x2c, %esi
movl $0x7b6, %edx            # imm = 0x7B6
callq 0x1140
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
jne 0x1aff
leaq 0x1629(%rip), %rdi      # 0x30ef
movb $0x0, %al
callq 0x1080
movl -0x88(%rbp), %edi
movl $0x2c, %esi
xorl %edx, %edx
callq 0x1140
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
jne 0x1afd
leaq 0x1632(%rip), %rdi      # 0x3120
callq 0x1110
movl $0x1, %edi
callq 0x1170
jmp 0x1b0d
leaq 0x1621(%rip), %rdi      # 0x3127
movb $0x0, %al
callq 0x1080
movl -0x14(%rbp), %edi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1130
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
jne 0x1b3e
leaq 0x161c(%rip), %rdi      # 0x314b
callq 0x1110
movl $0x1, %edi
callq 0x1170
movl -0x94(%rbp), %edi
movl $0x1, %esi
movl $0x7b6, %edx            # imm = 0x7B6
callq 0x1030
movl %eax, -0x18(%rbp)
cmpl $-0x1, %eax
jne 0x1b98
leaq 0x15ef(%rip), %rdi      # 0x3151
movb $0x0, %al
callq 0x1080
movl -0x94(%rbp), %edi
xorl %edx, %edx
movl %edx, %esi
callq 0x1030
movl %eax, -0x18(%rbp)
cmpl $-0x1, %eax
jne 0x1b96
leaq 0x15f6(%rip), %rdi      # 0x317d
callq 0x1110
movl $0x1, %edi
callq 0x1170
jmp 0x1ba6
leaq 0x15e5(%rip), %rdi      # 0x3184
movb $0x0, %al
callq 0x1080
movq -0x90(%rbp), %rax
movl $0x0, (%rax)
movq -0x90(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x90(%rbp), %rax
movl $0x0, 0x8(%rax)
movl $0x1, -0xa0(%rbp)
movl -0x18(%rbp), %edi
movq -0xa0(%rbp), %rcx
xorl %esi, %esi
movl $0x10, %edx
movb $0x0, %al
callq 0x1120
movslq -0x1c(%rbp), %rcx
leaq 0x3c54(%rip), %rax      # 0x5850
movl $0x0, (%rax,%rcx,4)
movslq -0x1c(%rbp), %rcx
leaq 0x3c52(%rip), %rax      # 0x5860
movl $0x0, (%rax,%rcx,4)
leaq 0x3c54(%rip), %rdi      # 0x5870
callq 0x11a0
movl $0x0, -0x84(%rbp)
cmpl $0x2, -0x84(%rbp)
jge 0x1cc4
movslq 0x3701(%rip), %rcx      # 0x5340
leaq 0x355a(%rip), %rax      # 0x51a0
movl (%rax,%rcx,4), %edx
movq -0x68(%rbp), %rax
movslq -0x1c(%rbp), %rsi
leaq 0x3bf8(%rip), %rcx      # 0x5850
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movslq 0x36da(%rip), %rcx      # 0x5340
leaq 0x3603(%rip), %rax      # 0x5270
movl (%rax,%rcx,4), %edx
movq -0x78(%rbp), %rax
movslq -0x1c(%rbp), %rsi
leaq 0x3bd1(%rip), %rcx      # 0x5850
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x36b4(%rip), %eax      # 0x5340
addl $0x1, %eax
movl %eax, 0x36ab(%rip)      # 0x5340
movslq -0x1c(%rbp), %rcx
leaq 0x3bb0(%rip), %rax      # 0x5850
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
leaq 0x3ba3(%rip), %rax      # 0x5850
movl %edx, (%rax,%rcx,4)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x1c2b
movslq 0x3675(%rip), %rcx      # 0x5340
leaq 0x34ce(%rip), %rax      # 0x51a0
movl (%rax,%rcx,4), %edx
movq -0x70(%rbp), %rax
movslq -0x1c(%rbp), %rsi
leaq 0x3b7c(%rip), %rcx      # 0x5860
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movslq 0x364e(%rip), %rcx      # 0x5340
leaq 0x3577(%rip), %rax      # 0x5270
movl (%rax,%rcx,4), %edx
movq -0x80(%rbp), %rax
movslq -0x1c(%rbp), %rsi
leaq 0x3b55(%rip), %rcx      # 0x5860
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x3628(%rip), %eax      # 0x5340
addl $0x1, %eax
movl %eax, 0x361f(%rip)      # 0x5340
movslq -0x1c(%rbp), %rcx
leaq 0x3b34(%rip), %rax      # 0x5860
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
leaq 0x3b27(%rip), %rax      # 0x5860
movl %edx, (%rax,%rcx,4)
leaq 0x3b2d(%rip), %rdi      # 0x5870
callq 0x10e0
movq -0x68(%rbp), %rax
movslq (%rax), %rcx
leaq 0x15fa(%rip), %rax      # 0x3350
movb (%rax,%rcx), %al
movb %al, -0x50(%rbp)
movq -0x78(%rbp), %rax
movslq (%rax), %rcx
leaq 0x15e2(%rip), %rax      # 0x334c
movb (%rax,%rcx), %al
movb %al, -0x4f(%rbp)
movq -0x68(%rbp), %rax
movslq 0x4(%rax), %rcx
leaq 0x15d1(%rip), %rax      # 0x3350
movb (%rax,%rcx), %al
movb %al, -0x4e(%rbp)
movq -0x78(%rbp), %rax
movslq 0x4(%rax), %rcx
leaq 0x15b8(%rip), %rax      # 0x334c
movb (%rax,%rcx), %al
movb %al, -0x4d(%rbp)
movq -0x70(%rbp), %rax
movslq (%rax), %rcx
leaq 0x15a8(%rip), %rax      # 0x3350
movb (%rax,%rcx), %al
movb %al, -0x4c(%rbp)
movq -0x80(%rbp), %rax
movslq (%rax), %rcx
leaq 0x1590(%rip), %rax      # 0x334c
movb (%rax,%rcx), %al
movb %al, -0x4b(%rbp)
movb $0x0, -0x4a(%rbp)
movl -0x18(%rbp), %edi
leaq -0xa6(%rbp), %rsi
movl $0x1, %edx
callq 0x1150
cmpl $-0x1, %eax
jne 0x1df5
leaq 0x13c3(%rip), %rdi      # 0x31a9
callq 0x1110
movl $0x1, %edi
callq 0x1170
movq -0x90(%rbp), %rdi
addq $0xc, %rdi
leaq -0x50(%rbp), %rsi
movl $0x20, %edx
callq 0x1040
leaq 0x13a7(%rip), %rdi      # 0x31bc
movb $0x0, %al
callq 0x1080
movq -0x90(%rbp), %rax
movl $0x1, (%rax)
movl -0x18(%rbp), %edi
leaq -0xac(%rbp), %rsi
movl $0x1, %edx
callq 0x1150
movq -0x90(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1e63
movl $0x1, %edi
callq 0x1190
leaq 0x1377(%rip), %rdi      # 0x31d1
movb $0x0, %al
callq 0x1080
jmp 0x1e3d
leaq 0x146c(%rip), %rdi      # 0x32d6
movb $0x0, %al
callq 0x1080
movl -0x1c(%rbp), %esi
leaq 0x1362(%rip), %rdi      # 0x31dd
movb $0x0, %al
callq 0x1080
movq -0x68(%rbp), %rdi
movq -0x78(%rbp), %rsi
movslq -0x1c(%rbp), %rcx
leaq 0x39bb(%rip), %rax      # 0x5850
movl (%rax,%rcx,4), %edx
callq 0x1460
movl -0x1c(%rbp), %esi
leaq 0x1347(%rip), %rdi      # 0x31ee
movb $0x0, %al
callq 0x1080
movq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rsi
movslq -0x1c(%rbp), %rcx
leaq 0x399f(%rip), %rax      # 0x5860
movl (%rax,%rcx,4), %edx
callq 0x1460
movq -0x90(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x1f07
movl -0x18(%rbp), %edi
leaq -0xa6(%rbp), %rsi
movl $0x1, %edx
callq 0x1150
cmpl $-0x1, %eax
jne 0x1f05
leaq 0x12b3(%rip), %rdi      # 0x31a9
callq 0x1110
movl $0x1, %edi
callq 0x1170
jmp 0x1f07
movq -0x90(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x2145
leaq -0x50(%rbp), %rdi
movq -0x90(%rbp), %rsi
addq $0xc, %rsi
movl $0x20, %edx
callq 0x1040
movq -0x90(%rbp), %rax
movl $0x1, 0x4(%rax)
movl -0x1c(%rbp), %esi
leaq -0x50(%rbp), %rdx
leaq 0x12be(%rip), %rdi      # 0x320b
movb $0x0, %al
callq 0x1080
movq -0x90(%rbp), %rdi
addq $0xc, %rdi
leaq 0x1410(%rip), %rsi      # 0x3376
movl $0x20, %edx
callq 0x1040
leaq -0x50(%rbp), %rdi
leaq 0x12af(%rip), %rsi      # 0x322a
callq 0x10a0
cmpl $0x0, %eax
jne 0x2109
leaq 0x38e0(%rip), %rdi      # 0x5870
callq 0x11a0
movslq 0x33a4(%rip), %rcx      # 0x5340
leaq 0x31fd(%rip), %rax      # 0x51a0
movl (%rax,%rcx,4), %edx
movq -0x68(%rbp), %rax
movslq -0x1c(%rbp), %rsi
leaq 0x389b(%rip), %rcx      # 0x5850
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movslq 0x337d(%rip), %rcx      # 0x5340
leaq 0x32a6(%rip), %rax      # 0x5270
movl (%rax,%rcx,4), %edx
movq -0x78(%rbp), %rax
movslq -0x1c(%rbp), %rsi
leaq 0x3874(%rip), %rcx      # 0x5850
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x68(%rbp), %rax
movslq -0x1c(%rbp), %rdx
leaq 0x385e(%rip), %rcx      # 0x5850
movslq (%rcx,%rdx,4), %rcx
movslq (%rax,%rcx,4), %rcx
leaq 0x134f(%rip), %rax      # 0x3350
movb (%rax,%rcx), %al
movb %al, -0x50(%rbp)
movq -0x78(%rbp), %rax
movslq -0x1c(%rbp), %rdx
leaq 0x383a(%rip), %rcx      # 0x5850
movslq (%rcx,%rdx,4), %rcx
movslq (%rax,%rcx,4), %rcx
leaq 0x1327(%rip), %rax      # 0x334c
movb (%rax,%rcx), %al
movb %al, -0x4f(%rbp)
movb $0x0, -0x4e(%rbp)
movl 0x330b(%rip), %eax      # 0x5340
addl $0x1, %eax
movl %eax, 0x3302(%rip)      # 0x5340
movslq -0x1c(%rbp), %rcx
leaq 0x3807(%rip), %rax      # 0x5850
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
leaq 0x37fa(%rip), %rax      # 0x5850
movl %edx, (%rax,%rcx,4)
leaq 0x3810(%rip), %rdi      # 0x5870
callq 0x10e0
movq -0x90(%rbp), %rdi
addq $0xc, %rdi
leaq -0x50(%rbp), %rsi
movl $0x20, %edx
callq 0x1040
movl -0x1c(%rbp), %esi
leaq -0x50(%rbp), %rdx
leaq 0x11a2(%rip), %rdi      # 0x322e
movb $0x0, %al
callq 0x1080
movq -0x90(%rbp), %rax
movl $0x2, (%rax)
movb $0x0, -0x50(%rbp)
movl -0x18(%rbp), %edi
leaq -0xac(%rbp), %rsi
movl $0x1, %edx
callq 0x1150
movq -0x68(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x3789(%rip), %rax      # 0x5850
movl (%rax,%rcx,4), %esi
callq 0x13c0
cmpl $0x15, %eax
jle 0x20e7
movl -0x1c(%rbp), %esi
leaq 0x1169(%rip), %rdi      # 0x3247
movb $0x0, %al
callq 0x1080
jmp 0x214a
movq -0x68(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x375a(%rip), %rax      # 0x5850
movl (%rax,%rcx,4), %esi
callq 0x13c0
cmpl $0x15, %eax
jne 0x2105
jmp 0x214a
jmp 0x2107
jmp 0x2143
leaq -0x50(%rbp), %rdi
leaq 0x1153(%rip), %rsi      # 0x3267
callq 0x10a0
cmpl $0x0, %eax
jne 0x2141
movq -0x90(%rbp), %rax
movl $0x0, (%rax)
movl -0x18(%rbp), %edi
leaq -0xac(%rbp), %rsi
movl $0x1, %edx
callq 0x1150
jmp 0x214a
jmp 0x2143
jmp 0x2145
jmp 0x1ec9
movl $0x0, -0x84(%rbp)
movq -0x70(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x36fd(%rip), %rax      # 0x5860
movl (%rax,%rcx,4), %esi
callq 0x13c0
cmpl $0x11, %eax
jge 0x2261
movslq 0x31c5(%rip), %rcx      # 0x5340
leaq 0x301e(%rip), %rax      # 0x51a0
movl (%rax,%rcx,4), %edx
movq -0x70(%rbp), %rax
movslq -0x1c(%rbp), %rsi
leaq 0x36cc(%rip), %rcx      # 0x5860
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movslq 0x319e(%rip), %rcx      # 0x5340
leaq 0x30c7(%rip), %rax      # 0x5270
movl (%rax,%rcx,4), %edx
movq -0x80(%rbp), %rax
movslq -0x1c(%rbp), %rsi
leaq 0x36a5(%rip), %rcx      # 0x5860
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x70(%rbp), %rax
movslq -0x1c(%rbp), %rdx
leaq 0x368f(%rip), %rcx      # 0x5860
movslq (%rcx,%rdx,4), %rcx
movslq (%rax,%rcx,4), %rcx
leaq 0x1170(%rip), %rax      # 0x3350
movb (%rax,%rcx), %cl
movl -0x84(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x84(%rbp)
cltq
movb %cl, -0x50(%rbp,%rax)
movq -0x80(%rbp), %rax
movslq -0x1c(%rbp), %rdx
leaq 0x3657(%rip), %rcx      # 0x5860
movslq (%rcx,%rdx,4), %rcx
movslq (%rax,%rcx,4), %rcx
leaq 0x1134(%rip), %rax      # 0x334c
movb (%rax,%rcx), %cl
movl -0x84(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x84(%rbp)
cltq
movb %cl, -0x50(%rbp,%rax)
movl 0x3108(%rip), %eax      # 0x5340
addl $0x1, %eax
movl %eax, 0x30ff(%rip)      # 0x5340
movslq -0x1c(%rbp), %rcx
leaq 0x3614(%rip), %rax      # 0x5860
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
leaq 0x3607(%rip), %rax      # 0x5860
movl %edx, (%rax,%rcx,4)
jmp 0x2154
movslq -0x84(%rbp), %rax
movb $0x0, -0x50(%rbp,%rax)
leaq 0x1062(%rip), %rdi      # 0x32d6
movb $0x0, %al
callq 0x1080
movl -0x1c(%rbp), %esi
leaq 0xf58(%rip), %rdi       # 0x31dd
movb $0x0, %al
callq 0x1080
movq -0x68(%rbp), %rdi
movq -0x78(%rbp), %rsi
movslq -0x1c(%rbp), %rcx
leaq 0x35b1(%rip), %rax      # 0x5850
movl (%rax,%rcx,4), %edx
callq 0x1460
movl -0x1c(%rbp), %esi
leaq 0xfbc(%rip), %rdi       # 0x326d
movb $0x0, %al
callq 0x1080
movq -0x70(%rbp), %rdi
movq -0x80(%rbp), %rsi
movslq -0x1c(%rbp), %rcx
leaq 0x3595(%rip), %rax      # 0x5860
movl (%rax,%rcx,4), %edx
callq 0x1460
movl -0x18(%rbp), %edi
leaq -0xa6(%rbp), %rsi
movl $0x1, %edx
callq 0x1150
cmpl $-0x1, %eax
jne 0x2302
leaq 0xeb6(%rip), %rdi       # 0x31a9
callq 0x1110
movl $0x1, %edi
callq 0x1170
movq -0x90(%rbp), %rdi
addq $0xc, %rdi
leaq -0x50(%rbp), %rsi
movl $0x20, %edx
callq 0x1040
movq -0x90(%rbp), %rax
movl $0x1, 0x8(%rax)
movl -0x18(%rbp), %edi
leaq -0xac(%rbp), %rsi
movl $0x1, %edx
callq 0x1150
movq -0x68(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x3504(%rip), %rax      # 0x5850
movl (%rax,%rcx,4), %esi
callq 0x13c0
movl %eax, -0x58(%rbp)
movq -0x70(%rbp), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x34fa(%rip), %rax      # 0x5860
movl (%rax,%rcx,4), %esi
callq 0x13c0
movl %eax, -0x5c(%rbp)
cmpl $0x15, -0x5c(%rbp)
jle 0x238a
movl -0x1c(%rbp), %esi
leaq 0xefd(%rip), %rdi       # 0x327e
movb $0x0, %al
callq 0x1080
jmp 0x23d5
movl -0x58(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jne 0x23a5
movl -0x1c(%rbp), %esi
leaq 0xf03(%rip), %rdi       # 0x329f
movb $0x0, %al
callq 0x1080
jmp 0x23d3
movl -0x58(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x23c0
movl -0x1c(%rbp), %esi
leaq 0xf21(%rip), %rdi       # 0x32d8
movb $0x0, %al
callq 0x1080
jmp 0x23d1
movl -0x1c(%rbp), %esi
leaq 0xf47(%rip), %rdi       # 0x3311
movb $0x0, %al
callq 0x1080
jmp 0x23d3
jmp 0x23d5
movq -0x90(%rbp), %rdi
callq 0x1070
cmpl $-0x1, %eax
jne 0x23fc
leaq 0xf51(%rip), %rdi       # 0x333e
callq 0x1110
movl $0x1, %edi
callq 0x1170
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq