// File: /workspace/github_c_makefile_star2_O1/PARKINHYO[P]BlackjackGame/fifo/fifo_client.c
// Function: send_msg
void* send_msg()
{
	int fd2;
	char filename[BUFF_SIZE];

	sprintf(filename, "%s%d", TO_SERVER_FILE, getpid());
	if ((fd2 = open(filename, O_WRONLY)) == -1) {
		printf("[SYSTEM] in send_msg() open error!!\n");
	}

	int choice;
	char strChoice[10];
	while (1) {
		sleep(1);
		if (finalcheck) { break; }
		/*check2==1 -> HIT/STAND 입력대기*/
		if (check2 == 1) {
			printf("\n");
			printf("1. Hit\n");
			printf("2. Stand\n");
			printf("Please choose 1 or 2: ");
			fflush(stdout);

			fgets(strChoice, sizeof(strChoice), stdin);
			choice = atoi(strChoice);

			if (choice == 1)
			{
				strcpy(buffer, HIT);
				//HIT 서버로 전달
				write(fd2, buffer, BUFFER_SIZE);

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

				check2 = 2;
				sleep(1);
			}
			else if (choice == 2)
			{
				strcpy(buffer, STAND);
				//STAND 서버로 전달
				write(fd2, buffer, BUFFER_SIZE);

				printf("Sending: %s\n", buffer);
				check2 = 0;
				check = 0;
				finalcheck = 1;
				break;
			}
			else {
				printf("Unrecognized choice. Choose again.\n");
			}
			strChoice[strlen(strChoice) - 1] = '\0';
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
callq 0x1060
leaq 0xbc0(%rip), %rsi       # 0x2097
leaq 0xb8b(%rip), %rdx       # 0x2069
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x1100
movq %rbx, %rdi
movl $0x1, %esi
xorl %eax, %eax
callq 0x10e0
movl %eax, %ebx
cmpl $-0x1, %eax
jne 0x1510
leaq 0xc54(%rip), %rdi       # 0x215f
callq 0x1040
movl $0x1, %edi
callq 0x1130
cmpl $0x0, 0x2c37(%rip)      # 0x4158
jne 0x166d
movq 0x2aa2(%rip), %r15      # 0x3fd0
movq 0x2aa3(%rip), %r12      # 0x3fd8
leaq -0x32(%rbp), %r13
leaq 0x2c60(%rip), %r14      # 0x41a0
cmpl $0x1, 0x2c0d(%rip)      # 0x4154
jne 0x1602
movl $0xa, %edi
callq 0x1030
leaq 0xc25(%rip), %rdi       # 0x2183
callq 0x1040
leaq 0xc20(%rip), %rdi       # 0x218a
callq 0x1040
leaq 0xb26(%rip), %rdi       # 0x209c
xorl %eax, %eax
callq 0x1080
movq (%r15), %rdi
callq 0x10c0
movq (%r12), %rdx
movq %r13, %rdi
movl $0xa, %esi
callq 0x10a0
movq %r13, %rdi
callq 0x10f0
cmpl $0x1, %eax
je 0x15b6
cmpl $0x2, %eax
je 0x161b
leaq 0xbe4(%rip), %rdi       # 0x2193
callq 0x1040
jmp 0x15f4
movl $0x544948, 0x2be0(%rip) # imm = 0x544948
movl $0x20, %edx
movl %ebx, %edi
movq %r14, %rsi
callq 0x1050
leaq 0xadd(%rip), %rdi       # 0x20b3
movq %r14, %rsi
xorl %eax, %eax
callq 0x1080
movl $0x2, 0x2b6a(%rip)      # 0x4154
movl $0x1, %edi
callq 0x1130
movq %r13, %rdi
callq 0x1070
movb $0x0, -0x1(%rax,%r13)
movl $0x1, %edi
callq 0x1130
cmpl $0x0, 0x2b45(%rip)      # 0x4158
je 0x1540
jmp 0x166d
movw $0x44, 0x2b80(%rip)     # 0x41a4
movl $0x4e415453, 0x2b72(%rip) # imm = 0x4E415453
leaq 0x2b6b(%rip), %r14      # 0x41a0
movl $0x20, %edx
movl %ebx, %edi
movq %r14, %rsi
callq 0x1050
leaq 0xa68(%rip), %rdi       # 0x20b3
xorl %ebx, %ebx
movq %r14, %rsi
xorl %eax, %eax
callq 0x1080
movl %ebx, 0x2af7(%rip)      # 0x4154
movl %ebx, 0x2aed(%rip)      # 0x4150
movl $0x1, 0x2aeb(%rip)      # 0x4158
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq