#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 timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
struct sockaddr_in {
  int sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ client_addr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ do_get(int, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *get_fileName(char *);
int /*<<< orphan*/ getpeername(int, struct sockaddr *, int *);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int read_line(int, char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
void data_process(int clientfd) {
  fd_set rfds;
  struct timeval tv;
  FD_ZERO(&rfds);
  FD_SET(clientfd, &rfds);
  tv.tv_sec = 10;
  tv.tv_usec = 0;
  struct sockaddr_in client_addr;
  socklen_t c_length = sizeof(client_addr);
  getpeername(clientfd, (struct sockaddr *)(&client_addr), &c_length);
  printf("a client %s:%u connect!\n", inet_ntoa(client_addr.sin_addr),
         client_addr.sin_port);
  int ret_sl = select(clientfd + 1, &rfds, NULL, NULL, &tv);
  if (ret_sl == 0) {
    printf("time out a client %s:%u disconnect!\n",
           inet_ntoa(client_addr.sin_addr), client_addr.sin_port);
    exit(0);
  }
  while (1) {
    char buf[256] = {'\0'};
    int recv_size = read_line(clientfd, buf, sizeof(buf));
    if (recv_size <= 2)
      break;
    char *fileName = get_fileName(buf);
    if (fileName != NULL) {
      do_get(clientfd, fileName);
    }
  }
  printf("a client %s:%u disconnect!\n", inet_ntoa(client_addr.sin_addr),
         client_addr.sin_port);
  exit(0);
}


x86 assembly (clang, -O0):
<data_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1080 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   10d0 <FD_SET@plt>
movl   $0xa,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x8,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <getpeername@plt>
mov    -0x1c(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
mov    -0x20(%rbp),%edx
lea    0xdf2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1090 <select@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    125b <data_process+0xab>
mov    -0x1c(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
mov    -0x20(%rbp),%edx
lea    0xdca(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    1260 <data_process+0xb0>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   10a0 <read_line@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x2,-0x134(%rbp)
jg     129f <data_process+0xef>
jmp    12d4 <data_process+0x124>
lea    -0x130(%rbp),%rdi
call   1070 <get_fileName@plt>
mov    %rax,-0x140(%rbp)
cmpq   $0x0,-0x140(%rbp)
je     12cf <data_process+0x11f>
mov    -0x4(%rbp),%edi
mov    -0x140(%rbp),%rsi
call   10c0 <do_get@plt>
jmp    1260 <data_process+0xb0>
mov    -0x1c(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
mov    -0x20(%rbp),%edx
lea    0xd39(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<data_process>:
push   %r14
push   %rbx
sub    $0x128,%rsp
mov    %edi,%r14d
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
movl   $0xa,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movl   $0x8,0x8(%rsp)
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
call   1040 <getpeername@plt>
mov    0x4(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    (%rsp),%edx
lea    0xdff(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
lea    0x1(%r14),%edi
lea    0x10(%rsp),%r8
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <select@plt>
test   %eax,%eax
jne    123a <data_process+0x9a>
mov    0x4(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    (%rsp),%edx
lea    0xde4(%rip),%rdi
jmp    12d5 <data_process+0x135>
xorps  %xmm0,%xmm0
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0x100,%edx
call   1090 <read_line@plt>
cmp    $0x3,%eax
jge    12e4 <data_process+0x144>
mov    0x4(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    (%rsp),%edx
lea    0xd4d(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0x20(%rsp),%rbx
jmp    137a <data_process+0x1da>
xchg   %ax,%ax
xorps  %xmm0,%xmm0
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1090 <read_line@plt>
cmp    $0x2,%eax
jle    12c2 <data_process+0x122>
mov    %rbx,%rdi
call   1060 <get_fileName@plt>
test   %rax,%rax
je     12f0 <data_process+0x150>
mov    %r14d,%edi
mov    %rax,%rsi
call   10b0 <do_get@plt>
jmp    12f0 <data_process+0x150>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"a client %s:%u connect!\0A\00"
@.str.1 = [37 x i8] c"time out a client %s:%u disconnect!\0A\00"
@.str.2 = [28 x i8] c"a client %s:%u disconnect!\0A\00"
define void @data_process(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %2
%11 = call i32 @FD_ZERO(i32* %3)
%12 = load i32, i32* %2
%13 = call i32 @FD_SET(i32 %12, i32* %3)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
store i32 10, i32* %14
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
store i64 0, i64* %15
store i32 8, i32* %6
%16 = load i32, i32* %2
%17 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%18 = call i32 @getpeername(i32 %16, %struct.sockaddr* %17, i32* %6)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%20 = load i32, i32* %19
%21 = call i8* @inet_ntoa(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %23)
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
%27 = call i32 @select(i32 %26, i32* %3, i32* null, i32* null, %struct.timeval* %4)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %1
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%32 = load i32, i32* %31
%33 = call i8* @inet_ntoa(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %33, i32 %35)
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %1
br label %39
39: ; preds = %38, %56
%40 = bitcast [256 x i8]* %8 to i8*
%41 = load i32, i32* %2
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%43 = call i32 @read_line(i32 %41, i8* %42, i32 256)
store i32 %43, i32* %9
%44 = load i32, i32* %9
%45 = icmp sle i32 %44, 2
br i1 %45, label %46, label %47
46: ; preds = %39
br label %57
47: ; preds = %39
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%49 = call i8* @get_fileName(i8* %48)
store i8* %49, i8** %10
%50 = load i8*, i8** %10
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32, i32* %2
%54 = load i8*, i8** %10
%55 = call i32 @do_get(i32 %53, i8* %54)
br label %56
56: ; preds = %52, %47
br label %39
57: ; preds = %46
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%59 = load i32, i32* %58
%60 = call i8* @inet_ntoa(i32 %59)
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %60, i32 %62)
%64 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"a client %s:%u connect!\0A\00"
@.str.1 = [37 x i8] c"time out a client %s:%u disconnect!\0A\00"
@.str.2 = [28 x i8] c"a client %s:%u disconnect!\0A\00"
define void @data_process(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = bitcast i32* %2 to i8*
%8 = bitcast %struct.timeval* %3 to i8*
%9 = call i32 @FD_ZERO(i32* %2)
%10 = call i32 @FD_SET(i32 %0, i32* %2)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 10, i32* %11
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i64 0, i64* %12
%13 = bitcast %struct.sockaddr_in* %4 to i8*
%14 = bitcast i32* %5 to i8*
store i32 8, i32* %5
%15 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%16 = call i32 @getpeername(i32 %0, %struct.sockaddr* %15, i32* %5)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%18 = load i32, i32* %17
%19 = call i8* @inet_ntoa(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %19, i32 %21)
%23 = add nsw i32 %0, 1
%24 = call i32 @select(i32 %23, i32* %2, i32* null, i32* null, %struct.timeval* %3)
%25 = icmp eq i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %1
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%28 = call i32 @read_line(i32 %0, i8* %27, i32 256)
%29 = icmp slt i32 %28, 3
br i1 %29, label %44, label %36
30: ; preds = %1
%31 = load i32, i32* %17
%32 = call i8* @inet_ntoa(i32 %31)
%33 = load i32, i32* %20
%34 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %32, i32 %33)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %26, %41
%37 = call i8* @get_fileName(i8* %27)
%38 = icmp eq i8* %37, null
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = call i32 @do_get(i32 %0, i8* %37)
br label %41
41: ; preds = %36, %39
%42 = call i32 @read_line(i32 %0, i8* %27, i32 256)
%43 = icmp slt i32 %42, 3
br i1 %43, label %44, label %36
44: ; preds = %41, %26
%45 = load i32, i32* %17
%46 = call i8* @inet_ntoa(i32 %45)
%47 = load i32, i32* %20
%48 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %46, i32 %47)
%49 = call i32 @exit(i32 0)
unreachable
}