#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*/ serverInfo;
typedef int /*<<< orphan*/ clientInfo;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sockfd = -1;
  int clifd = -1;
  char buf[1024];
  int rc = 0;
  int i = 0;
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd == -1) {
    printf("Fail to create a socket.");
  }
  struct sockaddr_in serverInfo, clientInfo;
  int addrlen = sizeof(clientInfo);
  bzero(&serverInfo, sizeof(serverInfo));
  serverInfo.sin_family = PF_INET;
  serverInfo.sin_addr.s_addr = INADDR_ANY;
  serverInfo.sin_port = htons(3260);
  bind(sockfd, (struct sockaddr *)&serverInfo, sizeof(serverInfo));
  listen(sockfd, 5);
  while (1) {
    clifd = accept(sockfd, (struct sockaddr *)&clientInfo, &addrlen);
    rc = recv(clifd, buf, sizeof(buf), 0);
    printf("cfd:%x, \n", clifd);
    printf("rc:%d\n", rc);
    for (i = 0; i < rc; i++) {
      if ((i % 16) == 0)
        printf("\n");
      printf("%02x,", buf[i]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11ef <main+0x6f>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xc,-0x44c(%rbp)
lea    -0x438(%rbp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x430(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x434(%rbp)
mov    $0xcbc,%edi
call   1040 <htons@plt>
mov    %eax,-0x438(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x438(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1060 <listen@plt>
mov    -0x14(%rbp),%edi
lea    -0x448(%rbp),%rsi
lea    -0x44c(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x424(%rbp)
mov    -0x18(%rbp),%esi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x424(%rbp),%esi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x428(%rbp)
mov    -0x428(%rbp),%eax
cmp    -0x424(%rbp),%eax
jge    1325 <main+0x1a5>
mov    -0x428(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12f4 <main+0x174>
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x428(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%esi
ff
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x428(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x428(%rbp)
jmp    12bd <main+0x13d>
jmp    1259 <main+0xd9>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
jne    11d0 <main+0x40>
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movl   $0xc,0xc(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0xcbc,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    %r13d,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
lea    0xdf4(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %r13d,%edi
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   10a0 <accept@plt>
mov    %eax,%r12d
mov    %eax,%edi
lea    0x30(%rsp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r15d
lea    0xda7(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xda0(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15d,%r15d
jle    1240 <main+0xb0>
mov    %r15d,%ebp
xor    %ebx,%ebx
jmp    12b8 <main+0x128>
nopl   0x0(%rax)
movsbl 0x30(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1240 <main+0xb0>
test   $0xf,%bl
jne    12a0 <main+0x110>
mov    $0xa,%edi
call   1040 <putchar@plt>
jmp    12a0 <main+0x110>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [25 x i8] c"Fail to create a socket.\00"
@PF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [10 x i8] c"cfd:%x, \0A\00"
@.str.2 = [7 x i8] c"rc:%d\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [6 x i8] c"%02x,\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
store i32 0, i32* %9
store i32 0, i32* %10
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
store i32 12, i32* %13
%22 = call i32 @bzero(%struct.sockaddr_in* %11, i32 12)
%23 = load i32, i32* @PF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = call i32 @htons(i32 3260)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %28, i32* %29
%30 = load i32, i32* %6
%31 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%32 = call i32 @bind(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = load i32, i32* %6
%34 = call i32 @listen(i32 %33, i32 5)
br label %35
35: ; preds = %21, %66
%36 = load i32, i32* %6
%37 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%38 = call i32 @accept(i32 %36, %struct.sockaddr* %37, i32* %13)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = call i32 @recv(i32 %39, i8* %40, i32 1024, i32 0)
store i32 %41, i32* %9
%42 = load i32, i32* %7
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %9
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %44)
store i32 0, i32* %10
br label %46
46: ; preds = %63, %35
%47 = load i32, i32* %10
%48 = load i32, i32* %9
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %66
50: ; preds = %46
%51 = load i32, i32* %10
%52 = srem i32 %51, 16
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %50
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %56
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %46
66: ; preds = %46
br label %35
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [25 x i8] c"Fail to create a socket.\00"
@PF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [10 x i8] c"cfd:%x, \0A\00"
@.str.2 = [7 x i8] c"rc:%d\0A\00"
@.str.4 = [6 x i8] c"%02x,\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = bitcast %struct.sockaddr_in* %4 to i8*
%16 = bitcast %struct.sockaddr_in* %5 to i8*
%17 = bitcast i32* %6 to i8*
store i32 12, i32* %6
%18 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%19 = load i32, i32* @PF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 3260)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%26 = call i32 @bind(i32 %10, %struct.sockaddr* %25, i32 12)
%27 = call i32 @listen(i32 %10, i32 5)
%28 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %29
29: ; preds = %35, %14
%30 = call i32 @accept(i32 %10, %struct.sockaddr* %28, i32* %6)
%31 = call i32 @recv(i32 %30, i8* %7, i32 1024, i32 0)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%34 = icmp sgt i32 %31, 0
br i1 %34, label %36, label %35
35: ; preds = %44, %29
br label %29
36: ; preds = %29
%37 = zext i32 %31 to i64
br label %38
38: ; preds = %36, %44
%39 = phi i64 [ 0, %36 ], [ %49, %44 ]
%40 = and i64 %39, 15
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @putchar(i32 10)
br label %44
44: ; preds = %42, %38
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %39
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = add nuw nsw i64 %39, 1
%50 = icmp eq i64 %49, %37
br i1 %50, label %35, label %38
}