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

/* Variables and functions */
int /*<<< orphan*/ do_get(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int read_line(int, char *, int);
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int time_out(int);
void get_client_data(int client_fd) {
  while (1) {
    int ret = time_out(client_fd);
    if (ret > 0) {
      char buf[128] = {'\0'};
      int size = read_line(client_fd, buf, sizeof(buf));
      printf("size:%d,read_line = %s", size, buf);
      if (size <= 2)
        break;
      char *p = strchr(buf, ' ');
      if (p) {
        *p++ = '\0';
        if (strcmp("GET", buf) == 0) {
          char *q = strchr(p, ' ');
          if (q) {
            *q = '\0';
            do_get(client_fd, p);
          }
        }
      }
    } else if (0 == ret) {
      printf("time out!\n");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<get_client_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <time_out@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1296 <get_client_data+0x126>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1080 <read_line@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%esi
lea    -0x90(%rbp),%rdx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x2,-0x94(%rbp)
jg     11ed <get_client_data+0x7d>
jmp    12be <get_client_data+0x14e>
lea    -0x90(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
je     1291 <get_client_data+0x121>
mov    -0xa0(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xa0(%rbp)
movb   $0x0,(%rax)
lea    -0x90(%rbp),%rsi
lea    0xdde(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    128c <get_client_data+0x11c>
mov    -0xa0(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
je     1287 <get_client_data+0x117>
mov    -0xa8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x4(%rbp),%edi
mov    -0xa0(%rbp),%rsi
call   1090 <do_get@plt>
jmp    128c <get_client_data+0x11c>
jmp    1291 <get_client_data+0x121>
jmp    12b9 <get_client_data+0x149>
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jne    12b4 <get_client_data+0x144>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12be <get_client_data+0x14e>
jmp    12b9 <get_client_data+0x149>
jmp    117e <get_client_data+0xe>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_client_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %edi,%ebp
mov    %rsp,%r14
lea    0xe75(%rip),%r15
lea    0xe85(%rip),%r12
jmp    11a6 <get_client_data+0x36>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
je     1258 <get_client_data+0xe8>
mov    %ebp,%edi
call   1070 <time_out@plt>
test   %eax,%eax
jle    11a0 <get_client_data+0x30>
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x80,%edx
call   1080 <read_line@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x3,%ebx
jl     1264 <get_client_data+0xf4>
mov    %r14,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a6 <get_client_data+0x36>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11a6 <get_client_data+0x36>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11a6 <get_client_data+0x36>
movb   $0x0,(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <do_get@plt>
jmp    11a6 <get_client_data+0x36>
lea    0xdbc(%rip),%rdi
call   1030 <puts@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"size:%d,read_line = %s\00"
@.str.1 = [4 x i8] c"GET\00"
@.str.2 = [11 x i8] c"time out!\0A\00"
define void @get_client_data(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %2
br label %8
8: ; preds = %1, %54
%9 = load i32, i32* %2
%10 = call i32 @time_out(i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %48
13: ; preds = %8
%14 = bitcast [128 x i8]* %4 to i8*
%15 = load i32, i32* %2
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%17 = call i32 @read_line(i32 %15, i8* %16, i32 128)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %18, i8* %19)
%21 = load i32, i32* %5
%22 = icmp sle i32 %21, 2
br i1 %22, label %23, label %24
23: ; preds = %13
br label %55
24: ; preds = %13
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%26 = call i8* @strchr(i8* %25, i8 signext 32)
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %47
29: ; preds = %24
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
store i8 0, i8* %30
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%33 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %46
35: ; preds = %29
%36 = load i8*, i8** %6
%37 = call i8* @strchr(i8* %36, i8 signext 32)
store i8* %37, i8** %7
%38 = load i8*, i8** %7
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i8*, i8** %7
store i8 0, i8* %41
%42 = load i32, i32* %2
%43 = load i8*, i8** %6
%44 = call i32 @do_get(i32 %42, i8* %43)
br label %45
45: ; preds = %40, %35
br label %46
46: ; preds = %45, %29
br label %47
47: ; preds = %46, %24
br label %54
48: ; preds = %8
%49 = load i32, i32* %3
%50 = icmp eq i32 0, %49
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %55
53: ; preds = %48
br label %54
54: ; preds = %53, %47
br label %8
55: ; preds = %51, %23
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"size:%d,read_line = %s\00"
@.str.1 = [4 x i8] c"GET\00"
@str = [10 x i8] c"time out!\00"
define void @get_client_data(i32 %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %27, %1
%5 = call i32 @time_out(i32 %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = call i32 @read_line(i32 %0, i8* %3, i32 128)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %3)
%10 = icmp slt i32 %8, 3
br i1 %10, label %24, label %11
11: ; preds = %7
%12 = call i8* @strchr(i8* %3, i8 signext 32)
%13 = icmp eq i8* %12, null
br i1 %13, label %23, label %14
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %12, i64 1
store i8 0, i8* %12
%16 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = call i8* @strchr(i8* %15, i8 signext 32)
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %18
store i8 0, i8* %19
%22 = call i32 @do_get(i32 %0, i8* %15)
br label %23
23: ; preds = %11, %14, %21, %18
br label %27
24: ; preds = %7
br label %30
25: ; preds = %4
%26 = icmp eq i32 %5, 0
br i1 %26, label %28, label %27
27: ; preds = %25, %23
br label %4
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %24, %28
ret void
}