#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 dummy;
};
struct hostent {
  int dummy;
};
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ MSG_CONFIRM;
int /*<<< orphan*/ bzero(char *, int const);
int /*<<< orphan*/ close(int);
int connect_to_client(char *, struct sockaddr_in *, int /*<<< orphan*/,
                      struct hostent *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
size_t fread(char *, int, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
size_t select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
              int /*<<< orphan*/ *, struct timeval *);
size_t send(int, char *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int transferFile(int argc, char *client, char *filename, char *opts) {
  int sockfd, maxfd;
  size_t n, rt, retval;
  fd_set wfds;
  FILE *fp;
  struct timeval tv;
  const int BUFFER_SIZE = 500;
  struct sockaddr_in serv_addr;
  struct hostent server;
  char *local_opts;
  char buffer[BUFFER_SIZE];
  bzero(buffer, sizeof(buffer));
  if (filename == NULL) {
    fprintf(stderr, "File not found.\n");
    return -1;
  }
  if (opts != NULL) {
    local_opts = opts;
  } else {
    local_opts = "r";
  }
  printf("Connecting to %s\n", client);
  sockfd = connect_to_client(client, &serv_addr, 0, &server, &wfds);
  if (sockfd < 0) {
    perror("Exiting.");
    close(sockfd);
    return -1;
  }
  fp = fopen(filename, local_opts);
  if (!fp) {
    perror("Error opening file");
    fclose(fp);
    close(sockfd);
    return -1;
  }
  maxfd = sockfd + 1;
  FD_ZERO(&wfds);
  FD_SET(sockfd, &wfds);
  int i = 0;
  while (i++ < 1000) {
    bzero(buffer, BUFFER_SIZE);
    n = fread(buffer, 1, BUFFER_SIZE, fp);
    if (n == 0) {
      printf("EOF reached. CLosing stream.\n");
      fclose(fp);
      close(sockfd);
      return 0;
    }
    tv.tv_sec = 20;
    tv.tv_usec = 0;
    retval = select(maxfd, NULL, &wfds, NULL, &tv);
    if (retval == -1) {
      fclose(fp);
      perror("select()");
    } else if (retval) {
      rt = send(sockfd, buffer, n, MSG_CONFIRM);
      if (rt < 0)
        perror("ERROR reading from socket");
    } else {
      fclose(fp);
      perror("Timeout");
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<transferFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x1f4,-0x64(%rbp)
mov    %rsp,%rax
mov    %rax,-0x80(%rbp)
lea    -0x280(%rbp),%rdi
mov    $0x1f4,%esi
call   10e0 <bzero@plt>
cmpq   $0x0,-0x18(%rbp)
jne    123f <transferFile+0x6f>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    14a0 <transferFile+0x2d0>
cmpq   $0x0,-0x20(%rbp)
je     1257 <transferFile+0x87>
mov    -0x20(%rbp),%rax
mov    %rax,-0x78(%rbp)
jmp    1262 <transferFile+0x92>
lea    0xdb3(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x68(%rbp),%rsi
xor    %edx,%edx
lea    -0x70(%rbp),%rcx
lea    -0x44(%rbp),%r8
call   10b0 <connect_to_client@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12c2 <transferFile+0xf2>
lea    0xd86(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    14a0 <transferFile+0x2d0>
mov    -0x18(%rbp),%rdi
mov    -0x78(%rbp),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1311 <transferFile+0x141>
lea    0xd49(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    14a0 <transferFile+0x2d0>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
lea    -0x44(%rbp),%rdi
call   1090 <FD_ZERO@plt>
mov    -0x24(%rbp),%edi
lea    -0x44(%rbp),%rsi
call   10f0 <FD_SET@plt>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x88(%rbp)
cmp    $0x3e8,%eax
jge    148f <transferFile+0x2bf>
lea    -0x280(%rbp),%rdi
mov    $0x1f4,%esi
call   10e0 <bzero@plt>
mov    -0x50(%rbp),%rcx
lea    -0x280(%rbp),%rdi
mov    $0x1,%esi
mov    $0x1f4,%edx
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    13c4 <transferFile+0x1f4>
lea    0xcab(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    14a0 <transferFile+0x2d0>
movl   $0x14,-0x60(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x28(%rbp),%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x44(%rbp),%rdx
lea    -0x60(%rbp),%r8
mov    %rcx,%rsi
call   10a0 <select@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0xffffffffffffffff,-0x40(%rbp)
jne    1413 <transferFile+0x243>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xc56(%rip),%rdi
call   10d0 <perror@plt>
jmp    148a <transferFile+0x2ba>
cmpq   $0x0,-0x40(%rbp)
je     145a <transferFile+0x28a>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    0x2bbc(%rip),%rax
mov    (%rax),%ecx
lea    -0x280(%rbp),%rsi
call   1050 <send@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jae    1455 <transferFile+0x285>
lea    0xc18(%rip),%rdi
call   10d0 <perror@plt>
jmp    1485 <transferFile+0x2b5>
mov    -0x50(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xc18(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    14a0 <transferFile+0x2d0>
jmp    148a <transferFile+0x2ba>
jmp    1339 <transferFile+0x169>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transferFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rsp,%r13
lea    0x30(%rsp),%rdi
mov    $0x1f4,%esi
call   10f0 <bzero@plt>
test   %rbx,%rbx
je     1342 <transferFile+0x162>
lea    0xdf7(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rbp,%rdi
xor    %edx,%edx
call   10c0 <connect_to_client@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1396 <transferFile+0x1b6>
test   %r15,%r15
lea    0xdbd(%rip),%rsi
cmovne %r15,%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     13a4 <transferFile+0x1c4>
mov    %rax,%r12
mov    %r13,0x8(%rsp)
mov    %r14d,%ebp
add    $0x1,%ebp
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   10a0 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1100 <FD_SET@plt>
mov    $0x3e8,%r13d
lea    0x30(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1f4,%esi
call   10f0 <bzero@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1f4,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
test   %rax,%rax
je     135e <transferFile+0x17e>
mov    %rax,%r15
movl   $0x14,0x20(%rsp)
movq   $0x0,0x28(%rsp)
mov    %ebp,%edi
xor    %esi,%esi
lea    0x4(%rsp),%rdx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
call   10b0 <select@plt>
cmp    $0xffffffffffffffff,%rax
je     1322 <transferFile+0x142>
test   %rax,%rax
je     13c6 <transferFile+0x1e6>
mov    0x2cde(%rip),%rax
mov    (%rax),%ecx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <send@plt>
add    $0xffffffff,%r13d
jne    12a0 <transferFile+0xc0>
jmp    137a <transferFile+0x19a>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xd10(%rip),%rdi
call   10e0 <perror@plt>
add    $0xffffffff,%r13d
jne    12a0 <transferFile+0xc0>
jmp    137a <transferFile+0x19a>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
lea    0xcae(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1381 <transferFile+0x1a1>
lea    0xced(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %eax,%eax
mov    0x8(%rsp),%r13
mov    %r13,%rsp
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc88(%rip),%rdi
call   10e0 <perror@plt>
jmp    13b7 <transferFile+0x1d7>
lea    0xc83(%rip),%rdi
call   10e0 <perror@plt>
xor    %edi,%edi
call   1050 <fclose@plt>
mov    %r14d,%edi
call   1080 <close@plt>
mov    $0xffffffff,%eax
jmp    1381 <transferFile+0x1a1>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xc75(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%eax
jmp    137c <transferFile+0x19c>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.sockaddr_in = type { i32 }
%struct.hostent = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"File not found.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"Connecting to %s\0A\00"
@.str.3 = [9 x i8] c"Exiting.\00"
@.str.4 = [19 x i8] c"Error opening file\00"
@.str.5 = [30 x i8] c"EOF reached. CLosing stream.\0A\00"
@.str.6 = [9 x i8] c"select()\00"
@MSG_CONFIRM = global i32 0
@.str.7 = [26 x i8] c"ERROR reading from socket\00"
@.str.8 = [8 x i8] c"Timeout\00"
define i32 @transferFile(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32*
%17 = alloca %struct.timeval
%18 = alloca i32
%19 = alloca %struct.sockaddr_in
%20 = alloca %struct.hostent
%21 = alloca i8*
%22 = alloca i8*
%23 = alloca i32
%24 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 500, i32* %18
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %22
%26 = alloca i8, i64 500
%27 = call i32 @bzero(i8* %26, i32 500)
%28 = load i8*, i8** %8
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %4
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
store i32 1, i32* %23
br label %115
33: ; preds = %4
%34 = load i8*, i8** %9
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = load i8*, i8** %9
store i8* %37, i8** %21
br label %39
38: ; preds = %33
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %21
br label %39
39: ; preds = %38, %36
%40 = load i8*, i8** %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i8*, i8** %7
%43 = call i32 @connect_to_client(i8* %42, %struct.sockaddr_in* %19, i32 0, %struct.hostent* %20, i32* %15)
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %39
%47 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%48 = load i32, i32* %10
%49 = call i32 @close(i32 %48)
store i32 -1, i32* %5
store i32 1, i32* %23
br label %115
50: ; preds = %39
%51 = load i8*, i8** %8
%52 = load i8*, i8** %21
%53 = call i32* @fopen(i8* %51, i8* %52)
store i32* %53, i32** %16
%54 = load i32*, i32** %16
%55 = icmp ne i32* %54, null
br i1 %55, label %62, label %56
56: ; preds = %50
%57 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%58 = load i32*, i32** %16
%59 = call i32 @fclose(i32* %58)
%60 = load i32, i32* %10
%61 = call i32 @close(i32 %60)
store i32 -1, i32* %5
store i32 1, i32* %23
br label %115
62: ; preds = %50
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %11
%65 = call i32 @FD_ZERO(i32* %15)
%66 = load i32, i32* %10
%67 = call i32 @FD_SET(i32 %66, i32* %15)
store i32 0, i32* %24
br label %68
68: ; preds = %113, %62
%69 = load i32, i32* %24
%70 = add nsw i32 %69, 1
store i32 %70, i32* %24
%71 = icmp slt i32 %69, 1000
br i1 %71, label %72, label %114
72: ; preds = %68
%73 = call i32 @bzero(i8* %26, i32 500)
%74 = load i32*, i32** %16
%75 = call i64 @fread(i8* %26, i32 1, i32 500, i32* %74)
store i64 %75, i64* %12
%76 = load i64, i64* %12
%77 = icmp eq i64 %76, 0
br i1 %77, label %78, label %84
78: ; preds = %72
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%80 = load i32*, i32** %16
%81 = call i32 @fclose(i32* %80)
%82 = load i32, i32* %10
%83 = call i32 @close(i32 %82)
store i32 0, i32* %5
store i32 1, i32* %23
br label %115
84: ; preds = %72
%85 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
store i32 20, i32* %85
%86 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
store i64 0, i64* %86
%87 = load i32, i32* %11
%88 = call i64 @select(i32 %87, i32* null, i32* %15, i32* null, %struct.timeval* %17)
store i64 %88, i64* %14
%89 = load i64, i64* %14
%90 = icmp eq i64 %89, -1
br i1 %90, label %91, label %95
91: ; preds = %84
%92 = load i32*, i32** %16
%93 = call i32 @fclose(i32* %92)
%94 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %113
95: ; preds = %84
%96 = load i64, i64* %14
%97 = icmp ne i64 %96, 0
br i1 %97, label %98, label %108
98: ; preds = %95
%99 = load i32, i32* %10
%100 = load i64, i64* %12
%101 = load i32, i32* @MSG_CONFIRM
%102 = call i64 @send(i32 %99, i8* %26, i64 %100, i32 %101)
store i64 %102, i64* %13
%103 = load i64, i64* %13
%104 = icmp ult i64 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %98
%106 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
br label %107
107: ; preds = %105, %98
br label %112
108: ; preds = %95
%109 = load i32*, i32** %16
%110 = call i32 @fclose(i32* %109)
%111 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %5
store i32 1, i32* %23
br label %115
112: ; preds = %107
br label %113
113: ; preds = %112, %91
br label %68
114: ; preds = %68
store i32 0, i32* %5
store i32 1, i32* %23
br label %115
115: ; preds = %114, %108, %78, %56, %46, %30
%116 = load i8*, i8** %22
%117 = load i32, i32* %5
ret i32 %117
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.sockaddr_in = type { i32 }
%struct.hostent = type { i32 }
@stderr = global i32 0
@.str = [17 x i8] c"File not found.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"Connecting to %s\0A\00"
@.str.3 = [9 x i8] c"Exiting.\00"
@.str.4 = [19 x i8] c"Error opening file\00"
@.str.6 = [9 x i8] c"select()\00"
@MSG_CONFIRM = global i32 0
@.str.8 = [8 x i8] c"Timeout\00"
@str = [29 x i8] c"EOF reached. CLosing stream.\00"
define i32 @transferFile(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.hostent
%9 = bitcast i32* %5 to i8*
%10 = bitcast %struct.timeval* %6 to i8*
%11 = bitcast %struct.sockaddr_in* %7 to i8*
%12 = bitcast %struct.hostent* %8 to i8*
%13 = tail call i8* @llvm.stacksave()
%14 = alloca [500 x i8]
%15 = getelementptr inbounds [500 x i8], [500 x i8]* %14, i64 0, i64 0
%16 = call i32 @bzero(i8* %15, i32 500)
%17 = icmp eq i8* %2, null
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %66
21: ; preds = %4
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%23 = call i32 @connect_to_client(i8* %1, %struct.sockaddr_in* %7, i32 0, %struct.hostent* %8, i32* %5)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @close(i32 %23)
br label %66
28: ; preds = %21
%29 = icmp eq i8* %3, null
%30 = select i1 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %3
%31 = call i32* @fopen(i8* %2, i8* %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @fclose(i32* null)
%36 = call i32 @close(i32 %23)
br label %66
37: ; preds = %28
%38 = add nuw nsw i32 %23, 1
%39 = call i32 @FD_ZERO(i32* %5)
%40 = call i32 @FD_SET(i32 %23, i32* %5)
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
br label %43
43: ; preds = %37, %63
%44 = phi i32 [ 1, %37 ], [ %64, %63 ]
%45 = call i32 @bzero(i8* %15, i32 500)
%46 = call i64 @fread(i8* %15, i32 1, i32 500, i32* %31)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%50 = call i32 @fclose(i32* %31)
%51 = call i32 @close(i32 %23)
br label %66
52: ; preds = %43
store i32 20, i32* %41
store i64 0, i64* %42
%53 = call i64 @select(i32 %38, i32* null, i32* %5, i32* null, %struct.timeval* %6)
switch i64 %53, label %57 [
i64 -1, label %54
i64 0, label %60
]
54: ; preds = %52
%55 = call i32 @fclose(i32* %31)
%56 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %63
57: ; preds = %52
%58 = load i32, i32* @MSG_CONFIRM
%59 = call i64 @send(i32 %23, i8* %15, i64 %46, i32 %58)
br label %63
60: ; preds = %52
%61 = call i32 @fclose(i32* %31)
%62 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
br label %66
63: ; preds = %57, %54
%64 = add nuw nsw i32 %44, 1
%65 = icmp eq i32 %64, 1001
br i1 %65, label %66, label %43
66: ; preds = %63, %48, %60, %33, %25, %18
%67 = phi i32 [ -1, %18 ], [ -1, %25 ], [ -1, %33 ], [ 0, %48 ], [ 1, %60 ], [ 0, %63 ]
ret i32 %67
}