#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct boardbuffer {
  int dummy;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ key_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ EOF;
int /*<<< orphan*/ IPC_CREAT;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ ftok(char *, int);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int semget(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ server_log(char *);
int /*<<< orphan*/ set_share_memory(struct boardbuffer *, char *, int);
scalar_t__ shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int shmget(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
void *receive_socket(void *sockfd_arg) {
  char buffer[1024] = {0};
  int sockfd = (int)*((int *)sockfd_arg);
  ssize_t n = 0;
  key_t key = ftok("/tmp", 59);
  key_t semkey = ftok("/tmp", 60);
  int shmid = shmget(key, 4096, IPC_CREAT);
  int semid = semget(semkey, 1, IPC_CREAT);
  struct boardbuffer *share_board = (struct boardbuffer *)shmat(shmid, NULL, 0);
  FILE *fp = NULL;
again:
  while ((n = read(sockfd, buffer, 1024)) > 0) {
    buffer[n] = '\0';
    if (buffer[0] == '#') {
      char filename[20];
      strcpy(filename, buffer + 1);
      printf("receiving file: %s\n", filename);
      if ((fp = fopen(filename, "w+")) == NULL) {
        server_log("open file error!");
        exit(1);
      }
      int length = 0;
      read(sockfd, &length, sizeof(int));
      length = recv(sockfd, buffer, length, 0);
      int write_length = fwrite(buffer, sizeof(char), length, fp);
      if (write_length < length) {
        printf("File write failed!\n");
        break;
      }
      if (length < 0) {
        printf("Recieve data failed!\n");
        break;
      }
      printf("Recieve file finished!\n");
      fclose(fp);
      fp = NULL;
      continue;
    } else {
      if (fputs(buffer, stdout) == EOF) {
        fprintf(stderr, "fputs() error.\n");
        exit(1);
      }
      set_share_memory(share_board, buffer, semid);
    }
  }
  if (n < 0 && errno == EINTR)
    goto again;
  else if (n < 0)
    perror("failed to read data from server.server terminated prematurely.");
  return NULL;
}


x86 assembly (clang, -O0):
<receive_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1090 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x414(%rbp)
movq   $0x0,-0x420(%rbp)
lea    0xda0(%rip),%rdi
mov    $0x3b,%esi
call   1140 <ftok@plt>
mov    %eax,-0x424(%rbp)
lea    0xd89(%rip),%rdi
mov    $0x3c,%esi
call   1140 <ftok@plt>
mov    %eax,-0x428(%rbp)
mov    -0x424(%rbp),%edi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1110 <shmget@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x428(%rbp),%edi
mov    0x2d05(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1040 <semget@plt>
mov    %eax,-0x430(%rbp)
mov    -0x42c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1100 <shmat@plt>
mov    %rax,-0x438(%rbp)
movq   $0x0,-0x440(%rbp)
jmp    12ed <receive_socket+0xcd>
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   10c0 <read@plt>
mov    %rax,-0x420(%rbp)
cmp    $0x0,%rax
jbe    14d4 <receive_socket+0x2b4>
mov    -0x420(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
movsbl -0x410(%rbp),%eax
cmp    $0x23,%eax
jne    1472 <receive_socket+0x252>
lea    -0x460(%rbp),%rdi
lea    -0x410(%rbp),%rsi
add    $0x1,%rsi
call   1050 <strcpy@plt>
lea    -0x460(%rbp),%rsi
lea    0xcaa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x460(%rbp),%rdi
lea    0xca9(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x440(%rbp)
cmp    $0x0,%rax
jne    139c <receive_socket+0x17c>
lea    0xc8f(%rip),%rdi
call   10a0 <server_log@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movl   $0x0,-0x464(%rbp)
mov    -0x414(%rbp),%edi
lea    -0x464(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   10c0 <read@plt>
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x464(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x464(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x464(%rbp),%edx
mov    -0x440(%rbp),%rcx
mov    $0x1,%esi
call   1130 <fwrite@plt>
mov    %eax,-0x468(%rbp)
mov    -0x468(%rbp),%eax
cmp    -0x464(%rbp),%eax
jge    1428 <receive_socket+0x208>
lea    0xc11(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14d4 <receive_socket+0x2b4>
cmpl   $0x0,-0x464(%rbp)
jge    1448 <receive_socket+0x228>
lea    0xc05(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14d4 <receive_socket+0x2b4>
lea    0xc08(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x440(%rbp),%rdi
call   1060 <fclose@plt>
movq   $0x0,-0x440(%rbp)
jmp    12ed <receive_socket+0xcd>
lea    -0x410(%rbp),%rdi
mov    0x2b40(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
mov    0x2b5a(%rip),%rcx
cmp    (%rcx),%rax
jne    14b6 <receive_socket+0x296>
mov    0x2b3a(%rip),%rax
mov    (%rax),%edi
lea    0xbc8(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x438(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x430(%rbp),%edx
call   10b0 <set_share_memory@plt>
jmp    12ed <receive_socket+0xcd>
cmpq   $0x0,-0x420(%rbp)
jae    1501 <receive_socket+0x2e1>
mov    0x2ae7(%rip),%rax
mov    (%rax),%rax
mov    0x2ad5(%rip),%rcx
cmp    (%rcx),%rax
jne    1501 <receive_socket+0x2e1>
jmp    12e8 <receive_socket+0xc8>
cmpq   $0x0,-0x420(%rbp)
jae    151b <receive_socket+0x2fb>
lea    0xb69(%rip),%rdi
call   10f0 <perror@plt>
jmp    1520 <receive_socket+0x300>
xor    %eax,%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_socket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rdi,%rbx
lea    0x30(%rsp),%r15
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <memset@plt>
mov    (%rbx),%ebx
lea    0xdaf(%rip),%r14
mov    %r14,%rdi
mov    $0x3b,%esi
call   1140 <ftok@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    $0x3c,%esi
call   1140 <ftok@plt>
mov    %eax,%r14d
mov    0x2d51(%rip),%r12
mov    (%r12),%edx
mov    %ebp,%edi
mov    $0x1000,%esi
call   1110 <shmget@plt>
mov    %eax,%ebp
mov    (%r12),%edx
mov    %r14d,%edi
mov    $0x1,%esi
call   1040 <semget@plt>
mov    %eax,%r14d
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1100 <shmat@plt>
mov    %rax,%r12
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %eax,%eax
call   10d0 <read@plt>
test   %rax,%rax
je     13e9 <receive_socket+0x1c9>
lea    0x10(%rsp),%rbp
lea    0x30(%rsp),%r15
jmp    1329 <receive_socket+0x109>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2ce9(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1090 <fputs@plt>
mov    0x2cf0(%rip),%rcx
cmp    (%rcx),%rax
je     13fd <receive_socket+0x1dd>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   10c0 <set_share_memory@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %eax,%eax
call   10d0 <read@plt>
test   %rax,%rax
je     13e9 <receive_socket+0x1c9>
movb   $0x0,0x30(%rsp,%rax,1)
cmpb   $0x23,0x30(%rsp)
jne    12e0 <receive_socket+0xc0>
mov    %rbp,%rdi
lea    0x31(%rsp),%rsi
call   1050 <strcpy@plt>
lea    0xcbc(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbp,%rdi
lea    0xcbc(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     141c <receive_socket+0x1fc>
mov    %rax,%r13
movl   $0x0,0xc(%rsp)
mov    $0x4,%edx
mov    %ebx,%edi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   10d0 <read@plt>
mov    0xc(%rsp),%edx
mov    %ebx,%edi
mov    %r15,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,0xc(%rsp)
mov    %r15,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r13,%rcx
call   1130 <fwrite@plt>
mov    0xc(%rsp),%ecx
cmp    %ecx,%eax
jl     13d4 <receive_socket+0x1b4>
test   %ecx,%ecx
js     13dd <receive_socket+0x1bd>
lea    0xc7b(%rip),%rdi
call   1060 <puts@plt>
mov    %r13,%rdi
call   1070 <fclose@plt>
jmp    130f <receive_socket+0xef>
lea    0xc8e(%rip),%rdi
jmp    13e4 <receive_socket+0x1c4>
lea    0xc70(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bd4(%rip),%rax
mov    (%rax),%edi
lea    0xc20(%rip),%rsi
call   10e0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xbf9(%rip),%rdi
call   10b0 <server_log@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.boardbuffer = type { i32 }
@.str = [5 x i8] c"/tmp\00"
@IPC_CREAT = global i32 0
@.str.1 = [20 x i8] c"receiving file: %s\0A\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [17 x i8] c"open file error!\00"
@.str.4 = [20 x i8] c"File write failed!\0A\00"
@.str.5 = [22 x i8] c"Recieve data failed!\0A\00"
@.str.6 = [24 x i8] c"Recieve file finished!\0A\00"
@stdout = global i32 0
@EOF = global i64 0
@stderr = global i32 0
@.str.7 = [16 x i8] c"fputs() error.\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.8 = [63 x i8] c"failed to read data from server.server terminated prematurely.\00"
define i8* @receive_socket(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.boardbuffer*
%11 = alloca i32*
%12 = alloca [20 x i8]
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %2
%15 = bitcast [1024 x i8]* %3 to i8*
%16 = load i8*, i8** %2
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
store i32 %18, i32* %4
store i64 0, i64* %5
%19 = call i32 @ftok(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 59)
store i32 %19, i32* %6
%20 = call i32 @ftok(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 60)
store i32 %20, i32* %7
%21 = load i32, i32* %6
%22 = load i32, i32* @IPC_CREAT
%23 = call i32 @shmget(i32 %21, i32 4096, i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %7
%25 = load i32, i32* @IPC_CREAT
%26 = call i32 @semget(i32 %24, i32 1, i32 %25)
store i32 %26, i32* %9
%27 = load i32, i32* %8
%28 = call i64 @shmat(i32 %27, i32* null, i32 0)
%29 = inttoptr i64 %28 to %struct.boardbuffer*
store %struct.boardbuffer* %29, %struct.boardbuffer** %10
store i32* null, i32** %11
br label %30
30: ; preds = %104, %1
br label %31
31: ; preds = %96, %77, %30
%32 = load i32, i32* %4
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%34 = call i64 (i32, ...) @read(i32 %32, i8* %33, i32 1024)
store i64 %34, i64* %5
%35 = icmp ugt i64 %34, 0
br i1 %35, label %36, label %97
36: ; preds = %31
%37 = load i64, i64* %5
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %37
store i8 0, i8* %38
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 35
br i1 %42, label %43, label %81
43: ; preds = %36
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = call i32 @strcpy(i8* %44, i8* %46)
%48 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %51, i32** %11
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %56
53: ; preds = %43
%54 = call i32 @server_log(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %43
store i32 0, i32* %13
%57 = load i32, i32* %4
%58 = call i64 (i32, ...) @read(i32 %57, i32* %13, i64 4)
%59 = load i32, i32* %4
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%61 = load i32, i32* %13
%62 = call i32 @recv(i32 %59, i8* %60, i32 %61, i32 0)
store i32 %62, i32* %13
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%64 = load i32, i32* %13
%65 = load i32*, i32** %11
%66 = call i32 @fwrite(i8* %63, i32 1, i32 %64, i32* %65)
store i32 %66, i32* %14
%67 = load i32, i32* %14
%68 = load i32, i32* %13
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %72
70: ; preds = %56
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %97
72: ; preds = %56
%73 = load i32, i32* %13
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %97
77: ; preds = %72
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%79 = load i32*, i32** %11
%80 = call i32 @fclose(i32* %79)
store i32* null, i32** %11
br label %31
81: ; preds = %36
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%83 = load i32, i32* @stdout
%84 = call i64 @fputs(i8* %82, i32 %83)
%85 = load i64, i64* @EOF
%86 = icmp eq i64 %84, %85
br i1 %86, label %87, label %91
87: ; preds = %81
%88 = load i32, i32* @stderr
%89 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %81
%92 = load %struct.boardbuffer*, %struct.boardbuffer** %10
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%94 = load i32, i32* %9
%95 = call i32 @set_share_memory(%struct.boardbuffer* %92, i8* %93, i32 %94)
br label %96
96: ; preds = %91
br label %31
97: ; preds = %75, %70, %31
%98 = load i64, i64* %5
%99 = icmp ult i64 %98, 0
br i1 %99, label %100, label %105
100: ; preds = %97
%101 = load i64, i64* @errno
%102 = load i64, i64* @EINTR
%103 = icmp eq i64 %101, %102
br i1 %103, label %104, label %105
104: ; preds = %100
br label %30
105: ; preds = %100, %97
%106 = load i64, i64* %5
%107 = icmp ult i64 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %105
%109 = call i32 @perror(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.8, i64 0, i64 0))
br label %110
110: ; preds = %108, %105
br label %111
111: ; preds = %110
ret i8* null
}

LLVM IR (-O2):
%struct.boardbuffer = type { i32 }
@.str = [5 x i8] c"/tmp\00"
@IPC_CREAT = global i32 0
@.str.1 = [20 x i8] c"receiving file: %s\0A\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [17 x i8] c"open file error!\00"
@stdout = global i32 0
@EOF = global i64 0
@stderr = global i32 0
@.str.7 = [16 x i8] c"fputs() error.\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@str = [23 x i8] c"Recieve file finished!\00"
@str.9 = [21 x i8] c"Recieve data failed!\00"
@str.10 = [19 x i8] c"File write failed!\00"
define noalias i8* @receive_socket(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = bitcast i8* %0 to i32*
%7 = load i32, i32* %6
%8 = tail call i32 @ftok(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 59)
%9 = tail call i32 @ftok(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 60)
%10 = load i32, i32* @IPC_CREAT
%11 = tail call i32 @shmget(i32 %8, i32 4096, i32 %10)
%12 = load i32, i32* @IPC_CREAT
%13 = tail call i32 @semget(i32 %9, i32 1, i32 %12)
%14 = tail call i64 @shmat(i32 %11, i32* null, i32 0)
%15 = inttoptr i64 %14 to %struct.boardbuffer*
%16 = call i64 (i32, ...) @read(i32 %7, i8* %5, i32 1024)
%17 = icmp eq i64 %16, 0
br i1 %17, label %64, label %18
18: ; preds = %1
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1
%21 = bitcast i32* %4 to i8*
br label %22
22: ; preds = %18, %61
%23 = phi i64 [ %16, %18 ], [ %62, %61 ]
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %23
store i8 0, i8* %24
%25 = load i8, i8* %5
%26 = icmp eq i8 %25, 35
br i1 %26, label %27, label %50
27: ; preds = %22
%28 = call i32 @strcpy(i8* %19, i8* %20)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%30 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @server_log(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %27
store i32 0, i32* %4
%36 = call i64 (i32, ...) @read(i32 %7, i32* %4, i64 4)
%37 = load i32, i32* %4
%38 = call i32 @recv(i32 %7, i8* %5, i32 %37, i32 0)
store i32 %38, i32* %4
%39 = call i32 @fwrite(i8* %5, i32 1, i32 %38, i32* %30)
%40 = load i32, i32* %4
%41 = icmp slt i32 %39, %40
br i1 %41, label %44, label %42
42: ; preds = %35
%43 = icmp slt i32 %40, 0
br i1 %43, label %44, label %47
44: ; preds = %42, %35
%45 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.10, i64 0, i64 0), %35 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0), %42 ]
%46 = call i32 @puts(i8* dereferenceable(1) %45)
br label %64
47: ; preds = %42
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%49 = call i32 @fclose(i32* %30)
br label %61
50: ; preds = %22
%51 = load i32, i32* @stdout
%52 = call i64 @fputs(i8* %5, i32 %51)
%53 = load i64, i64* @EOF
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %50
%60 = call i32 @set_share_memory(%struct.boardbuffer* %15, i8* %5, i32 %13)
br label %61
61: ; preds = %59, %47
%62 = call i64 (i32, ...) @read(i32 %7, i8* %5, i32 1024)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %22
64: ; preds = %61, %1, %44
ret i8* null
}