// File: /workspace/github_c_makefile_star2_O0/PARKINHYO[P]BlackjackGame/mqueue/mqueue_client.c
// Function: recv_msg
void* recv_msg() {
	msg buf;
	buf.type = pid;

	char buffer[BUFFER_SIZE];

	check =1;
	int my_hand_values[20], dealer_hand_values[20];
	int my_hand_suits[20], dealer_hand_suits[20];
	int nmy = 0, ndealer = 0;
	buf.type = pid;

	while (1) {
		if(check == 1){

			printf("pid: %d\n\n", pid);
			msgrcv(msgid_Recv_Main, (void*)&buf, sizeof(msg), pid, 0);
			strncpy(buffer, buf.data, BUFFER_SIZE);
			printf("%s\n", buffer);

			my_hand_values[0] = get_value_id(buffer[0]);
			my_hand_suits[0] = get_suit_id(buffer[1]);
			my_hand_values[1] = get_value_id(buffer[2]);
			my_hand_suits[1] = get_suit_id(buffer[3]);
			dealer_hand_values[0] = get_value_id(buffer[4]);
			dealer_hand_suits[0] = get_suit_id(buffer[5]);
			nmy = 2;
			ndealer = 1;

			my_sum = calc_sum(my_hand_values, nmy);

			printf("\n");
			// 카드덱과 합산값 화면출력
			printf("My Hand: ");
			display_state(my_hand_values, my_hand_suits, nmy);
			printf("Dealer Hand: ");
			display_state(dealer_hand_values, dealer_hand_suits, ndealer);

			if (my_sum > 21)
			{
				printf("\nI'm busted! I lose!\n");
				return 0;
			}

			check = 0;
			check2 = 1;
			buffer[0]='\0';
		}
		if(check2 == 2){
			printf("buffer: %s\n", buffer);
			msgrcv(msgid_Recv_Main, (void*)&buf, sizeof(msg), pid, 0);
			printf("buf.data: %s\n", buf.data);
			strncpy(buffer, buf.data, BUFFER_SIZE);
			printf("I received: %s\n", buffer);
			my_hand_values[nmy] = get_value_id(buffer[0]);
			my_hand_suits[nmy] = get_suit_id(buffer[1]);
			++nmy;

			printf("\n");
			printf("My Hand: ");
			display_state(my_hand_values, my_hand_suits, nmy);
			printf("Dealer Hand: ");
			display_state(dealer_hand_values, dealer_hand_suits, ndealer);
			my_sum = calc_sum(my_hand_values, nmy);
			if(my_sum>21){
				printf("\nI'm busted! I lose!\n");
				return 0;
			}

			check2 = 1;
		}

		if(finalcheck == 1){
			finalcheck = 0;
			unsigned i;
			msgrcv(msgid_Recv_Main, (void*)&buf, sizeof(msg), pid, 0);
			strncpy(buffer, buf.data, BUFFER_SIZE);

			printf("I received: %s\n", buffer);

			for (i = 0; i < strlen(buffer); i += 2)
			{
				dealer_hand_values[ndealer] = get_value_id(buffer[i]);
				dealer_hand_suits[ndealer] = get_suit_id(buffer[i + 1]);
				++ndealer;
			}

			printf("\n");
			printf("My Hand: ");
			display_state(my_hand_values, my_hand_suits, nmy);
			printf("Dealer Hand: ");
			display_state(dealer_hand_values, dealer_hand_suits, ndealer);

			my_sum = calc_sum(my_hand_values, nmy);
			dealer_sum = calc_sum(dealer_hand_values, ndealer);

			if (dealer_sum > 21)
				printf("\nDealer busted! I win!\n");
			else if (my_sum == dealer_sum)
				printf("\nMe and the dealer have the same score. It's a push!\n");
			else if (my_sum < dealer_sum)
				printf("\nDealer has a higher score. I lose!\n");
			else
				printf("\nI have a higher score. I win!\n");

			return 0;

		}
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movslq 0x2aa2(%rip), %rax      # 0x4174
movq %rax, -0x30(%rbp)
movl $0x1, 0x2a80(%rip)      # 0x4160
movl $0x0, -0x194(%rbp)
movl $0x0, -0x198(%rbp)
movslq 0x2a79(%rip), %rax      # 0x4174
movq %rax, -0x30(%rbp)
cmpl $0x1, 0x2a5a(%rip)      # 0x4160
jne 0x1884
movl 0x2a62(%rip), %esi      # 0x4174
leaq 0xa0a(%rip), %rdi       # 0x2123
movb $0x0, %al
callq 0x1090
movl 0x2a4a(%rip), %edi      # 0x4170
movslq 0x2a47(%rip), %rcx      # 0x4174
leaq -0x30(%rbp), %rsi
movl $0x28, %edx
xorl %r8d, %r8d
callq 0x1150
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
addq $0x8, %rsi
movl $0x20, %edx
callq 0x1040
leaq -0x50(%rbp), %rsi
leaq 0xa12(%rip), %rdi       # 0x2171
movb $0x0, %al
callq 0x1090
movsbl -0x50(%rbp), %edi
callq 0x1300
movl %eax, -0xa0(%rbp)
movsbl -0x4f(%rbp), %edi
callq 0x12a0
movl %eax, -0x140(%rbp)
movsbl -0x4e(%rbp), %edi
callq 0x1300
movl %eax, -0x9c(%rbp)
movsbl -0x4d(%rbp), %edi
callq 0x12a0
movl %eax, -0x13c(%rbp)
movsbl -0x4c(%rbp), %edi
callq 0x1300
movl %eax, -0xf0(%rbp)
movsbl -0x4b(%rbp), %edi
callq 0x12a0
movl %eax, -0x190(%rbp)
movl $0x2, -0x194(%rbp)
movl $0x1, -0x198(%rbp)
leaq -0xa0(%rbp), %rdi
movl -0x194(%rbp), %esi
callq 0x1360
movl %eax, 0x298c(%rip)      # 0x4178
leaq 0x938(%rip), %rdi       # 0x212b
movb $0x0, %al
callq 0x1090
leaq 0x92c(%rip), %rdi       # 0x212d
movb $0x0, %al
callq 0x1090
leaq -0xa0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
movl -0x194(%rbp), %edx
callq 0x1400
leaq 0x90f(%rip), %rdi       # 0x2137
movb $0x0, %al
callq 0x1090
leaq -0xf0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
movl -0x198(%rbp), %edx
callq 0x1400
cmpl $0x15, 0x2929(%rip)     # 0x4178
jle 0x186c
leaq 0x8ed(%rip), %rdi       # 0x2145
movb $0x0, %al
callq 0x1090
movq $0x0, -0x8(%rbp)
jmp 0x1bd8
movl $0x0, 0x28ea(%rip)      # 0x4160
movl $0x1, 0x28e4(%rip)      # 0x4164
movb $0x0, -0x50(%rbp)
cmpl $0x2, 0x28d9(%rip)      # 0x4164
jne 0x19e2
leaq -0x50(%rbp), %rsi
leaq 0x8bf(%rip), %rdi       # 0x215b
movb $0x0, %al
callq 0x1090
movl 0x28c7(%rip), %edi      # 0x4170
movslq 0x28c4(%rip), %rcx      # 0x4174
leaq -0x30(%rbp), %rsi
movl $0x28, %edx
xorl %r8d, %r8d
callq 0x1150
leaq -0x30(%rbp), %rsi
addq $0x8, %rsi
leaq 0x897(%rip), %rdi       # 0x2167
movb $0x0, %al
callq 0x1090
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
addq $0x8, %rsi
movl $0x20, %edx
callq 0x1040
leaq -0x50(%rbp), %rsi
leaq 0x87d(%rip), %rdi       # 0x2175
movb $0x0, %al
callq 0x1090
movsbl -0x50(%rbp), %edi
callq 0x1300
movl %eax, %ecx
movslq -0x194(%rbp), %rax
movl %ecx, -0xa0(%rbp,%rax,4)
movsbl -0x4f(%rbp), %edi
callq 0x12a0
movl %eax, %ecx
movslq -0x194(%rbp), %rax
movl %ecx, -0x140(%rbp,%rax,4)
movl -0x194(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x194(%rbp)
leaq 0x7e4(%rip), %rdi       # 0x212b
movb $0x0, %al
callq 0x1090
leaq 0x7d8(%rip), %rdi       # 0x212d
movb $0x0, %al
callq 0x1090
leaq -0xa0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
movl -0x194(%rbp), %edx
callq 0x1400
leaq 0x7bb(%rip), %rdi       # 0x2137
movb $0x0, %al
callq 0x1090
leaq -0xf0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
movl -0x198(%rbp), %edx
callq 0x1400
leaq -0xa0(%rbp), %rdi
movl -0x194(%rbp), %esi
callq 0x1360
movl %eax, 0x27c4(%rip)      # 0x4178
cmpl $0x15, 0x27bd(%rip)     # 0x4178
jle 0x19d8
leaq 0x781(%rip), %rdi       # 0x2145
movb $0x0, %al
callq 0x1090
movq $0x0, -0x8(%rbp)
jmp 0x1bd8
movl $0x1, 0x2782(%rip)      # 0x4164
cmpl $0x1, 0x277f(%rip)      # 0x4168
jne 0x1bd3
movl $0x0, 0x276f(%rip)      # 0x4168
movl 0x2771(%rip), %edi      # 0x4170
movslq 0x276e(%rip), %rcx      # 0x4174
leaq -0x30(%rbp), %rsi
movl $0x28, %edx
xorl %r8d, %r8d
callq 0x1150
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
addq $0x8, %rsi
movl $0x20, %edx
callq 0x1040
leaq -0x50(%rbp), %rsi
leaq 0x73d(%rip), %rdi       # 0x2175
movb $0x0, %al
callq 0x1090
movl $0x0, -0x19c(%rbp)
movl -0x19c(%rbp), %eax
movq %rax, -0x1a8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x1080
movq %rax, %rcx
movq -0x1a8(%rbp), %rax
cmpq %rcx, %rax
jae 0x1ad6
movl -0x19c(%rbp), %eax
movsbl -0x50(%rbp,%rax), %edi
callq 0x1300
movl %eax, %ecx
movslq -0x198(%rbp), %rax
movl %ecx, -0xf0(%rbp,%rax,4)
movl -0x19c(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movsbl -0x50(%rbp,%rax), %edi
callq 0x12a0
movl %eax, %ecx
movslq -0x198(%rbp), %rax
movl %ecx, -0x190(%rbp,%rax,4)
movl -0x198(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x198(%rbp)
movl -0x19c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x19c(%rbp)
jmp 0x1a49
leaq 0x64e(%rip), %rdi       # 0x212b
movb $0x0, %al
callq 0x1090
leaq 0x642(%rip), %rdi       # 0x212d
movb $0x0, %al
callq 0x1090
leaq -0xa0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
movl -0x194(%rbp), %edx
callq 0x1400
leaq 0x625(%rip), %rdi       # 0x2137
movb $0x0, %al
callq 0x1090
leaq -0xf0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
movl -0x198(%rbp), %edx
callq 0x1400
leaq -0xa0(%rbp), %rdi
movl -0x194(%rbp), %esi
callq 0x1360
movl %eax, 0x262e(%rip)      # 0x4178
leaq -0xf0(%rbp), %rdi
movl -0x198(%rbp), %esi
callq 0x1360
movl %eax, 0x261a(%rip)      # 0x417c
cmpl $0x15, 0x2613(%rip)     # 0x417c
jle 0x1b7b
leaq 0x613(%rip), %rdi       # 0x2185
movb $0x0, %al
callq 0x1090
jmp 0x1bc9
movl 0x25f7(%rip), %eax      # 0x4178
cmpl 0x25f5(%rip), %eax      # 0x417c
jne 0x1b99
leaq 0x60d(%rip), %rdi       # 0x219d
movb $0x0, %al
callq 0x1090
jmp 0x1bc7
movl 0x25d9(%rip), %eax      # 0x4178
cmpl 0x25d7(%rip), %eax      # 0x417c
jge 0x1bb7
leaq 0x625(%rip), %rdi       # 0x21d3
movb $0x0, %al
callq 0x1090
jmp 0x1bc5
leaq 0x63a(%rip), %rdi       # 0x21f8
movb $0x0, %al
callq 0x1090
jmp 0x1bc7
jmp 0x1bc9
movq $0x0, -0x8(%rbp)
jmp 0x1bd8
jmp 0x16ff
movq -0x8(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
nopw %cs:(%rax,%rax)