#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;
  int tv_usec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int checksum(unsigned char *, int);
int getint(unsigned char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int read(int, unsigned char *, int);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int listen(int fd, unsigned char *pak) {
  unsigned char buf[1024];
  fd_set readfs;
  struct timeval tout;
  int ret, res, STOP, TIMEOUT;
  int maxfd = fd + 1;
  int len = 0;
  STOP = 0;
  TIMEOUT = 0;
  FD_ZERO(&readfs);
  tout.tv_sec = 2;
  tout.tv_usec = 560000;
  while (STOP == 0) {
    FD_SET(fd, &readfs);
    ret = select(maxfd, &readfs, NULL, NULL, &tout);
    if (FD_ISSET(fd, &readfs)) {
      res = read(fd, buf, 1024);
      if (res > 0) {
        if (buf[0] == 0x06 || buf[0] == 0x15 || buf[0] == 0x18 ||
            buf[0] == 0xa5) {
          STOP = 1;
          memcpy(pak, buf, res);
          len += res;
        }
      }
    }
    if (ret == 0) {
      STOP = 1;
      TIMEOUT = 1;
    }
  }
  if (TIMEOUT == 1)
    return -1;
  if (pak[0] == 0x06 || pak[0] == 0x15 || pak[0] == 0x18)
    return 1;
  STOP = 0;
  if (len >= 6 && (len - 6) == getint(&pak[2]))
    STOP = 1;
  TIMEOUT = 0;
  FD_ZERO(&readfs);
  tout.tv_sec = 2;
  tout.tv_usec = 560000;
  while (STOP == 0) {
    FD_SET(fd, &readfs);
    ret = select(maxfd, &readfs, NULL, NULL, &tout);
    if (FD_ISSET(fd, &readfs)) {
      res = read(fd, buf, 1024);
      if (res > 0) {
        memcpy(&pak[len], buf, res);
        len += res;
      }
    }
    if (ret == 0) {
      STOP = 1;
      TIMEOUT = 1;
    }
    if (len >= 6 && (len - 6) == getint(&pak[2]))
      STOP = 1;
  }
  if (checksum(pak, len) == 1)
    return len;
  else
    return -2;
}


x86 assembly (clang, -O0):
<listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
movl   $0x0,-0x438(%rbp)
movl   $0x0,-0x42c(%rbp)
movl   $0x0,-0x430(%rbp)
lea    -0x414(%rbp),%rdi
call   1080 <FD_ZERO@plt>
movl   $0x2,-0x420(%rbp)
movl   $0x88b80,-0x41c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jne    1302 <listen+0x182>
mov    -0x8(%rbp),%edi
lea    -0x414(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x434(%rbp),%edi
lea    -0x414(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x420(%rbp),%r8
mov    %rcx,%rdx
call   1090 <select@plt>
mov    %eax,-0x424(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x414(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     12dc <listen+0x15c>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0x0,-0x428(%rbp)
jle    12d7 <listen+0x157>
movzbl -0x410(%rbp),%eax
cmp    $0x6,%eax
je     12a0 <listen+0x120>
movzbl -0x410(%rbp),%eax
cmp    $0x15,%eax
je     12a0 <listen+0x120>
movzbl -0x410(%rbp),%eax
cmp    $0x18,%eax
je     12a0 <listen+0x120>
movzbl -0x410(%rbp),%eax
cmp    $0xa5,%eax
jne    12d2 <listen+0x152>
movl   $0x1,-0x42c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x428(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x428(%rbp),%eax
add    -0x438(%rbp),%eax
mov    %eax,-0x438(%rbp)
jmp    12d7 <listen+0x157>
jmp    12dc <listen+0x15c>
cmpl   $0x0,-0x424(%rbp)
jne    12fd <listen+0x17d>
movl   $0x1,-0x42c(%rbp)
movl   $0x1,-0x430(%rbp)
jmp    11dc <listen+0x5c>
cmpl   $0x1,-0x430(%rbp)
jne    131b <listen+0x19b>
movl   $0xffffffff,-0x4(%rbp)
jmp    151d <listen+0x39d>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x6,%eax
je     134b <listen+0x1cb>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x15,%eax
je     134b <listen+0x1cb>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x18,%eax
jne    1357 <listen+0x1d7>
movl   $0x1,-0x4(%rbp)
jmp    151d <listen+0x39d>
movl   $0x0,-0x42c(%rbp)
cmpl   $0x6,-0x438(%rbp)
jl     13a4 <listen+0x224>
mov    -0x438(%rbp),%eax
sub    $0x6,%eax
mov    %eax,-0x43c(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
call   1050 <getint@plt>
mov    %eax,%ecx
mov    -0x43c(%rbp),%eax
cmp    %ecx,%eax
jne    13a4 <listen+0x224>
movl   $0x1,-0x42c(%rbp)
movl   $0x0,-0x430(%rbp)
lea    -0x414(%rbp),%rdi
call   1080 <FD_ZERO@plt>
movl   $0x2,-0x420(%rbp)
movl   $0x88b80,-0x41c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jne    14f0 <listen+0x370>
mov    -0x8(%rbp),%edi
lea    -0x414(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x434(%rbp),%edi
lea    -0x414(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x420(%rbp),%r8
mov    %rcx,%rdx
call   1090 <select@plt>
mov    %eax,-0x424(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x414(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1487 <listen+0x307>
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0x0,-0x428(%rbp)
jle    1482 <listen+0x302>
mov    -0x10(%rbp),%rdi
movslq -0x438(%rbp),%rax
add    %rax,%rdi
lea    -0x410(%rbp),%rsi
mov    -0x428(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x428(%rbp),%eax
add    -0x438(%rbp),%eax
mov    %eax,-0x438(%rbp)
jmp    1487 <listen+0x307>
cmpl   $0x0,-0x424(%rbp)
jne    14a8 <listen+0x328>
movl   $0x1,-0x42c(%rbp)
movl   $0x1,-0x430(%rbp)
cmpl   $0x6,-0x438(%rbp)
jl     14eb <listen+0x36b>
mov    -0x438(%rbp),%eax
sub    $0x6,%eax
mov    %eax,-0x440(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
call   1050 <getint@plt>
mov    %eax,%ecx
mov    -0x440(%rbp),%eax
cmp    %ecx,%eax
jne    14eb <listen+0x36b>
movl   $0x1,-0x42c(%rbp)
jmp    13ce <listen+0x24e>
mov    -0x10(%rbp),%rdi
mov    -0x438(%rbp),%esi
call   1040 <checksum@plt>
cmp    $0x1,%eax
jne    1516 <listen+0x396>
mov    -0x438(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    151d <listen+0x39d>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsi,0x10(%rsp)
mov    %edi,%ebx
lea    0x1(%rbx),%eax
mov    %eax,0x1c(%rsp)
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
call   1080 <FD_ZERO@plt>
movabs $0x88b8000000002,%rax
mov    %rax,0x20(%rsp)
xor    %r15d,%r15d
lea    0x20(%rsp),%r13
jmp    11e2 <listen+0x62>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0xa5,%al
je     123f <listen+0xbf>
test   %r14d,%r14d
mov    $0x1,%eax
cmove  %eax,%r15d
je     1260 <listen+0xe0>
mov    %ebx,%edi
mov    %rbp,%rsi
call   10a0 <FD_SET@plt>
mov    0x1c(%rsp),%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r13,%r8
call   1090 <select@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     11d4 <listen+0x54>
mov    %ebx,%edi
lea    0x30(%rsp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11d4 <listen+0x54>
mov    %eax,%r12d
movzbl 0x30(%rsp),%eax
cmp    $0x18,%rax
ja     11d0 <listen+0x50>
mov    $0x1200040,%ecx
bt     %rax,%rcx
jae    11d0 <listen+0x50>
lea    0x30(%rsp),%rsi
mov    0x10(%rsp),%rdi
mov    %r12d,%edx
call   1070 <memcpy@plt>
test   %r14d,%r14d
jne    1263 <listen+0xe3>
mov    $0xffffffff,%eax
jmp    13c1 <listen+0x241>
xor    %r12d,%r12d
mov    $0xffffffff,%eax
cmp    $0x1,%r15d
je     13c1 <listen+0x241>
mov    0x10(%rsp),%rax
movzbl (%rax),%ecx
cmp    $0x18,%rcx
ja     1294 <listen+0x114>
mov    $0x1,%eax
mov    $0x1200040,%edx
bt     %rcx,%rdx
jb     13c1 <listen+0x241>
cmp    $0x5,%r12d
jle    12d2 <listen+0x152>
lea    -0x6(%r12),%r14d
mov    0x10(%rsp),%rax
lea    0x2(%rax),%rdi
call   1050 <getint@plt>
mov    %eax,%ebp
lea    0xc(%rsp),%rdi
call   1080 <FD_ZERO@plt>
movabs $0x88b8000000002,%rax
mov    %rax,0x20(%rsp)
cmp    %ebp,%r14d
jne    12eb <listen+0x16b>
jmp    13a8 <listen+0x228>
lea    0xc(%rsp),%rdi
call   1080 <FD_ZERO@plt>
movabs $0x88b8000000002,%rax
mov    %rax,0x20(%rsp)
mov    0x10(%rsp),%rax
add    $0x2,%rax
mov    %rax,0x28(%rsp)
lea    0xc(%rsp),%r15
lea    0x30(%rsp),%rbp
jmp    1319 <listen+0x199>
cs nopw 0x0(%rax,%rax,1)
nop
test   %r13d,%r13d
je     13a8 <listen+0x228>
mov    %ebx,%edi
mov    %r15,%rsi
call   10a0 <FD_SET@plt>
mov    0x1c(%rsp),%edi
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
call   1090 <select@plt>
mov    %eax,%r13d
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     137a <listen+0x1fa>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    137a <listen+0x1fa>
mov    %eax,%r14d
movslq %r12d,%r12
mov    0x10(%rsp),%rax
lea    (%rax,%r12,1),%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1070 <memcpy@plt>
add    %r14d,%r12d
cmp    $0x6,%r12d
jl     1310 <listen+0x190>
mov    %r15,%r14
mov    %rbp,%r15
lea    -0x6(%r12),%ebp
mov    0x28(%rsp),%rdi
call   1050 <getint@plt>
cmp    %eax,%ebp
je     13a8 <listen+0x228>
test   %r13d,%r13d
mov    %r15,%rbp
mov    %r14,%r15
jne    1319 <listen+0x199>
mov    0x10(%rsp),%rdi
mov    %r12d,%esi
call   1040 <checksum@plt>
cmp    $0x1,%eax
mov    $0xfffffffe,%eax
cmove  %r12d,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @listen(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %13
store i32 0, i32* %14
store i32 0, i32* %11
store i32 0, i32* %12
%17 = call i32 @FD_ZERO(i32* %7)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 2, i32* %18
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i32 560000, i32* %19
br label %20
20: ; preds = %71, %2
%21 = load i32, i32* %11
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %72
23: ; preds = %20
%24 = load i32, i32* %4
%25 = call i32 @FD_SET(i32 %24, i32* %7)
%26 = load i32, i32* %13
%27 = call i32 @select(i32 %26, i32* %7, i32* null, i32* null, %struct.timeval* %8)
store i32 %27, i32* %9
%28 = load i32, i32* %4
%29 = call i64 @FD_ISSET(i32 %28, i32* %7)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %67
31: ; preds = %23
%32 = load i32, i32* %4
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 1024)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %66
37: ; preds = %31
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = icmp eq i32 %40, 6
br i1 %41, label %57, label %42
42: ; preds = %37
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = icmp eq i32 %45, 21
br i1 %46, label %57, label %47
47: ; preds = %42
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = icmp eq i32 %50, 24
br i1 %51, label %57, label %52
52: ; preds = %47
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = icmp eq i32 %55, 165
br i1 %56, label %57, label %65
57: ; preds = %52, %47, %42, %37
store i32 1, i32* %11
%58 = load i8*, i8** %5
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%60 = load i32, i32* %10
%61 = call i32 @memcpy(i8* %58, i8* %59, i32 %60)
%62 = load i32, i32* %10
%63 = load i32, i32* %14
%64 = add nsw i32 %63, %62
store i32 %64, i32* %14
br label %65
65: ; preds = %57, %52
br label %66
66: ; preds = %65, %31
br label %67
67: ; preds = %66, %23
%68 = load i32, i32* %9
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %67
store i32 1, i32* %11
store i32 1, i32* %12
br label %71
71: ; preds = %70, %67
br label %20
72: ; preds = %20
%73 = load i32, i32* %12
%74 = icmp eq i32 %73, 1
br i1 %74, label %75, label %76
75: ; preds = %72
store i32 -1, i32* %3
br label %163
76: ; preds = %72
%77 = load i8*, i8** %5
%78 = getelementptr inbounds i8, i8* %77, i64 0
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = icmp eq i32 %80, 6
br i1 %81, label %94, label %82
82: ; preds = %76
%83 = load i8*, i8** %5
%84 = getelementptr inbounds i8, i8* %83, i64 0
%85 = load i8, i8* %84
%86 = zext i8 %85 to i32
%87 = icmp eq i32 %86, 21
br i1 %87, label %94, label %88
88: ; preds = %82
%89 = load i8*, i8** %5
%90 = getelementptr inbounds i8, i8* %89, i64 0
%91 = load i8, i8* %90
%92 = zext i8 %91 to i32
%93 = icmp eq i32 %92, 24
br i1 %93, label %94, label %95
94: ; preds = %88, %82, %76
store i32 1, i32* %3
br label %163
95: ; preds = %88
store i32 0, i32* %11
%96 = load i32, i32* %14
%97 = icmp sge i32 %96, 6
br i1 %97, label %98, label %106
98: ; preds = %95
%99 = load i32, i32* %14
%100 = sub nsw i32 %99, 6
%101 = load i8*, i8** %5
%102 = getelementptr inbounds i8, i8* %101, i64 2
%103 = call i32 @getint(i8* %102)
%104 = icmp eq i32 %100, %103
br i1 %104, label %105, label %106
105: ; preds = %98
store i32 1, i32* %11
br label %106
106: ; preds = %105, %98, %95
store i32 0, i32* %12
%107 = call i32 @FD_ZERO(i32* %7)
%108 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 2, i32* %108
%109 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i32 560000, i32* %109
br label %110
110: ; preds = %154, %106
%111 = load i32, i32* %11
%112 = icmp eq i32 %111, 0
br i1 %112, label %113, label %155
113: ; preds = %110
%114 = load i32, i32* %4
%115 = call i32 @FD_SET(i32 %114, i32* %7)
%116 = load i32, i32* %13
%117 = call i32 @select(i32 %116, i32* %7, i32* null, i32* null, %struct.timeval* %8)
store i32 %117, i32* %9
%118 = load i32, i32* %4
%119 = call i64 @FD_ISSET(i32 %118, i32* %7)
%120 = icmp ne i64 %119, 0
br i1 %120, label %121, label %139
121: ; preds = %113
%122 = load i32, i32* %4
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%124 = call i32 @read(i32 %122, i8* %123, i32 1024)
store i32 %124, i32* %10
%125 = load i32, i32* %10
%126 = icmp sgt i32 %125, 0
br i1 %126, label %127, label %138
127: ; preds = %121
%128 = load i8*, i8** %5
%129 = load i32, i32* %14
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8, i8* %128, i64 %130
%132 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%133 = load i32, i32* %10
%134 = call i32 @memcpy(i8* %131, i8* %132, i32 %133)
%135 = load i32, i32* %10
%136 = load i32, i32* %14
%137 = add nsw i32 %136, %135
store i32 %137, i32* %14
br label %138
138: ; preds = %127, %121
br label %139
139: ; preds = %138, %113
%140 = load i32, i32* %9
%141 = icmp eq i32 %140, 0
br i1 %141, label %142, label %143
142: ; preds = %139
store i32 1, i32* %11
store i32 1, i32* %12
br label %143
143: ; preds = %142, %139
%144 = load i32, i32* %14
%145 = icmp sge i32 %144, 6
br i1 %145, label %146, label %154
146: ; preds = %143
%147 = load i32, i32* %14
%148 = sub nsw i32 %147, 6
%149 = load i8*, i8** %5
%150 = getelementptr inbounds i8, i8* %149, i64 2
%151 = call i32 @getint(i8* %150)
%152 = icmp eq i32 %148, %151
br i1 %152, label %153, label %154
153: ; preds = %146
store i32 1, i32* %11
br label %154
154: ; preds = %153, %146, %143
br label %110
155: ; preds = %110
%156 = load i8*, i8** %5
%157 = load i32, i32* %14
%158 = call i32 @checksum(i8* %156, i32 %157)
%159 = icmp eq i32 %158, 1
br i1 %159, label %160, label %162
160: ; preds = %155
%161 = load i32, i32* %14
store i32 %161, i32* %3
br label %163
162: ; preds = %155
store i32 -2, i32* %3
br label %163
163: ; preds = %162, %160, %94, %75
%164 = load i32, i32* %3
ret i32 %164
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @listen(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast %struct.timeval* %5 to i8*
%9 = add nsw i32 %0, 1
%10 = call i32 @FD_ZERO(i32* %4)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 2, i32* %11
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i32 560000, i32* %12
br label %13
13: ; preds = %2, %27
%14 = phi i32 [ 0, %2 ], [ %29, %27 ]
%15 = call i32 @FD_SET(i32 %0, i32* %4)
%16 = call i32 @select(i32 %9, i32* %4, i32* null, i32* null, %struct.timeval* %5)
%17 = call i64 @FD_ISSET(i32 %0, i32* %4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %13
%20 = call i32 @read(i32 %0, i8* %6, i32 1024)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i8, i8* %6
switch i8 %23, label %27 [
i8 -91, label %24
i8 24, label %24
i8 21, label %24
i8 6, label %24
]
24: ; preds = %22, %22, %22, %22
%25 = call i32 @memcpy(i8* %1, i8* %6, i32 %20)
%26 = icmp eq i32 %16, 0
br i1 %26, label %79, label %30
27: ; preds = %22, %19, %13
%28 = icmp eq i32 %16, 0
%29 = select i1 %28, i32 1, i32 %14
br i1 %28, label %30, label %13
30: ; preds = %27, %24
%31 = phi i32 [ %14, %24 ], [ %29, %27 ]
%32 = phi i32 [ %20, %24 ], [ 0, %27 ]
%33 = icmp eq i32 %31, 1
br i1 %33, label %79, label %34
34: ; preds = %30
%35 = load i8, i8* %1
switch i8 %35, label %36 [
i8 6, label %79
i8 21, label %79
i8 24, label %79
]
36: ; preds = %34
%37 = icmp sgt i32 %32, 5
br i1 %37, label %40, label %38
38: ; preds = %36
%39 = call i32 @FD_ZERO(i32* %4)
store i32 2, i32* %11
store i32 560000, i32* %12
br label %46
40: ; preds = %36
%41 = add nsw i32 %32, -6
%42 = getelementptr inbounds i8, i8* %1, i64 2
%43 = call i32 @getint(i8* %42)
%44 = icmp eq i32 %41, %43
%45 = call i32 @FD_ZERO(i32* %4)
store i32 2, i32* %11
store i32 560000, i32* %12
br i1 %44, label %74, label %46
46: ; preds = %38, %40
%47 = getelementptr inbounds i8, i8* %1, i64 2
br label %48
48: ; preds = %73, %46
%49 = phi i32 [ %32, %46 ], [ %63, %73 ]
%50 = call i32 @FD_SET(i32 %0, i32* %4)
%51 = call i32 @select(i32 %9, i32* %4, i32* null, i32* null, %struct.timeval* %5)
%52 = call i64 @FD_ISSET(i32 %0, i32* %4)
%53 = icmp eq i64 %52, 0
br i1 %53, label %62, label %54
54: ; preds = %48
%55 = call i32 @read(i32 %0, i8* %6, i32 1024)
%56 = icmp sgt i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = sext i32 %49 to i64
%59 = getelementptr inbounds i8, i8* %1, i64 %58
%60 = call i32 @memcpy(i8* %59, i8* %6, i32 %55)
%61 = add nsw i32 %55, %49
br label %62
62: ; preds = %54, %57, %48
%63 = phi i32 [ %61, %57 ], [ %49, %54 ], [ %49, %48 ]
%64 = icmp eq i32 %51, 0
%65 = icmp sgt i32 %63, 5
br i1 %65, label %66, label %72
66: ; preds = %62
%67 = add nsw i32 %63, -6
%68 = call i32 @getint(i8* %47)
%69 = icmp ne i32 %67, %68
%70 = xor i1 %64, true
%71 = select i1 %69, i1 %70, i1 false
br i1 %71, label %73, label %74
72: ; preds = %62
br i1 %64, label %74, label %73
73: ; preds = %72, %66
br label %48
74: ; preds = %66, %72, %40
%75 = phi i32 [ %32, %40 ], [ %63, %72 ], [ %63, %66 ]
%76 = call i32 @checksum(i8* %1, i32 %75)
%77 = icmp eq i32 %76, 1
%78 = select i1 %77, i32 %75, i32 -2
br label %79
79: ; preds = %24, %74, %34, %34, %34, %30
%80 = phi i32 [ -1, %30 ], [ 1, %34 ], [ 1, %34 ], [ 1, %34 ], [ %78, %74 ], [ -1, %24 ]
ret i32 %80
}