#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 timeval {
  int tv_usec;
  int tv_sec;
};
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*/ serv_addr;
typedef int /*<<< orphan*/ optval;
typedef int /*<<< orphan*/ cli_addr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ MSG_NOSIGNAL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd, newsockfd, clilen;
  struct sockaddr_in serv_addr, cli_addr;
  if (argc < 2) {
    printf("usage: %s <data file>\n", argv[0]);
    return 1;
  }
  char *datafile = argv[1];
again:
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  int optval = 1;
  if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) ==
      -1) {
    perror("setsockopt");
    return -1;
  }
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(5038);
  if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    error("ERROR on binding");
  listen(sockfd, 5);
  printf("Listening on port %d ...\n", 5038);
  clilen = sizeof(cli_addr);
  newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
  if (newsockfd < 0)
    error("ERROR on accept");
  int seq[5002];
  struct timeval tv;
  gettimeofday(&tv, NULL);
  srand(tv.tv_usec * tv.tv_sec);
  int rr;
  for (rr = 0; rr < 5000; rr++) {
    seq[rr] = rand();
    seq[rr] = seq[rr] % 2000;
    seq[rr]++;
  }
  seq[5001] = 0;
  printf("int seq[] = {");
  for (rr = 0; rr < 5001; rr++) {
    printf("%d, ", seq[rr]);
  }
  printf("};\n");
  seq[0] = 82;
  int seqn;
  char buf[4096];
  FILE *f;
  int rv;
  f = fopen(datafile, "r");
  if (f == NULL) {
    perror("fopen");
    return 1;
  }
  for (seqn = 0; seq[seqn] != 0; seqn++) {
    rv = fread(buf, 1, seq[seqn], f);
    if (rv <= 0) {
      perror("fread");
      break;
    }
    write(1, buf, rv);
    if (send(newsockfd, buf, rv, MSG_NOSIGNAL) < 0) {
      perror("send");
      break;
    }
    usleep(10000);
  }
  printf("\n\n");
  usleep(100000);
  close(newsockfd);
  close(sockfd);
  goto again;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x5e90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1274 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1603 <main+0x3d3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12b2 <main+0x82>
lea    0xd6a(%rip),%rdi
call   10e0 <error@plt>
movl   $0x1,-0x44(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d25(%rip),%rax
mov    (%rax),%esi
mov    0x2cec(%rip),%rax
mov    (%rax),%edx
lea    -0x44(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    12fe <main+0xce>
lea    0xd3f(%rip),%rdi
call   1100 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1603 <main+0x3d3>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cb9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x13ae,%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    1358 <main+0x128>
lea    0xce4(%rip),%rdi
call   10e0 <error@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
lea    0xcdc(%rip),%rdi
mov    $0x13ae,%esi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0xc,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    13a8 <main+0x178>
lea    0xcbf(%rip),%rdi
call   10e0 <error@plt>
lea    -0x4e78(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <gettimeofday@plt>
mov    -0x4e78(%rbp),%edi
imul   -0x4e74(%rbp),%edi
call   10b0 <srand@plt>
movl   $0x0,-0x4e7c(%rbp)
cmpl   $0x1388,-0x4e7c(%rbp)
jge    144b <main+0x21b>
mov    $0x0,%al
call   1130 <rand@plt>
mov    %eax,%ecx
movslq -0x4e7c(%rbp),%rax
mov    %ecx,-0x4e70(%rbp,%rax,4)
movslq -0x4e7c(%rbp),%rax
mov    -0x4e70(%rbp,%rax,4),%eax
mov    $0x7d0,%ecx
cltd
idiv   %ecx
movslq -0x4e7c(%rbp),%rax
mov    %edx,-0x4e70(%rbp,%rax,4)
movslq -0x4e7c(%rbp),%rax
mov    -0x4e70(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x4e70(%rbp,%rax,4)
mov    -0x4e7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e7c(%rbp)
jmp    13d4 <main+0x1a4>
movl   $0x0,-0x4c(%rbp)
lea    0xc19(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4e7c(%rbp)
cmpl   $0x1389,-0x4e7c(%rbp)
jge    14aa <main+0x27a>
movslq -0x4e7c(%rbp),%rax
mov    -0x4e70(%rbp,%rax,4),%esi
lea    0xbf1(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x4e7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e7c(%rbp)
jmp    146a <main+0x23a>
lea    0xbd4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x52,-0x4e70(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xbbc(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x5e88(%rbp)
cmpq   $0x0,-0x5e88(%rbp)
jne    14ff <main+0x2cf>
lea    0xb9d(%rip),%rdi
call   1100 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1603 <main+0x3d3>
movl   $0x0,-0x4e80(%rbp)
movslq -0x4e80(%rbp),%rax
cmpl   $0x0,-0x4e70(%rbp,%rax,4)
je     15d6 <main+0x3a6>
lea    -0x5e80(%rbp),%rdi
movslq -0x4e80(%rbp),%rax
mov    -0x4e70(%rbp,%rax,4),%edx
mov    -0x5e88(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x5e8c(%rbp)
cmpl   $0x0,-0x5e8c(%rbp)
jg     1568 <main+0x338>
lea    0xb33(%rip),%rdi
call   1100 <perror@plt>
jmp    15d6 <main+0x3a6>
lea    -0x5e80(%rbp),%rsi
mov    -0x5e8c(%rbp),%edx
mov    $0x1,%edi
call   1050 <write@plt>
mov    -0x18(%rbp),%edi
lea    -0x5e80(%rbp),%rsi
mov    -0x5e8c(%rbp),%edx
mov    0x2a2a(%rip),%rax
mov    (%rax),%ecx
call   1070 <send@plt>
cmp    $0x0,%rax
jge    15b8 <main+0x388>
lea    0xae9(%rip),%rdi
call   1100 <perror@plt>
jmp    15d6 <main+0x3a6>
mov    $0x2710,%edi
call   1140 <usleep@plt>
mov    -0x4e80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4e80(%rbp)
jmp    1509 <main+0x2d9>
lea    0xabf(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x186a0,%edi
call   1140 <usleep@plt>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
jmp    1280 <main+0x50>
mov    -0x4(%rbp),%eax
add    $0x5e90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5e78,%rsp
cmp    $0x1,%edi
jg     127e <main+0x3e>
mov    (%rsi),%rsi
lea    0xda0(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%eax
add    $0x5e78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsi),%rax
mov    %rax,0x28(%rsp)
mov    0x2d52(%rip),%r15
lea    0xdeb(%rip),%r14
lea    0x4e70(%rsp),%rbp
jmp    12de <main+0x9e>
lea    0xde7(%rip),%rdi
call   1110 <perror@plt>
nopl   0x0(%rax,%rax,1)
lea    0xda9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x186a0,%edi
call   1150 <usleep@plt>
mov    %r13d,%edi
call   10b0 <close@plt>
mov    0x4(%rsp),%edi
call   10b0 <close@plt>
mov    0x2d02(%rip),%r15
mov    (%r15),%edi
mov    0x2ce0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    1304 <main+0xc4>
lea    0xd18(%rip),%rdi
call   10f0 <error@plt>
movl   $0x1,0x8(%rsp)
mov    0x2cd5(%rip),%rax
mov    (%rax),%esi
mov    0x2c9c(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
lea    0x8(%rsp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     152a <main+0x2ea>
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x20(%rsp)
mov    0x2c7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    $0x13ae,%edi
call   1070 <htons@plt>
mov    %eax,0x18(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
jns    138f <main+0x14f>
lea    0xcad(%rip),%rdi
call   10f0 <error@plt>
mov    %r12d,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
lea    0xca5(%rip),%rdi
mov    $0x13ae,%esi
xor    %eax,%eax
call   1090 <printf@plt>
movl   $0xc,0xc(%rsp)
mov    %r12d,%edi
lea    0x30(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1130 <accept@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    13dc <main+0x19c>
lea    0xc8b(%rip),%rdi
call   10f0 <error@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   10a0 <gettimeofday@plt>
mov    0x14(%rsp),%edi
imul   0x10(%rsp),%edi
call   10c0 <srand@plt>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1140 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x27,%rcx
add    %edx,%ecx
imul   $0x7d0,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,0x40(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x1388,%rbx
jne    1400 <main+0x1c0>
mov    %r12d,0x4(%rsp)
movl   $0x0,0x4e64(%rsp)
lea    0xc20(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x40(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
add    $0x1,%rbx
cmp    $0x1389,%rbx
jne    1460 <main+0x220>
lea    0xc16(%rip),%rdi
call   1030 <puts@plt>
movl   $0x52,0x40(%rsp)
mov    0x28(%rsp),%rdi
lea    0xbea(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     1540 <main+0x300>
mov    %rax,%r12
mov    $0x52,%edx
lea    0x44(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r12,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    129f <main+0x5f>
mov    %eax,%ebx
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1060 <write@plt>
mov    0x2ad0(%rip),%rax
mov    (%rax),%ecx
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1080 <send@plt>
test   %rax,%rax
js     151e <main+0x2de>
mov    $0x2710,%edi
call   1150 <usleep@plt>
mov    (%r15),%edx
add    $0x4,%r15
test   %edx,%edx
jne    14c0 <main+0x280>
jmp    12b0 <main+0x70>
lea    0xb6e(%rip),%rdi
jmp    12a6 <main+0x66>
lea    0xafb(%rip),%rdi
call   1110 <perror@plt>
mov    $0xffffffff,%eax
jmp    126c <main+0x2c>
lea    0xb40(%rip),%rdi
call   1110 <perror@plt>
jmp    1267 <main+0x27>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"usage: %s <data file>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [11 x i8] c"setsockopt\00"
@INADDR_ANY = global i32 0
@.str.3 = [17 x i8] c"ERROR on binding\00"
@.str.4 = [26 x i8] c"Listening on port %d ...\0A\00"
@.str.5 = [16 x i8] c"ERROR on accept\00"
@.str.6 = [14 x i8] c"int seq[] = {\00"
@.str.7 = [5 x i8] c"%d, \00"
@.str.8 = [4 x i8] c"};\0A\00"
@.str.9 = [2 x i8] c"r\00"
@.str.10 = [6 x i8] c"fopen\00"
@.str.11 = [6 x i8] c"fread\00"
@MSG_NOSIGNAL = global i32 0
@.str.12 = [5 x i8] c"send\00"
@.str.13 = [3 x i8] c"\0A\0A\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 i32
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca i8*
%12 = alloca i32
%13 = alloca [5002 x i32]
%14 = alloca %struct.timeval
%15 = alloca i32
%16 = alloca i32
%17 = alloca [4096 x i8]
%18 = alloca i32*
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 1, i32* %3
br label %173
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
store i8* %30, i8** %11
br label %31
31: ; preds = %166, %27
%32 = load i32, i32* @AF_INET
%33 = load i32, i32* @SOCK_STREAM
%34 = call i32 @socket(i32 %32, i32 %33, i32 0)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %31
store i32 1, i32* %12
%40 = load i32, i32* %6
%41 = load i32, i32* @SOL_SOCKET
%42 = load i32, i32* @SO_REUSEADDR
%43 = call i32 @setsockopt(i32 %40, i32 %41, i32 %42, i32* %12, i32 4)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %173
47: ; preds = %39
%48 = bitcast %struct.sockaddr_in* %9 to i8*
%49 = call i32 @bzero(i8* %48, i32 12)
%50 = load i32, i32* @AF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %50, i32* %51
%52 = load i32, i32* @INADDR_ANY
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %53, i32 0, i32 0
store i32 %52, i32* %54
%55 = call i32 @htons(i32 5038)
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %55, i32* %56
%57 = load i32, i32* %6
%58 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%59 = call i64 @bind(i32 %57, %struct.sockaddr* %58, i32 12)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %47
%62 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %63
63: ; preds = %61, %47
%64 = load i32, i32* %6
%65 = call i32 @listen(i32 %64, i32 5)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 5038)
store i32 12, i32* %8
%67 = load i32, i32* %6
%68 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%69 = call i32 @accept(i32 %67, %struct.sockaddr* %68, i32* %8)
store i32 %69, i32* %7
%70 = load i32, i32* %7
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %63
%73 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %74
74: ; preds = %72, %63
%75 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%76 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%77 = load i32, i32* %76
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%79 = load i32, i32* %78
%80 = mul nsw i32 %77, %79
%81 = call i32 @srand(i32 %80)
store i32 0, i32* %15
br label %82
82: ; preds = %103, %74
%83 = load i32, i32* %15
%84 = icmp slt i32 %83, 5000
br i1 %84, label %85, label %106
85: ; preds = %82
%86 = call i32 (...) @rand()
%87 = load i32, i32* %15
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [5002 x i32], [5002 x i32]* %13, i64 0, i64 %88
store i32 %86, i32* %89
%90 = load i32, i32* %15
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [5002 x i32], [5002 x i32]* %13, i64 0, i64 %91
%93 = load i32, i32* %92
%94 = srem i32 %93, 2000
%95 = load i32, i32* %15
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [5002 x i32], [5002 x i32]* %13, i64 0, i64 %96
store i32 %94, i32* %97
%98 = load i32, i32* %15
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [5002 x i32], [5002 x i32]* %13, i64 0, i64 %99
%101 = load i32, i32* %100
%102 = add nsw i32 %101, 1
store i32 %102, i32* %100
br label %103
103: ; preds = %85
%104 = load i32, i32* %15
%105 = add nsw i32 %104, 1
store i32 %105, i32* %15
br label %82
106: ; preds = %82
%107 = getelementptr inbounds [5002 x i32], [5002 x i32]* %13, i64 0, i64 5001
store i32 0, i32* %107
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %15
br label %109
109: ; preds = %118, %106
%110 = load i32, i32* %15
%111 = icmp slt i32 %110, 5001
br i1 %111, label %112, label %121
112: ; preds = %109
%113 = load i32, i32* %15
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [5002 x i32], [5002 x i32]* %13, i64 0, i64 %114
%116 = load i32, i32* %115
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %116)
br label %118
118: ; preds = %112
%119 = load i32, i32* %15
%120 = add nsw i32 %119, 1
store i32 %120, i32* %15
br label %109
121: ; preds = %109
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%123 = getelementptr inbounds [5002 x i32], [5002 x i32]* %13, i64 0, i64 0
store i32 82, i32* %123
%124 = load i8*, i8** %11
%125 = call i32* @fopen(i8* %124, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %125, i32** %18
%126 = load i32*, i32** %18
%127 = icmp eq i32* %126, null
br i1 %127, label %128, label %130
128: ; preds = %121
%129 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %173
130: ; preds = %121
store i32 0, i32* %16
br label %131
131: ; preds = %163, %130
%132 = load i32, i32* %16
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds [5002 x i32], [5002 x i32]* %13, i64 0, i64 %133
%135 = load i32, i32* %134
%136 = icmp ne i32 %135, 0
br i1 %136, label %137, label %166
137: ; preds = %131
%138 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%139 = load i32, i32* %16
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds [5002 x i32], [5002 x i32]* %13, i64 0, i64 %140
%142 = load i32, i32* %141
%143 = load i32*, i32** %18
%144 = call i32 @fread(i8* %138, i32 1, i32 %142, i32* %143)
store i32 %144, i32* %19
%145 = load i32, i32* %19
%146 = icmp sle i32 %145, 0
br i1 %146, label %147, label %149
147: ; preds = %137
%148 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
br label %166
149: ; preds = %137
%150 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%151 = load i32, i32* %19
%152 = call i32 @write(i32 1, i8* %150, i32 %151)
%153 = load i32, i32* %7
%154 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%155 = load i32, i32* %19
%156 = load i32, i32* @MSG_NOSIGNAL
%157 = call i64 @send(i32 %153, i8* %154, i32 %155, i32 %156)
%158 = icmp slt i64 %157, 0
br i1 %158, label %159, label %161
159: ; preds = %149
%160 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %166
161: ; preds = %149
%162 = call i32 @usleep(i32 10000)
br label %163
163: ; preds = %161
%164 = load i32, i32* %16
%165 = add nsw i32 %164, 1
store i32 %165, i32* %16
br label %131
166: ; preds = %159, %147, %131
%167 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
%168 = call i32 @usleep(i32 100000)
%169 = load i32, i32* %7
%170 = call i32 @close(i32 %169)
%171 = load i32, i32* %6
%172 = call i32 @close(i32 %171)
br label %31
173: ; preds = %128, %45, %22
%174 = load i32, i32* %3
ret i32 %174
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [23 x i8] c"usage: %s <data file>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [11 x i8] c"setsockopt\00"
@INADDR_ANY = global i32 0
@.str.3 = [17 x i8] c"ERROR on binding\00"
@.str.4 = [26 x i8] c"Listening on port %d ...\0A\00"
@.str.5 = [16 x i8] c"ERROR on accept\00"
@.str.6 = [14 x i8] c"int seq[] = {\00"
@.str.7 = [5 x i8] c"%d, \00"
@.str.9 = [2 x i8] c"r\00"
@.str.10 = [6 x i8] c"fopen\00"
@.str.11 = [6 x i8] c"fread\00"
@MSG_NOSIGNAL = global i32 0
@.str.12 = [5 x i8] c"send\00"
@str = [3 x i8] c"};\00"
@str.14 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca [5002 x i32]
%8 = alloca %struct.timeval
%9 = alloca [4096 x i8]
%10 = bitcast i32* %3 to i8*
%11 = bitcast %struct.sockaddr_in* %4 to i8*
%12 = bitcast %struct.sockaddr_in* %5 to i8*
%13 = icmp slt i32 %0, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %1
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %113
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%23 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%24 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
%27 = getelementptr inbounds [5002 x i32], [5002 x i32]* %7, i64 0, i64 5001
%28 = getelementptr inbounds [5002 x i32], [5002 x i32]* %7, i64 0, i64 0
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
br label %30
30: ; preds = %108, %17
%31 = load i32, i32* @AF_INET
%32 = load i32, i32* @SOCK_STREAM
%33 = call i32 @socket(i32 %31, i32 %32, i32 0)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %30
store i32 1, i32* %6
%38 = load i32, i32* @SOL_SOCKET
%39 = load i32, i32* @SO_REUSEADDR
%40 = call i32 @setsockopt(i32 %33, i32 %38, i32 %39, i32* %6, i32 4)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %113
44: ; preds = %37
%45 = call i32 @bzero(i8* %11, i32 12)
%46 = load i32, i32* @AF_INET
store i32 %46, i32* %20
%47 = load i32, i32* @INADDR_ANY
store i32 %47, i32* %21
%48 = call i32 @htons(i32 5038)
store i32 %48, i32* %22
%49 = call i64 @bind(i32 %33, %struct.sockaddr* %23, i32 12)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %44
%52 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %51, %44
%54 = call i32 @listen(i32 %33, i32 5)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 5038)
store i32 12, i32* %3
%56 = call i32 @accept(i32 %33, %struct.sockaddr* %24, i32* %3)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %60
60: ; preds = %58, %53
%61 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%62 = load i32, i32* %25
%63 = load i32, i32* %26
%64 = mul nsw i32 %63, %62
%65 = call i32 @srand(i32 %64)
br label %66
66: ; preds = %60, %66
%67 = phi i64 [ 0, %60 ], [ %72, %66 ]
%68 = call i32 (...) @rand()
%69 = getelementptr inbounds [5002 x i32], [5002 x i32]* %7, i64 0, i64 %67
%70 = srem i32 %68, 2000
%71 = add nsw i32 %70, 1
store i32 %71, i32* %69
%72 = add nuw nsw i64 %67, 1
%73 = icmp eq i64 %72, 5000
br i1 %73, label %74, label %66
74: ; preds = %66
store i32 0, i32* %27
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %76
76: ; preds = %74, %76
%77 = phi i64 [ 0, %74 ], [ %81, %76 ]
%78 = getelementptr inbounds [5002 x i32], [5002 x i32]* %7, i64 0, i64 %77
%79 = load i32, i32* %78
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %79)
%81 = add nuw nsw i64 %77, 1
%82 = icmp eq i64 %81, 5001
br i1 %82, label %83, label %76
83: ; preds = %76
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
store i32 82, i32* %28
%85 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%86 = icmp eq i32* %85, null
br i1 %86, label %87, label %89
87: ; preds = %83
%88 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %113
89: ; preds = %83, %99
%90 = phi i64 [ %101, %99 ], [ 0, %83 ]
%91 = phi i32 [ %103, %99 ], [ 82, %83 ]
%92 = call i32 @fread(i8* %29, i32 1, i32 %91, i32* %85)
%93 = icmp slt i32 %92, 1
br i1 %93, label %105, label %94
94: ; preds = %89
%95 = call i32 @write(i32 1, i8* %29, i32 %92)
%96 = load i32, i32* @MSG_NOSIGNAL
%97 = call i64 @send(i32 %56, i8* %29, i32 %92, i32 %96)
%98 = icmp slt i64 %97, 0
br i1 %98, label %105, label %99
99: ; preds = %94
%100 = call i32 @usleep(i32 10000)
%101 = add nuw i64 %90, 1
%102 = getelementptr inbounds [5002 x i32], [5002 x i32]* %7, i64 0, i64 %101
%103 = load i32, i32* %102
%104 = icmp eq i32 %103, 0
br i1 %104, label %108, label %89
105: ; preds = %94, %89
%106 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), %89 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), %94 ]
%107 = call i32 @perror(i8* %106)
br label %108
108: ; preds = %99, %105
%109 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.14, i64 0, i64 0))
%110 = call i32 @usleep(i32 100000)
%111 = call i32 @close(i32 %56)
%112 = call i32 @close(i32 %33)
br label %30
113: ; preds = %42, %87, %14
%114 = phi i32 [ 1, %14 ], [ -1, %42 ], [ 1, %87 ]
ret i32 %114
}