#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serverAddr;
typedef int /*<<< orphan*/ sendbuffer;
typedef int /*<<< orphan*/ guess;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
double RAND_MAX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, int *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int listensd;
  int connectsd;
  int n;
  int processID;
  struct sockaddr_in serverAddr;
  struct sockaddr_in clientAddr;
  int clAddrLen;
  int sd;
  srand(time(NULL));
  listensd = socket(PF_INET, SOCK_STREAM, 0);
  if (listensd == -1) {
    printf("Fail to socket!\n");
    close(listensd);
    exit(1);
  }
  memset(&serverAddr, 0, sizeof(serverAddr));
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  serverAddr.sin_port = htons(3122);
  sd = bind(listensd, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
  if (sd == -1) {
    printf("Fail to bind!\n");
    close(listensd);
    exit(2);
  }
  sd = listen(listensd, 5);
  if (sd == -1) {
    printf("Fail to listen!\n");
    close(listensd);
    exit(3);
  }
  while (1) {
    connectsd = accept(listensd, (struct sockaddr *)&clientAddr, &clAddrLen);
    if (connectsd == -1) {
      printf("Fail to accept!\n");
      close(listensd);
      exit(4);
    }
    int num = (int)((double)(rand()) / RAND_MAX * 100);
    processID = fork();
    if (processID == 0) {
      close(listensd);
      int guess;
      int count = 0;
      int sendbuffer;
      printf("A client start to guess %d\n", num);
      while (1) {
        int bytesToRecv = sizeof(guess);
        char *movePtr = (char *)(&guess);
        count++;
        while ((n = recv(connectsd, movePtr, bytesToRecv, 0)) > 0) {
          movePtr += n;
          bytesToRecv -= n;
          if (bytesToRecv == 0)
            break;
        }
        if (guess > num)
          sendbuffer = -2;
        else if (guess < num)
          sendbuffer = -1;
        else
          sendbuffer = count;
        sd = send(connectsd, &sendbuffer, sizeof(sendbuffer), 0);
        if (sd == -1) {
          printf("A connection failed(error:%d)!\n", errno);
          exit(0);
        }
        if (guess == num) {
          printf("client guess %d in %d time\n", num, count);
          break;
        }
      }
      _exit(0);
    }
    close(connectsd);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   10b0 <srand@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1275 <main+0x65>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xc32,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    12ed <main+0xdd>
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
mov    $0x2,%edi
call   1100 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1327 <main+0x117>
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
mov    $0x3,%edi
call   1100 <exit@plt>
jmp    132c <main+0x11c>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1369 <main+0x159>
lea    0xce9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
mov    $0x4,%edi
call   1100 <exit@plt>
mov    $0x0,%al
call   1120 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2c5c(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xc78(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    14d6 <main+0x2c6>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x3c(%rbp),%esi
lea    0xc8a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x4,-0x4c(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x4c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    142c <main+0x21c>
mov    -0x10(%rbp),%ecx
mov    -0x58(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0x4c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jne    1427 <main+0x217>
jmp    142c <main+0x21c>
jmp    13df <main+0x1cf>
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jle    1444 <main+0x234>
movl   $0xfffffffe,-0x48(%rbp)
jmp    1467 <main+0x257>
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    145c <main+0x24c>
movl   $0xffffffff,-0x48(%rbp)
jmp    1462 <main+0x252>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
jmp    1467 <main+0x257>
mov    -0xc(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    14a5 <main+0x295>
mov    0x2b32(%rip),%rax
mov    (%rax),%esi
lea    0xbcf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jne    14ca <main+0x2ba>
mov    -0x3c(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    0xbc8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14cf <main+0x2bf>
jmp    13c7 <main+0x1b7>
xor    %edi,%edi
call   1040 <_exit@plt>
mov    -0xc(%rbp),%edi
call   10a0 <close@plt>
jmp    132c <main+0x11c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,%edi
call   10c0 <srand@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
cmp    $0xffffffff,%eax
jne    127a <main+0x5a>
lea    0xe2d(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%edi
call   10b0 <close@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   10a0 <memset@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0xc32,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12f1 <main+0xd1>
lea    0xda6(%rip),%rdi
call   1050 <puts@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    $0x2,%edi
call   1110 <exit@plt>
mov    %r14d,%edi
mov    $0x5,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1321 <main+0x101>
lea    0xd66(%rip),%rdi
call   1050 <puts@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    $0x3,%edi
call   1110 <exit@plt>
lea    0x28(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
call   1100 <accept@plt>
cmp    $0xffffffff,%eax
je     138f <main+0x16f>
mov    %eax,%r13d
mov    0x2c96(%rip),%r12
lea    0x28(%rsp),%r15
lea    0xc(%rsp),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1130 <rand@plt>
mov    %rax,%rbp
movsd  (%r12),%xmm0
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
je     13ad <main+0x18d>
mov    %r13d,%edi
call   10b0 <close@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1100 <accept@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    1350 <main+0x130>
lea    0xcca(%rip),%rdi
call   1050 <puts@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    $0x4,%edi
call   1110 <exit@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rbp,%xmm0
divsd  0x20(%rsp),%xmm0
mulsd  0xc3d(%rip),%xmm0
cvttsd2si %xmm0,%r15d
mov    %r14d,%edi
call   10b0 <close@plt>
lea    0xc31(%rip),%rdi
xor    %r12d,%r12d
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x4(%rsp),%r14
nopl   0x0(%rax)
mov    $0x4,%ebx
lea    0x8(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    141c <main+0x1fc>
mov    %eax,%ecx
add    %rcx,%rbp
sub    %eax,%ebx
jne    1400 <main+0x1e0>
add    $0x1,%r12d
cmp    %r15d,0x8(%rsp)
jle    1440 <main+0x220>
movl   $0xfffffffe,0x4(%rsp)
ff
jmp    1455 <main+0x235>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
jge    1450 <main+0x230>
movl   $0xffffffff,0x4(%rsp)
ff
jmp    1455 <main+0x235>
nopl   0x0(%rax)
mov    %r12d,0x4(%rsp)
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0xffffffff,%eax
je     1492 <main+0x272>
cmp    %r15d,0x8(%rsp)
jne    13f0 <main+0x1d0>
lea    0xbc6(%rip),%rdi
mov    %r15d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   1040 <_exit@plt>
mov    0x2b27(%rip),%rax
mov    (%rax),%esi
lea    0xb82(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [17 x i8] c"Fail to socket!\0A\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [15 x i8] c"Fail to bind!\0A\00"
@.str.2 = [17 x i8] c"Fail to listen!\0A\00"
@.str.3 = [17 x i8] c"Fail to accept!\0A\00"
@RAND_MAX = global double 0.000000e+00
@.str.4 = [28 x i8] c"A client start to guess %d\0A\00"
@.str.5 = [32 x i8] c"A connection failed(error:%d)!\0A\00"
@errno = global i32 0
@.str.6 = [28 x i8] c"client guess %d in %d time\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
store i32 0, i32* %1
%16 = call i32 @time(i32* null)
%17 = call i32 @srand(i32 %16)
%18 = load i32, i32* @PF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* %2
%26 = call i32 @close(i32 %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %0
%29 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i32, i32* @INADDR_ANY
%33 = call i32 @htonl(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i32 %33, i32* %35
%36 = call i32 @htons(i32 3122)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %36, i32* %37
%38 = load i32, i32* %2
%39 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%40 = call i32 @bind(i32 %38, %struct.sockaddr* %39, i32 12)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %48
43: ; preds = %28
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%45 = load i32, i32* %2
%46 = call i32 @close(i32 %45)
%47 = call i32 @exit(i32 2)
unreachable
48: ; preds = %28
%49 = load i32, i32* %2
%50 = call i32 @listen(i32 %49, i32 5)
store i32 %50, i32* %9
%51 = load i32, i32* %9
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %58
53: ; preds = %48
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32, i32* %2
%56 = call i32 @close(i32 %55)
%57 = call i32 @exit(i32 3)
unreachable
58: ; preds = %48
br label %59
59: ; preds = %58, %140
%60 = load i32, i32* %2
%61 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%62 = call i32 @accept(i32 %60, %struct.sockaddr* %61, i32* %8)
store i32 %62, i32* %3
%63 = load i32, i32* %3
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %70
65: ; preds = %59
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%67 = load i32, i32* %2
%68 = call i32 @close(i32 %67)
%69 = call i32 @exit(i32 4)
unreachable
70: ; preds = %59
%71 = call i64 (...) @rand()
%72 = sitofp i64 %71 to double
%73 = load double, double* @RAND_MAX
%74 = fdiv double %72, %73
%75 = fmul double %74, 1.000000e+02
%76 = fptosi double %75 to i32
store i32 %76, i32* %10
%77 = call i32 (...) @fork()
store i32 %77, i32* %5
%78 = load i32, i32* %5
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %140
80: ; preds = %70
%81 = load i32, i32* %2
%82 = call i32 @close(i32 %81)
store i32 0, i32* %12
%83 = load i32, i32* %10
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %83)
br label %85
85: ; preds = %80, %137
store i32 4, i32* %14
%86 = bitcast i32* %11 to i8*
store i8* %86, i8** %15
%87 = load i32, i32* %12
%88 = add nsw i32 %87, 1
store i32 %88, i32* %12
br label %89
89: ; preds = %106, %85
%90 = load i32, i32* %3
%91 = load i8*, i8** %15
%92 = load i32, i32* %14
%93 = call i32 @recv(i32 %90, i8* %91, i32 %92, i32 0)
store i32 %93, i32* %4
%94 = icmp sgt i32 %93, 0
br i1 %94, label %95, label %107
95: ; preds = %89
%96 = load i32, i32* %4
%97 = load i8*, i8** %15
%98 = sext i32 %96 to i64
%99 = getelementptr inbounds i8, i8* %97, i64 %98
store i8* %99, i8** %15
%100 = load i32, i32* %4
%101 = load i32, i32* %14
%102 = sub nsw i32 %101, %100
store i32 %102, i32* %14
%103 = load i32, i32* %14
%104 = icmp eq i32 %103, 0
br i1 %104, label %105, label %106
105: ; preds = %95
br label %107
106: ; preds = %95
br label %89
107: ; preds = %105, %89
%108 = load i32, i32* %11
%109 = load i32, i32* %10
%110 = icmp sgt i32 %108, %109
br i1 %110, label %111, label %112
111: ; preds = %107
store i32 -2, i32* %13
br label %120
112: ; preds = %107
%113 = load i32, i32* %11
%114 = load i32, i32* %10
%115 = icmp slt i32 %113, %114
br i1 %115, label %116, label %117
116: ; preds = %112
store i32 -1, i32* %13
br label %119
117: ; preds = %112
%118 = load i32, i32* %12
store i32 %118, i32* %13
br label %119
119: ; preds = %117, %116
br label %120
120: ; preds = %119, %111
%121 = load i32, i32* %3
%122 = call i32 @send(i32 %121, i32* %13, i32 4, i32 0)
store i32 %122, i32* %9
%123 = load i32, i32* %9
%124 = icmp eq i32 %123, -1
br i1 %124, label %125, label %129
125: ; preds = %120
%126 = load i32, i32* @errno
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %126)
%128 = call i32 @exit(i32 0)
unreachable
129: ; preds = %120
%130 = load i32, i32* %11
%131 = load i32, i32* %10
%132 = icmp eq i32 %130, %131
br i1 %132, label %133, label %137
133: ; preds = %129
%134 = load i32, i32* %10
%135 = load i32, i32* %12
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %134, i32 %135)
br label %138
137: ; preds = %129
br label %85
138: ; preds = %133
%139 = call i32 @_exit(i32 0)
unreachable
140: ; preds = %70
%141 = load i32, i32* %3
%142 = call i32 @close(i32 %141)
br label %59
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@RAND_MAX = global double 0.000000e+00
@.str.4 = [28 x i8] c"A client start to guess %d\0A\00"
@.str.5 = [32 x i8] c"A connection failed(error:%d)!\0A\00"
@errno = global i32 0
@.str.6 = [28 x i8] c"client guess %d in %d time\0A\00"
@str = [16 x i8] c"Fail to accept!\00"
@str.7 = [16 x i8] c"Fail to listen!\00"
@str.8 = [14 x i8] c"Fail to bind!\00"
@str.9 = [16 x i8] c"Fail to socket!\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = bitcast %struct.sockaddr_in* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = tail call i32 @time(i32* null)
%10 = tail call i32 @srand(i32 %9)
%11 = load i32, i32* @PF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0))
%17 = tail call i32 @close(i32 -1)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %0
%20 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %24, i32* %25
%26 = call i32 @htons(i32 3122)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %26, i32* %27
%28 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%29 = call i32 @bind(i32 %13, %struct.sockaddr* %28, i32 12)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %19
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0))
%33 = call i32 @close(i32 %13)
%34 = call i32 @exit(i32 2)
unreachable
35: ; preds = %19
%36 = call i32 @listen(i32 %13, i32 5)
%37 = icmp eq i32 %36, -1
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%40 = call i32 @accept(i32 %13, %struct.sockaddr* %39, i32* %3)
%41 = icmp eq i32 %40, -1
br i1 %41, label %46, label %50
42: ; preds = %35
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%44 = call i32 @close(i32 %13)
%45 = call i32 @exit(i32 3)
unreachable
46: ; preds = %99, %38
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%48 = call i32 @close(i32 %13)
%49 = call i32 @exit(i32 4)
unreachable
50: ; preds = %38, %99
%51 = phi i32 [ %101, %99 ], [ %40, %38 ]
%52 = call i64 (...) @rand()
%53 = load double, double* @RAND_MAX
%54 = call i32 (...) @fork()
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %99
56: ; preds = %50
%57 = sitofp i64 %52 to double
%58 = fdiv double %57, %53
%59 = fmul double %58, 1.000000e+02
%60 = fptosi double %59 to i32
%61 = call i32 @close(i32 %13)
%62 = bitcast i32* %4 to i8*
%63 = bitcast i32* %5 to i8*
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %60)
br label %65
65: ; preds = %93, %56
%66 = phi i32 [ 0, %56 ], [ %78, %93 ]
br label %67
67: ; preds = %67, %65
%68 = phi i32 [ 4, %65 ], [ %74, %67 ]
%69 = phi i8* [ %62, %65 ], [ %73, %67 ]
%70 = call i32 @recv(i32 %51, i8* %69, i32 %68, i32 0)
%71 = icmp slt i32 %70, 1
%72 = zext i32 %70 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
%74 = sub nsw i32 %68, %70
%75 = icmp eq i32 %74, 0
%76 = select i1 %71, i1 true, i1 %75
br i1 %76, label %77, label %67
77: ; preds = %67
%78 = add nuw nsw i32 %66, 1
%79 = load i32, i32* %4
%80 = icmp sgt i32 %79, %60
br i1 %80, label %81, label %82
81: ; preds = %77
store i32 -2, i32* %5
br label %86
82: ; preds = %77
%83 = icmp slt i32 %79, %60
br i1 %83, label %84, label %85
84: ; preds = %82
store i32 -1, i32* %5
br label %86
85: ; preds = %82
store i32 %78, i32* %5
br label %86
86: ; preds = %84, %85, %81
%87 = call i32 @send(i32 %51, i32* %5, i32 4, i32 0)
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %93
89: ; preds = %86
%90 = load i32, i32* @errno
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %90)
%92 = call i32 @exit(i32 0)
unreachable
93: ; preds = %86
%94 = load i32, i32* %4
%95 = icmp eq i32 %94, %60
br i1 %95, label %96, label %65
96: ; preds = %93
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %60, i32 %78)
%98 = call i32 @_exit(i32 0)
unreachable
99: ; preds = %50
%100 = call i32 @close(i32 %51)
%101 = call i32 @accept(i32 %13, %struct.sockaddr* %39, i32* %3)
%102 = icmp eq i32 %101, -1
br i1 %102, label %46, label %50
}