#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 sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
typedef int /*<<< orphan*/ recvbuf;

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write(int, char *, int);
void doServer(int connsocket, struct sockaddr_in cliaddr) {
  char recvbuf[1024];
  while (1) {
    memset(recvbuf, 0, sizeof(recvbuf));
    int recvcount = read(connsocket, recvbuf, sizeof(recvbuf));
    if (recvcount == 0) {
      printf("the client whose ip=%s,and port=%d,closed! \n",
             inet_ntoa(cliaddr.sin_addr), ntohs(cliaddr.sin_port));
      break;
    }
    fputs(recvbuf, stdout);
    write(connsocket, recvbuf, recvcount);
  }
}


x86 assembly (clang, -O0):
<doServer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rsi,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jne    11ed <doServer+0x7d>
mov    -0x4(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x420(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <ntohs@plt>
mov    -0x420(%rbp),%rsi
mov    %eax,%edx
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
jmp    121c <doServer+0xac>
lea    -0x410(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1030 <write@plt>
jmp    1182 <doServer+0x12>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doServer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
test   %eax,%eax
je     11fe <doServer+0x8e>
mov    %eax,%ebp
mov    0x2e2c(%rip),%r12
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    (%r12),%esi
mov    %rbx,%rdi
call   1060 <fputs@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11c0 <doServer+0x50>
mov    %r14,%rdi
shr    $0x20,%rdi
call   1040 <inet_ntoa@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1090 <ntohs@plt>
lea    0xde4(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
@.str = [45 x i8] c"the client whose ip=%s,and port=%d,closed! \0A\00"
@stdout = global i32 0
define void @doServer(i32 %0, i64 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = bitcast %struct.sockaddr_in* %3 to i64*
store i64 %1, i64* %7
store i32 %0, i32* %4
br label %8
8: ; preds = %2, %24
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 1024)
%11 = load i32, i32* %4
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 1024)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %8
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i8* @inet_ntoa(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @ntohs(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %19, i32 %22)
br label %32
24: ; preds = %8
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%26 = load i32, i32* @stdout
%27 = call i32 @fputs(i8* %25, i32 %26)
%28 = load i32, i32* %4
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%30 = load i32, i32* %6
%31 = call i32 @write(i32 %28, i8* %29, i32 %30)
br label %8
32: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"the client whose ip=%s,and port=%d,closed! \0A\00"
@stdout = global i32 0
define void @doServer(i32 %0, i64 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 1024)
%6 = call i32 @read(i32 %0, i8* %4, i32 1024)
%7 = icmp eq i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %2, %8
%9 = phi i32 [ %14, %8 ], [ %6, %2 ]
%10 = load i32, i32* @stdout
%11 = call i32 @fputs(i8* %4, i32 %10)
%12 = call i32 @write(i32 %0, i8* %4, i32 %9)
%13 = call i32 @memset(i8* %4, i32 0, i32 1024)
%14 = call i32 @read(i32 %0, i8* %4, i32 1024)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8, %2
%17 = lshr i64 %1, 32
%18 = trunc i64 %17 to i32
%19 = trunc i64 %1 to i32
%20 = call i8* @inet_ntoa(i32 %18)
%21 = call i32 @ntohs(i32 %19)
%22 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %21)
ret void
}