#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 {
  double tv_usec;
  scalar_t__ tv_sec;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int off_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int sendfile(int, int, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char *buffer;
  char hname[128] = "localhost", infile[128] = "./infile";
  int rc, fd1, sd, j, k, size, nbuf, nchunk = 1, nrep = 10, which = 0;
  struct sockaddr_in addr;
  struct hostent *hostent;
  struct timeval tv1, tv2;
  double io_time = 0;
  if (argc < 2) {
    fprintf(stderr,
            "USAGE: %s on | off "
            "[infile] [hostname] [nchunks] [nreps]",
            argv[0]);
    exit(-1);
  }
  if (!strncmp(argv[1], "on", 2))
    which = 1;
  if (argc > 2)
    strcpy(infile, argv[2]);
  if (argc > 3)
    strcpy(hname, argv[3]);
  if (argc > 4)
    nchunk = atoi(argv[4]);
  if (argc > 5)
    nrep = atoi(argv[5]);
  fd1 = open(infile, O_RDONLY);
  size = (int)lseek(fd1, 0, SEEK_END);
  close(fd1);
  nbuf = (size - 1) / nchunk + 1;
  buffer = malloc(nbuf);
  printf("Input file: %s,  Size: %d, Chunks: %d, Bytes: %d \n", infile, size,
         nchunk, nbuf);
  hostent = gethostbyname(hname);
  addr.sin_family = AF_INET;
  addr.sin_port = htons(7177);
  memcpy(&addr.sin_addr, hostent->h_addr, hostent->h_length);
  printf("Doing iteration:");
  for (k = 0; k < nrep; k++) {
    printf("%4d", k + 1);
    fflush(stdout);
    fd1 = open(infile, O_RDONLY);
    sd = socket(PF_INET, SOCK_STREAM, 0);
    connect(sd, (struct sockaddr *)&addr, sizeof(addr));
    gettimeofday(&tv1, NULL);
    for (j = 0; j < nchunk; j++) {
      if (which == 0) {
        rc = read(fd1, buffer, nbuf);
        write(sd, buffer, rc);
      } else {
        off_t offset = j * nbuf;
        rc = sendfile(sd, fd1, &offset, nbuf);
      }
    }
    gettimeofday(&tv2, NULL);
    io_time += ((double)((tv2.tv_sec - tv1.tv_sec) +
                         .000001 * (tv2.tv_usec - tv1.tv_usec)));
    close(fd1);
    close(sd);
  }
  if (which == 0)
    fprintf(stderr, "\nDONE, Did Not Use sendfile()");
  else
    fprintf(stderr, "\nDONE, Did     Use sendfile()");
  printf("\n Total time spent in I/O = %f seconds\n", io_time);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xda9(%rip),%rsi
mov    $0x80,%edx
call   10e0 <memcpy@plt>
lea    -0x120(%rbp),%rdi
lea    0xe11(%rip),%rsi
mov    $0x80,%edx
call   10e0 <memcpy@plt>
movl   $0x1,-0x140(%rbp)
movl   $0xa,-0x144(%rbp)
movl   $0x0,-0x148(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x188(%rbp)
ff
cmpl   $0x2,-0x8(%rbp)
jge    12e4 <main+0xa4>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1140 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe56(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1310 <main+0xd0>
movl   $0x1,-0x148(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    132e <main+0xee>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <strcpy@plt>
cmpl   $0x3,-0x8(%rbp)
jle    134c <main+0x10c>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1040 <strcpy@plt>
cmpl   $0x4,-0x8(%rbp)
jle    1369 <main+0x129>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x140(%rbp)
cmpl   $0x5,-0x8(%rbp)
jle    1386 <main+0x146>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x144(%rbp)
lea    -0x120(%rbp),%rdi
mov    0x2c44(%rip),%rax
mov    (%rax),%esi
call   1120 <open@plt>
mov    %eax,-0x128(%rbp)
mov    -0x128(%rbp),%edi
mov    0x2c3a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <lseek@plt>
mov    %eax,-0x138(%rbp)
mov    -0x128(%rbp),%edi
call   10a0 <close@plt>
mov    -0x138(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0x140(%rbp)
add    $0x1,%eax
mov    %eax,-0x13c(%rbp)
mov    -0x13c(%rbp),%edi
call   10f0 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    -0x120(%rbp),%rsi
mov    -0x138(%rbp),%edx
mov    -0x140(%rbp),%ecx
mov    -0x13c(%rbp),%r8d
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xa0(%rbp),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x160(%rbp)
mov    0x2bae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
mov    $0x1c09,%edi
call   1060 <htons@plt>
mov    %eax,-0x154(%rbp)
lea    -0x158(%rbp),%rdi
mov    -0x160(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x160(%rbp),%rax
mov    (%rax),%edx
call   10e0 <memcpy@plt>
lea    0xd0f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x134(%rbp)
mov    -0x134(%rbp),%eax
cmp    -0x144(%rbp),%eax
jge    1644 <main+0x404>
mov    -0x134(%rbp),%esi
add    $0x1,%esi
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2aff(%rip),%rax
mov    (%rax),%edi
call   1100 <fflush@plt>
lea    -0x120(%rbp),%rdi
mov    0x2b12(%rip),%rax
mov    (%rax),%esi
call   1120 <open@plt>
mov    %eax,-0x128(%rbp)
mov    0x2ade(%rip),%rax
mov    (%rax),%edi
mov    0x2add(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x12c(%rbp)
mov    -0x12c(%rbp),%edi
lea    -0x158(%rbp),%rsi
mov    $0xc,%edx
call   1150 <connect@plt>
lea    -0x170(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <gettimeofday@plt>
movl   $0x0,-0x130(%rbp)
mov    -0x130(%rbp),%eax
cmp    -0x140(%rbp),%eax
jge    15c7 <main+0x387>
cmpl   $0x0,-0x148(%rbp)
jne    1577 <main+0x337>
mov    -0x128(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x13c(%rbp),%edx
call   10b0 <read@plt>
mov    %eax,-0x124(%rbp)
mov    -0x12c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   1050 <write@plt>
jmp    15ae <main+0x36e>
mov    -0x130(%rbp),%eax
imul   -0x13c(%rbp),%eax
mov    %eax,-0x18c(%rbp)
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%esi
mov    -0x13c(%rbp),%ecx
lea    -0x18c(%rbp),%rdx
call   1110 <sendfile@plt>
mov    %eax,-0x124(%rbp)
jmp    15b3 <main+0x373>
mov    -0x130(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x130(%rbp)
jmp    1523 <main+0x2e3>
lea    -0x180(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <gettimeofday@plt>
mov    -0x178(%rbp),%rax
sub    -0x168(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  -0x180(%rbp),%xmm0
ff
subsd  -0x170(%rbp),%xmm0
ff
movsd  0x9fe(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x188(%rbp),%xmm0
ff
movsd  %xmm0,-0x188(%rbp)
ff
mov    -0x128(%rbp),%edi
call   10a0 <close@plt>
mov    -0x12c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    1481 <main+0x241>
cmpl   $0x0,-0x148(%rbp)
jne    166d <main+0x42d>
mov    0x2970(%rip),%rax
mov    (%rax),%edi
lea    0xb33(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
jmp    1684 <main+0x444>
mov    0x2954(%rip),%rax
mov    (%rax),%edi
lea    0xb35(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
movsd  -0x188(%rbp),%xmm0
ff
lea    0xb3d(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    0x2907(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    %rsi,%rbx
movaps 0xe25(%rip),%xmm0
movaps %xmm0,0x140(%rsp)
movaps 0xe06(%rip),%xmm0
movaps %xmm0,0x130(%rsp)
movaps 0xde7(%rip),%xmm0
movaps %xmm0,0x120(%rsp)
movaps 0xdc8(%rip),%xmm0
movaps %xmm0,0x110(%rsp)
movaps 0xda9(%rip),%xmm0
movaps %xmm0,0x100(%rsp)
movaps 0xd8a(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movaps 0xd6b(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xd4c(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xe2d(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xe0e(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xdef(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xdd0(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xdb1(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xd92(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xd76(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movapd 0xd59(%rip),%xmm0
movapd %xmm0,0x50(%rsp)
cmp    $0x1,%edi
jg     1366 <main+0x126>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdbb(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1140 <exit@plt>
mov    %edi,%ebp
mov    0x8(%rbx),%rdi
lea    0xdd6(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    %eax,0xc(%rsp)
movl   $0xa,0x8(%rsp)
movl   $0x1,0x4(%rsp)
cmp    $0x2,%ebp
je     13de <main+0x19e>
mov    0x10(%rbx),%rsi
lea    0x50(%rsp),%rdi
call   1040 <strcpy@plt>
cmp    $0x4,%ebp
jb     13de <main+0x19e>
mov    0x18(%rbx),%rsi
lea    0xd0(%rsp),%rdi
call   1040 <strcpy@plt>
cmp    $0x4,%ebp
je     13de <main+0x19e>
mov    0x20(%rbx),%rdi
call   1130 <atoi@plt>
mov    %eax,0x4(%rsp)
cmp    $0x6,%ebp
jb     13de <main+0x19e>
mov    0x28(%rbx),%rdi
call   1130 <atoi@plt>
mov    %eax,0x8(%rsp)
mov    0x2bf3(%rip),%rax
mov    (%rax),%esi
lea    0x50(%rsp),%r14
mov    %r14,%rdi
call   1120 <open@plt>
mov    %eax,%ebx
mov    0x2beb(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1080 <lseek@plt>
mov    %rax,%r15
mov    %ebx,%edi
call   10a0 <close@plt>
lea    -0x1(%r15),%eax
cltd
mov    0x4(%rsp),%r12d
idiv   %r12d
mov    %eax,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
lea    0xd17(%rip),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %r12d,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd0(%rsp),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,%r14
mov    0x2b81(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    $0x1c09,%edi
call   1060 <htons@plt>
mov    %eax,0x24(%rsp)
mov    (%r14),%edx
mov    0x4(%r14),%esi
lea    0x20(%rsp),%rdi
call   10e0 <memcpy@plt>
lea    0xcf4(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
cmpl   $0x0,0x8(%rsp)
jle    15f7 <main+0x3b7>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %esi,%esi
jmp    1524 <main+0x2e4>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
mov    0x38(%rsp),%rax
sub    0x48(%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x30(%rsp),%xmm1
subsd  0x40(%rsp),%xmm1
mulsd  0xb0e(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
mov    0x18(%rsp),%esi
cmp    0x8(%rsp),%esi
je     15f7 <main+0x3b7>
add    $0x1,%esi
lea    0xc62(%rip),%rdi
mov    %esi,0x18(%rsp)
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2a70(%rip),%rax
mov    (%rax),%edi
call   1100 <fflush@plt>
mov    0x2a8a(%rip),%rax
mov    (%rax),%esi
lea    0x50(%rsp),%rdi
call   1120 <open@plt>
mov    %eax,%r15d
mov    0x2a54(%rip),%rax
mov    (%rax),%edi
mov    0x2a53(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,%r13d
mov    %eax,%edi
lea    0x20(%rsp),%rsi
mov    $0xc,%edx
call   1150 <connect@plt>
lea    0x40(%rsp),%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
cmpl   $0x0,0x4(%rsp)
jle    14c0 <main+0x280>
xor    %r14d,%r14d
mov    0x4(%rsp),%r12d
jmp    15d4 <main+0x394>
nopl   0x0(%rax,%rax,1)
mov    %r14d,0x1c(%rsp)
mov    %r13d,%edi
mov    %r15d,%esi
lea    0x1c(%rsp),%rdx
mov    %ebp,%ecx
call   1110 <sendfile@plt>
add    %ebp,%r14d
add    $0xffffffff,%r12d
je     14c0 <main+0x280>
cmpl   $0x0,0xc(%rsp)
je     15b0 <main+0x370>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   10b0 <read@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
jmp    15c7 <main+0x387>
cmpl   $0x0,0xc(%rsp)
mov    0x29c5(%rip),%rax
mov    (%rax),%edi
lea    0xba6(%rip),%rax
lea    0xb81(%rip),%rsi
cmove  %rax,%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
lea    0xbab(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1070 <printf@plt>
mov    0x296f(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.timeval = type { double, i64 }
%struct.sockaddr = type { i32 }
@__const.main.hname = [128 x i8] c"localhost\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.infile = [128 x i8] c"./infile\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [57 x i8] c"USAGE: %s on | off [infile] [hostname] [nchunks] [nreps]\00"
@.str.1 = [3 x i8] c"on\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@.str.2 = [51 x i8] c"Input file: %s, Size: %d, Chunks: %d, Bytes: %d \0A\00"
@AF_INET = global i32 0
@.str.3 = [17 x i8] c"Doing iteration:\00"
@.str.4 = [4 x i8] c"%4d\00"
@stdout = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [30 x i8] c"\0ADONE, Did Not Use sendfile()\00"
@.str.6 = [30 x i8] c"\0ADONE, Did Use sendfile()\00"
@.str.7 = [40 x i8] c"\0A Total time spent in I/O = %f seconds\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [128 x i8]
%8 = alloca [128 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca %struct.sockaddr_in
%20 = alloca %struct.hostent*
%21 = alloca %struct.timeval
%22 = alloca %struct.timeval
%23 = alloca double
%24 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%25 = bitcast [128 x i8]* %7 to i8*
%26 = bitcast [128 x i8]* %8 to i8*
store i32 1, i32* %16
store i32 10, i32* %17
store i32 0, i32* %18
store double 0.000000e+00, double* %23
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 2
br i1 %28, label %29, label %36
29: ; preds = %2
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %2
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @strncmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %36
store i32 1, i32* %18
br label %43
43: ; preds = %42, %36
%44 = load i32, i32* %4
%45 = icmp sgt i32 %44, 2
br i1 %45, label %46, label %52
46: ; preds = %43
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @strcpy(i8* %47, i8* %50)
br label %52
52: ; preds = %46, %43
%53 = load i32, i32* %4
%54 = icmp sgt i32 %53, 3
br i1 %54, label %55, label %61
55: ; preds = %52
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 3
%59 = load i8*, i8** %58
%60 = call i32 @strcpy(i8* %56, i8* %59)
br label %61
61: ; preds = %55, %52
%62 = load i32, i32* %4
%63 = icmp sgt i32 %62, 4
br i1 %63, label %64, label %69
64: ; preds = %61
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 4
%67 = load i8*, i8** %66
%68 = call i32 @atoi(i8* %67)
store i32 %68, i32* %16
br label %69
69: ; preds = %64, %61
%70 = load i32, i32* %4
%71 = icmp sgt i32 %70, 5
br i1 %71, label %72, label %77
72: ; preds = %69
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 5
%75 = load i8*, i8** %74
%76 = call i32 @atoi(i8* %75)
store i32 %76, i32* %17
br label %77
77: ; preds = %72, %69
%78 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%79 = load i32, i32* @O_RDONLY
%80 = call i32 @open(i8* %78, i32 %79)
store i32 %80, i32* %10
%81 = load i32, i32* %10
%82 = load i32, i32* @SEEK_END
%83 = call i64 @lseek(i32 %81, i32 0, i32 %82)
%84 = trunc i64 %83 to i32
store i32 %84, i32* %14
%85 = load i32, i32* %10
%86 = call i32 @close(i32 %85)
%87 = load i32, i32* %14
%88 = sub nsw i32 %87, 1
%89 = load i32, i32* %16
%90 = sdiv i32 %88, %89
%91 = add nsw i32 %90, 1
store i32 %91, i32* %15
%92 = load i32, i32* %15
%93 = call i8* @malloc(i32 %92)
store i8* %93, i8** %6
%94 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%95 = load i32, i32* %14
%96 = load i32, i32* %16
%97 = load i32, i32* %15
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %94, i32 %95, i32 %96, i32 %97)
%99 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%100 = call %struct.hostent* @gethostbyname(i8* %99)
store %struct.hostent* %100, %struct.hostent** %20
%101 = load i32, i32* @AF_INET
%102 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 2
store i32 %101, i32* %102
%103 = call i32 @htons(i32 7177)
%104 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 1
store i32 %103, i32* %104
%105 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
%106 = load %struct.hostent*, %struct.hostent** %20
%107 = getelementptr inbounds %struct.hostent, %struct.hostent* %106, i32 0, i32 1
%108 = load i32, i32* %107
%109 = load %struct.hostent*, %struct.hostent** %20
%110 = getelementptr inbounds %struct.hostent, %struct.hostent* %109, i32 0, i32 0
%111 = load i32, i32* %110
%112 = call i32 @memcpy(i32* %105, i32 %108, i32 %111)
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %13
br label %114
114: ; preds = %182, %77
%115 = load i32, i32* %13
%116 = load i32, i32* %17
%117 = icmp slt i32 %115, %116
br i1 %117, label %118, label %185
118: ; preds = %114
%119 = load i32, i32* %13
%120 = add nsw i32 %119, 1
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %120)
%122 = load i32, i32* @stdout
%123 = call i32 @fflush(i32 %122)
%124 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%125 = load i32, i32* @O_RDONLY
%126 = call i32 @open(i8* %124, i32 %125)
store i32 %126, i32* %10
%127 = load i32, i32* @PF_INET
%128 = load i32, i32* @SOCK_STREAM
%129 = call i32 @socket(i32 %127, i32 %128, i32 0)
store i32 %129, i32* %11
%130 = load i32, i32* %11
%131 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%132 = call i32 @connect(i32 %130, %struct.sockaddr* %131, i32 12)
%133 = call i32 @gettimeofday(%struct.timeval* %21, i32* null)
store i32 0, i32* %12
br label %134
134: ; preds = %159, %118
%135 = load i32, i32* %12
%136 = load i32, i32* %16
%137 = icmp slt i32 %135, %136
br i1 %137, label %138, label %162
138: ; preds = %134
%139 = load i32, i32* %18
%140 = icmp eq i32 %139, 0
br i1 %140, label %141, label %150
141: ; preds = %138
%142 = load i32, i32* %10
%143 = load i8*, i8** %6
%144 = load i32, i32* %15
%145 = call i32 @read(i32 %142, i8* %143, i32 %144)
store i32 %145, i32* %9
%146 = load i32, i32* %11
%147 = load i8*, i8** %6
%148 = load i32, i32* %9
%149 = call i32 @write(i32 %146, i8* %147, i32 %148)
br label %158
150: ; preds = %138
%151 = load i32, i32* %12
%152 = load i32, i32* %15
%153 = mul nsw i32 %151, %152
store i32 %153, i32* %24
%154 = load i32, i32* %11
%155 = load i32, i32* %10
%156 = load i32, i32* %15
%157 = call i32 @sendfile(i32 %154, i32 %155, i32* %24, i32 %156)
store i32 %157, i32* %9
br label %158
158: ; preds = %150, %141
br label %159
159: ; preds = %158
%160 = load i32, i32* %12
%161 = add nsw i32 %160, 1
store i32 %161, i32* %12
br label %134
162: ; preds = %134
%163 = call i32 @gettimeofday(%struct.timeval* %22, i32* null)
%164 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%165 = load i64, i64* %164
%166 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 1
%167 = load i64, i64* %166
%168 = sub nsw i64 %165, %167
%169 = sitofp i64 %168 to double
%170 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
%171 = load double, double* %170
%172 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 0
%173 = load double, double* %172
%174 = fsub double %171, %173
%175 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %174, double %169)
%176 = load double, double* %23
%177 = fadd double %176, %175
store double %177, double* %23
%178 = load i32, i32* %10
%179 = call i32 @close(i32 %178)
%180 = load i32, i32* %11
%181 = call i32 @close(i32 %180)
br label %182
182: ; preds = %162
%183 = load i32, i32* %13
%184 = add nsw i32 %183, 1
store i32 %184, i32* %13
br label %114
185: ; preds = %114
%186 = load i32, i32* %18
%187 = icmp eq i32 %186, 0
br i1 %187, label %188, label %191
188: ; preds = %185
%189 = load i32, i32* @stderr
%190 = call i32 (i32, i8*, ...) @fprintf(i32 %189, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %194
191: ; preds = %185
%192 = load i32, i32* @stderr
%193 = call i32 (i32, i8*, ...) @fprintf(i32 %192, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %194
194: ; preds = %191, %188
%195 = load double, double* %23
%196 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), double %195)
%197 = load i32, i32* @EXIT_SUCCESS
%198 = call i32 @exit(i32 %197)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.timeval = type { double, i64 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@__const.main.hname = [128 x i8] c"localhost\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.infile = [128 x i8] c"./infile\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [57 x i8] c"USAGE: %s on | off [infile] [hostname] [nchunks] [nreps]\00"
@.str.1 = [3 x i8] c"on\00"
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@.str.2 = [51 x i8] c"Input file: %s, Size: %d, Chunks: %d, Bytes: %d \0A\00"
@AF_INET = global i32 0
@.str.3 = [17 x i8] c"Doing iteration:\00"
@.str.4 = [4 x i8] c"%4d\00"
@stdout = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [30 x i8] c"\0ADONE, Did Not Use sendfile()\00"
@.str.6 = [30 x i8] c"\0ADONE, Did Use sendfile()\00"
@.str.7 = [40 x i8] c"\0A Total time spent in I/O = %f seconds\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca i32
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = bitcast %struct.sockaddr_in* %5 to i8*
%12 = bitcast %struct.timeval* %6 to i8*
%13 = bitcast %struct.timeval* %7 to i8*
%14 = icmp slt i32 %0, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%24 = icmp eq i32 %23, 0
%25 = icmp eq i32 %0, 2
br i1 %25, label %45, label %26
26: ; preds = %20
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @strcpy(i8* %10, i8* %28)
%30 = icmp ugt i32 %0, 3
br i1 %30, label %31, label %45
31: ; preds = %26
%32 = getelementptr inbounds i8*, i8** %1, i64 3
%33 = load i8*, i8** %32
%34 = call i32 @strcpy(i8* %9, i8* %33)
%35 = icmp eq i32 %0, 4
br i1 %35, label %45, label %36
36: ; preds = %31
%37 = getelementptr inbounds i8*, i8** %1, i64 4
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
%40 = icmp ugt i32 %0, 5
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = getelementptr inbounds i8*, i8** %1, i64 5
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
br label %45
45: ; preds = %20, %26, %31, %41, %36
%46 = phi i32 [ %39, %41 ], [ %39, %36 ], [ 1, %31 ], [ 1, %26 ], [ 1, %20 ]
%47 = phi i32 [ %44, %41 ], [ 10, %36 ], [ 10, %31 ], [ 10, %26 ], [ 10, %20 ]
%48 = load i32, i32* @O_RDONLY
%49 = call i32 @open(i8* %10, i32 %48)
%50 = load i32, i32* @SEEK_END
%51 = call i64 @lseek(i32 %49, i32 0, i32 %50)
%52 = trunc i64 %51 to i32
%53 = call i32 @close(i32 %49)
%54 = add nsw i32 %52, -1
%55 = sdiv i32 %54, %46
%56 = add nsw i32 %55, 1
%57 = call i8* @malloc(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %10, i32 %52, i32 %46, i32 %56)
%59 = call %struct.hostent* @gethostbyname(i8* %9)
%60 = load i32, i32* @AF_INET
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %60, i32* %61
%62 = call i32 @htons(i32 7177)
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %62, i32* %63
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%65 = getelementptr inbounds %struct.hostent, %struct.hostent* %59, i64 0, i32 1
%66 = load i32, i32* %65
%67 = getelementptr inbounds %struct.hostent, %struct.hostent* %59, i64 0, i32 0
%68 = load i32, i32* %67
%69 = call i32 @memcpy(i32* %64, i32 %66, i32 %68)
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%71 = icmp sgt i32 %47, 0
br i1 %71, label %72, label %119
72: ; preds = %45
%73 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%74 = icmp sgt i32 %46, 0
%75 = bitcast i32* %8 to i8*
%76 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%79 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
br label %80
80: ; preds = %72, %105
%81 = phi double [ 0.000000e+00, %72 ], [ %115, %105 ]
%82 = phi i32 [ 0, %72 ], [ %83, %105 ]
%83 = add nuw nsw i32 %82, 1
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %83)
%85 = load i32, i32* @stdout
%86 = call i32 @fflush(i32 %85)
%87 = load i32, i32* @O_RDONLY
%88 = call i32 @open(i8* %10, i32 %87)
%89 = load i32, i32* @PF_INET
%90 = load i32, i32* @SOCK_STREAM
%91 = call i32 @socket(i32 %89, i32 %90, i32 0)
%92 = call i32 @connect(i32 %91, %struct.sockaddr* %73, i32 12)
%93 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
br i1 %74, label %94, label %105
94: ; preds = %80, %102
%95 = phi i32 [ %103, %102 ], [ 0, %80 ]
br i1 %24, label %99, label %96
96: ; preds = %94
%97 = call i32 @read(i32 %88, i8* %57, i32 %56)
%98 = call i32 @write(i32 %91, i8* %57, i32 %97)
br label %102
99: ; preds = %94
%100 = mul nsw i32 %95, %56
store i32 %100, i32* %8
%101 = call i32 @sendfile(i32 %91, i32 %88, i32* %8, i32 %56)
br label %102
102: ; preds = %96, %99
%103 = add nuw nsw i32 %95, 1
%104 = icmp eq i32 %103, %46
br i1 %104, label %105, label %94
105: ; preds = %102, %80
%106 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%107 = load i64, i64* %76
%108 = load i64, i64* %77
%109 = sub nsw i64 %107, %108
%110 = sitofp i64 %109 to double
%111 = load double, double* %78
%112 = load double, double* %79
%113 = fsub double %111, %112
%114 = call double @llvm.fmuladd.f64(double %113, double 0x3EB0C6F7A0B5ED8D, double %110)
%115 = fadd double %81, %114
%116 = call i32 @close(i32 %88)
%117 = call i32 @close(i32 %91)
%118 = icmp eq i32 %83, %47
br i1 %118, label %119, label %80
119: ; preds = %105, %45
%120 = phi double [ 0.000000e+00, %45 ], [ %115, %105 ]
%121 = load i32, i32* @stderr
%122 = select i1 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0)
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* %122)
%124 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0), double %120)
%125 = load i32, i32* @EXIT_SUCCESS
%126 = call i32 @exit(i32 %125)
unreachable
}