#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_RDONLY;
int O_SYNC;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int atol(char *);
scalar_t__ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int getpid();
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int snprintf(char *, int, char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strncpy(char *, char *, int);
int strnlen(char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int rv;
  int inputFD;
  int outputFD;
  char inputFilename[80];
  char outputFilename[80];
  char outputFilenameBase[80];
  ssize_t transfersize = 0;
  ssize_t blocksize = 0;
  char *transferBuffer = NULL;
  ssize_t buffersize;
  ssize_t bytesRead = 0;
  ssize_t totalBytesRead = 0;
  int totalReads = 0;
  ssize_t bytesWritten = 0;
  ssize_t totalBytesWritten = 0;
  int totalWrites = 0;
  int inputFileResets = 0;
  if (argc < 2) {
    transfersize = 1024 * 100;
  } else {
    transfersize = atol(argv[1]);
    if (transfersize < 1) {
      fprintf(stderr, "Bad transfersize value\n");
      exit(EXIT_FAILURE);
    }
  }
  if (argc < 3) {
    blocksize = 1024;
  } else {
    blocksize = atol(argv[2]);
    if (blocksize < 1) {
      fprintf(stderr, "Bad blocksize value\n");
      exit(EXIT_FAILURE);
    }
  }
  if (argc < 4) {
    if (strnlen("rwinput", 80) >= 80) {
      fprintf(stderr, "Default input filename too long\n");
      exit(EXIT_FAILURE);
    }
    strncpy(inputFilename, "rwinput", 80);
  } else {
    if (strnlen(argv[3], 80) >= 80) {
      fprintf(stderr, "Input filename too long\n");
      exit(EXIT_FAILURE);
    }
    strncpy(inputFilename, argv[3], 80);
  }
  if (argc < 5) {
    if (strnlen("rwoutput", 80) >= 80) {
      fprintf(stderr, "Default output filename base too long\n");
      exit(EXIT_FAILURE);
    }
    strncpy(outputFilenameBase, "rwoutput", 80);
  } else {
    if (strnlen(argv[4], 80) >= 80) {
      fprintf(stderr, "Output filename base is too long\n");
      exit(EXIT_FAILURE);
    }
    strncpy(outputFilenameBase, argv[4], 80);
  }
  if (blocksize > transfersize) {
    fprintf(stderr, "blocksize can not exceed transfersize\n");
    exit(EXIT_FAILURE);
  }
  if (transfersize % blocksize) {
    fprintf(stderr, "blocksize must be multiple of transfersize\n");
    exit(EXIT_FAILURE);
  }
  buffersize = blocksize;
  if (!(transferBuffer = malloc(buffersize * sizeof(*transferBuffer)))) {
    perror("Failed to allocate transfer buffer");
    exit(EXIT_FAILURE);
  }
  if ((inputFD = open(inputFilename, O_RDONLY | O_SYNC)) < 0) {
    perror("Failed to open input file");
    exit(EXIT_FAILURE);
  }
  rv = snprintf(outputFilename, 80, "%s-%d", outputFilenameBase, getpid());
  if (rv > 80) {
    fprintf(stderr, "Output filenmae length exceeds limit of %d characters.\n",
            80);
    exit(EXIT_FAILURE);
  } else if (rv < 0) {
    perror("Failed to generate output filename");
    exit(EXIT_FAILURE);
  }
  if ((outputFD = open(outputFilename, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC,
                       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)) < 0) {
    perror("Failed to open output file");
    exit(EXIT_FAILURE);
  }
  fprintf(stdout, "Reading from %s and writing to %s\n", inputFilename,
          outputFilename);
  do {
    bytesRead = read(inputFD, transferBuffer, buffersize);
    if (bytesRead < 0) {
      perror("Error reading input file");
      exit(EXIT_FAILURE);
    } else {
      totalBytesRead += bytesRead;
      totalReads++;
    }
    if (bytesRead == blocksize) {
      bytesWritten = write(outputFD, transferBuffer, bytesRead);
      if (bytesWritten < 0) {
        perror("Error writing output file");
        exit(EXIT_FAILURE);
      } else {
        totalBytesWritten += bytesWritten;
        totalWrites++;
      }
    } else {
      if (lseek(inputFD, 0, SEEK_SET)) {
        perror("Error resetting to beginning of file");
        exit(EXIT_FAILURE);
      }
      inputFileResets++;
    }
  } while (totalBytesWritten < transfersize);
  fprintf(stdout, "Read:    %zd bytes in %d reads\n", totalBytesRead,
          totalReads);
  fprintf(stdout, "Written: %zd bytes in %d writes\n", totalBytesWritten,
          totalWrites);
  fprintf(stdout, "Read input file in %d pass%s\n", (inputFileResets + 1),
          (inputFileResets ? "es" : ""));
  fprintf(stdout, "Processed %zd bytes in blocks of %zd bytes\n", transfersize,
          blocksize);
  free(transferBuffer);
  if (close(outputFD)) {
    perror("Failed to close output file");
    exit(EXIT_FAILURE);
  }
  if (close(inputFD)) {
    perror("Failed to close input file");
    exit(EXIT_FAILURE);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x114(%rbp)
movl   $0x0,-0x118(%rbp)
movq   $0x0,-0x120(%rbp)
movl   $0x0,-0x128(%rbp)
movl   $0x0,-0x12c(%rbp)
movl   $0x0,-0x130(%rbp)
movl   $0x0,-0x134(%rbp)
movl   $0x0,-0x138(%rbp)
movl   $0x0,-0x13c(%rbp)
movl   $0x0,-0x140(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1287 <main+0x97>
movl   $0x19000,-0x114(%rbp)
jmp    12d1 <main+0xe1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atol@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x1,-0x114(%rbp)
jge    12cc <main+0xdc>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xd49(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
jmp    12d1 <main+0xe1>
cmpl   $0x3,-0x8(%rbp)
jge    12ea <main+0xfa>
movl   $0x400,-0x118(%rbp)
jmp    1334 <main+0x144>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atol@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0x1,-0x118(%rbp)
jge    132f <main+0x13f>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
lea    0xcfe(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
jmp    1334 <main+0x144>
cmpl   $0x4,-0x8(%rbp)
jge    1397 <main+0x1a7>
lea    0xce8(%rip),%rdi
mov    $0x50,%esi
call   1090 <strnlen@plt>
cmp    $0x50,%eax
jl     137d <main+0x18d>
mov    0x2c51(%rip),%rax
mov    (%rax),%edi
lea    0xccd(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2c1a(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
lea    -0x70(%rbp),%rdi
lea    0xca5(%rip),%rsi
mov    $0x50,%edx
call   1040 <strncpy@plt>
jmp    13ed <main+0x1fd>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    $0x50,%esi
call   1090 <strnlen@plt>
cmp    $0x50,%eax
jl     13d7 <main+0x1e7>
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
lea    0xc94(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2bc0(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    $0x50,%edx
call   1040 <strncpy@plt>
cmpl   $0x5,-0x8(%rbp)
jge    1453 <main+0x263>
lea    0xc71(%rip),%rdi
mov    $0x50,%esi
call   1090 <strnlen@plt>
cmp    $0x50,%eax
jl     1436 <main+0x246>
mov    0x2b98(%rip),%rax
mov    (%rax),%edi
lea    0xc57(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2b61(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
lea    -0x110(%rbp),%rdi
lea    0xc2b(%rip),%rsi
mov    $0x50,%edx
call   1040 <strncpy@plt>
jmp    14ac <main+0x2bc>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    $0x50,%esi
call   1090 <strnlen@plt>
cmp    $0x50,%eax
jl     1493 <main+0x2a3>
mov    0x2b3b(%rip),%rax
mov    (%rax),%edi
lea    0xc21(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
mov    $0x50,%edx
call   1040 <strncpy@plt>
mov    -0x118(%rbp),%eax
cmp    -0x114(%rbp),%eax
jle    14e3 <main+0x2f3>
mov    0x2aeb(%rip),%rax
mov    (%rax),%edi
lea    0xbf3(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2ab4(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x114(%rbp),%eax
cltd
idivl  -0x118(%rbp)
cmp    $0x0,%edx
je     151e <main+0x32e>
mov    0x2ab0(%rip),%rax
mov    (%rax),%edi
lea    0xbdf(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2a79(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x118(%rbp),%eax
mov    %eax,-0x124(%rbp)
movslq -0x124(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x120(%rbp)
cmp    $0x0,%rax
jne    1567 <main+0x377>
lea    0xbc0(%rip),%rdi
call   1100 <perror@plt>
mov    0x2a30(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    0x2a5e(%rip),%rax
mov    (%rax),%esi
mov    0x2a5d(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10f0 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    15aa <main+0x3ba>
lea    0xba0(%rip),%rdi
call   1100 <perror@plt>
mov    0x29ed(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
lea    -0xc0(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    $0x0,%al
call   1060 <getpid@plt>
mov    -0x150(%rbp),%rdi
mov    -0x148(%rbp),%rcx
mov    %eax,%r8d
mov    $0x50,%esi
lea    0xb67(%rip),%rdx
call   1070 <snprintf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x50,-0x14(%rbp)
jle    1626 <main+0x436>
mov    0x29ad(%rip),%rax
mov    (%rax),%edi
lea    0xb4b(%rip),%rsi
mov    $0x50,%edx
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2971(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jge    164a <main+0x45a>
lea    0xb58(%rip),%rdi
call   1100 <perror@plt>
mov    0x294d(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
jmp    164f <main+0x45f>
lea    -0xc0(%rbp),%rdi
mov    0x290b(%rip),%rax
mov    (%rax),%esi
mov    0x2992(%rip),%rax
or     (%rax),%esi
mov    0x2981(%rip),%rax
or     (%rax),%esi
mov    0x2960(%rip),%rax
or     (%rax),%esi
mov    0x2907(%rip),%rax
mov    (%rax),%edx
mov    0x2936(%rip),%rax
or     (%rax),%edx
mov    0x290d(%rip),%rax
or     (%rax),%edx
mov    0x292c(%rip),%rax
or     (%rax),%edx
mov    0x28f3(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10f0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    16d4 <main+0x4e4>
lea    0xaf1(%rip),%rdi
call   1100 <perror@plt>
mov    0x28c3(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    0x28a5(%rip),%rax
mov    (%rax),%edi
lea    -0x70(%rbp),%rdx
lea    -0xc0(%rbp),%rcx
lea    0xade(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x18(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   10b0 <read@plt>
mov    %eax,-0x128(%rbp)
cmpl   $0x0,-0x128(%rbp)
jge    1738 <main+0x548>
lea    0xacb(%rip),%rdi
call   1100 <perror@plt>
mov    0x285f(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x128(%rbp),%eax
add    -0x12c(%rbp),%eax
mov    %eax,-0x12c(%rbp)
mov    -0x130(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x130(%rbp)
mov    -0x128(%rbp),%eax
cmp    -0x118(%rbp),%eax
jne    17d3 <main+0x5e3>
mov    -0x1c(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    -0x128(%rbp),%edx
call   1050 <write@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jge    17ad <main+0x5bd>
lea    0xa6f(%rip),%rdi
call   1100 <perror@plt>
mov    0x27ea(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x134(%rbp),%eax
add    -0x138(%rbp),%eax
mov    %eax,-0x138(%rbp)
mov    -0x13c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13c(%rbp)
jmp    1819 <main+0x629>
mov    -0x18(%rbp),%edi
mov    0x27cb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <lseek@plt>
cmp    $0x0,%rax
je     180a <main+0x61a>
lea    0xa2c(%rip),%rdi
call   1100 <perror@plt>
mov    0x278d(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x140(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x140(%rbp)
jmp    181e <main+0x62e>
mov    -0x138(%rbp),%eax
cmp    -0x114(%rbp),%eax
jl     16f6 <main+0x506>
mov    0x2749(%rip),%rax
mov    (%rax),%edi
mov    -0x12c(%rbp),%edx
mov    -0x130(%rbp),%ecx
lea    0x9fc(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2726(%rip),%rax
mov    (%rax),%edi
mov    -0x138(%rbp),%edx
mov    -0x13c(%rbp),%ecx
lea    0x9f9(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2703(%rip),%rax
mov    (%rax),%edi
mov    -0x140(%rbp),%edx
add    $0x1,%edx
mov    -0x140(%rbp),%esi
lea    0x8f9(%rip),%rcx
lea    0xa0b(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0x9df(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x26c8(%rip),%rax
mov    (%rax),%edi
mov    -0x114(%rbp),%edx
mov    -0x118(%rbp),%ecx
lea    0x9dd(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x120(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
cmp    $0x0,%rax
je     190c <main+0x71c>
lea    0x9dd(%rip),%rdi
call   1100 <perror@plt>
mov    0x268b(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x18(%rbp),%edi
call   10a0 <close@plt>
cmp    $0x0,%rax
je     1938 <main+0x748>
lea    0x9cd(%rip),%rdi
call   1100 <perror@plt>
mov    0x265f(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    0x2639(%rip),%rax
mov    (%rax),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    $0x19000,%ebp
cmp    $0x2,%edi
jge    1214 <main+0x24>
movl   $0x400,(%rsp)
jmp    1255 <main+0x65>
mov    %rsi,%r14
mov    %edi,%ebx
movl   $0x400,(%rsp)
mov    0x8(%rsi),%rdi
call   10e0 <atol@plt>
test   %eax,%eax
jle    166c <main+0x47c>
mov    %eax,%ebp
cmp    $0x3,%ebx
jb     1255 <main+0x65>
mov    0x10(%r14),%rdi
call   10e0 <atol@plt>
test   %eax,%eax
jle    167e <main+0x48e>
cmp    $0x3,%ebx
mov    %eax,(%rsp)
ja     1545 <main+0x355>
lea    0xdd1(%rip),%rdi
mov    $0x50,%esi
call   1090 <strnlen@plt>
cmp    $0x50,%eax
jge    165a <main+0x46a>
lea    0xdb7(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    $0x50,%edx
call   1040 <strncpy@plt>
lea    0xde3(%rip),%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1090 <strnlen@plt>
cmp    $0x50,%eax
jge    1648 <main+0x458>
lea    0xc0(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1040 <strncpy@plt>
mov    (%rsp),%edi
cmp    %ebp,%edi
ja     15c4 <main+0x3d4>
mov    %ebp,%eax
xor    %edx,%edx
div    %edi
test   %edx,%edx
jne    15d9 <main+0x3e9>
call   10d0 <malloc@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     15ee <main+0x3fe>
mov    0x2ce6(%rip),%rax
mov    0x2ce7(%rip),%rbx
mov    (%rbx),%esi
or     (%rax),%esi
lea    0x20(%rsp),%rdi
xor    %eax,%eax
call   10f0 <open@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
js     15f7 <main+0x407>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xe36(%rip),%rdx
lea    0x70(%rsp),%rdi
lea    0xc0(%rsp),%rcx
mov    $0x50,%esi
mov    %eax,%r8d
call   1070 <snprintf@plt>
cmp    $0x51,%eax
jge    1600 <main+0x410>
test   %eax,%eax
js     161e <main+0x42e>
mov    0x2c1b(%rip),%rax
mov    0x2ca4(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c91(%rip),%rax
or     (%rax),%esi
or     (%rbx),%esi
mov    0x2c1e(%rip),%rax
mov    0x2c4f(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2c24(%rip),%rax
or     (%rax),%edx
mov    0x2c43(%rip),%rax
or     (%rax),%edx
mov    0x2c0a(%rip),%rax
or     (%rax),%edx
xor    %ebx,%ebx
lea    0x70(%rsp),%rdi
xor    %eax,%eax
call   10f0 <open@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
js     1627 <main+0x437>
mov    0x2bcf(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0x70(%rsp),%rcx
xor    %eax,%eax
call   10c0 <fprintf@plt>
xor    %r15d,%r15d
xor    %r14d,%r14d
movl   $0x0,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
mov    (%rsp),%eax
jmp    1403 <main+0x213>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%eax
add    %r13d,%ebx
add    $0x1,%r15d
cmp    %ebp,%r14d
jge    147f <main+0x28f>
mov    0x4(%rsp),%edi
mov    0x18(%rsp),%rsi
mov    %eax,%edx
mov    %eax,%r12d
call   10b0 <read@plt>
test   %eax,%eax
js     1598 <main+0x3a8>
mov    %eax,%r13d
cmp    %r12d,%eax
jne    1450 <main+0x260>
mov    0xc(%rsp),%edi
mov    0x18(%rsp),%rsi
mov    %r12d,%edx
call   1050 <write@plt>
test   %eax,%eax
js     15a1 <main+0x3b1>
add    %eax,%r14d
addl   $0x1,0x8(%rsp)
jmp    13f0 <main+0x200>
nopl   0x0(%rax)
mov    0x2b51(%rip),%rax
mov    (%rax),%edx
mov    0x4(%rsp),%edi
xor    %esi,%esi
call   1080 <lseek@plt>
test   %rax,%rax
jne    15aa <main+0x3ba>
mov    0x10(%rsp),%rax
add    $0x1,%eax
mov    %rax,0x10(%rsp)
jmp    13f0 <main+0x200>
mov    0x2afa(%rip),%r12
mov    (%r12),%edi
lea    0xdb7(%rip),%rsi
mov    %ebx,%edx
mov    %eax,%ebx
mov    %r15d,%ecx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%r12),%edi
lea    0xdbe(%rip),%rsi
mov    %r14d,%edx
mov    0x8(%rsp),%ecx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%r12),%edi
mov    0x10(%rsp),%rax
lea    0x1(%rax),%edx
test   %eax,%eax
lea    0xcc1(%rip),%rax
lea    0xdd3(%rip),%rcx
cmove  %rax,%rcx
lea    0xdaa(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%r12),%edi
lea    0xdb9(%rip),%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0xc(%rsp),%edi
call   10a0 <close@plt>
test   %rax,%rax
jne    1630 <main+0x440>
mov    0x4(%rsp),%edi
call   10a0 <close@plt>
test   %rax,%rax
jne    163c <main+0x44c>
mov    0x2a47(%rip),%rax
mov    (%rax),%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x18(%r14),%rdi
mov    $0x50,%esi
call   1090 <strnlen@plt>
cmp    $0x50,%eax
jge    1690 <main+0x4a0>
mov    0x18(%r14),%rsi
lea    0x20(%rsp),%rdi
mov    $0x50,%edx
call   1040 <strncpy@plt>
cmp    $0x4,%ebx
jbe    1285 <main+0x95>
mov    0x20(%r14),%rdi
mov    $0x50,%esi
call   1090 <strnlen@plt>
cmp    $0x50,%eax
jge    16a2 <main+0x4b2>
mov    0x20(%r14),%rbx
jmp    12a2 <main+0xb2>
lea    0xc51(%rip),%rdi
jmp    15b1 <main+0x3c1>
lea    0xc61(%rip),%rdi
jmp    15b1 <main+0x3c1>
lea    0xc72(%rip),%rdi
call   1100 <perror@plt>
mov    0x29d3(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    0x29e5(%rip),%rax
mov    (%rax),%edi
lea    0xaed(%rip),%rsi
jmp    16b2 <main+0x4c2>
mov    0x29d0(%rip),%rax
mov    (%rax),%edi
lea    0xaff(%rip),%rsi
jmp    16b2 <main+0x4c2>
lea    0xb1f(%rip),%rdi
jmp    15b1 <main+0x3c1>
lea    0xb39(%rip),%rdi
jmp    15b1 <main+0x3c1>
mov    0x29a9(%rip),%rax
mov    (%rax),%edi
lea    0xb47(%rip),%rsi
mov    $0x50,%edx
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    15b6 <main+0x3c6>
lea    0xb6a(%rip),%rdi
jmp    15b1 <main+0x3c1>
lea    0xb84(%rip),%rdi
jmp    15b1 <main+0x3c1>
lea    0xc9f(%rip),%rdi
jmp    15b1 <main+0x3c1>
lea    0xcaf(%rip),%rdi
jmp    15b1 <main+0x3c1>
mov    0x2961(%rip),%rax
mov    (%rax),%edi
lea    0xa20(%rip),%rsi
jmp    16b2 <main+0x4c2>
mov    0x294f(%rip),%rax
mov    (%rax),%edi
lea    0x9cb(%rip),%rsi
jmp    16b2 <main+0x4c2>
mov    0x293d(%rip),%rax
mov    (%rax),%edi
lea    0x984(%rip),%rsi
jmp    16b2 <main+0x4c2>
mov    0x292b(%rip),%rax
mov    (%rax),%edi
lea    0x98a(%rip),%rsi
jmp    16b2 <main+0x4c2>
mov    0x2919(%rip),%rax
mov    (%rax),%edi
lea    0x9b6(%rip),%rsi
jmp    16b2 <main+0x4c2>
mov    0x2907(%rip),%rax
mov    (%rax),%edi
lea    0x9ed(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    15b6 <main+0x3c6>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Bad transfersize value\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"Bad blocksize value\0A\00"
@.str.2 = [8 x i8] c"rwinput\00"
@.str.3 = [33 x i8] c"Default input filename too long\0A\00"
@.str.4 = [25 x i8] c"Input filename too long\0A\00"
@.str.5 = [9 x i8] c"rwoutput\00"
@.str.6 = [39 x i8] c"Default output filename base too long\0A\00"
@.str.7 = [34 x i8] c"Output filename base is too long\0A\00"
@.str.8 = [39 x i8] c"blocksize can not exceed transfersize\0A\00"
@.str.9 = [44 x i8] c"blocksize must be multiple of transfersize\0A\00"
@.str.10 = [35 x i8] c"Failed to allocate transfer buffer\00"
@O_RDONLY = global i32 0
@O_SYNC = global i32 0
@.str.11 = [26 x i8] c"Failed to open input file\00"
@.str.12 = [6 x i8] c"%s-%d\00"
@.str.13 = [56 x i8] c"Output filenmae length exceeds limit of %d characters.\0A\00"
@.str.14 = [35 x i8] c"Failed to generate output filename\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@.str.15 = [27 x i8] c"Failed to open output file\00"
@stdout = global i32 0
@.str.16 = [35 x i8] c"Reading from %s and writing to %s\0A\00"
@.str.17 = [25 x i8] c"Error reading input file\00"
@.str.18 = [26 x i8] c"Error writing output file\00"
@SEEK_SET = global i32 0
@.str.19 = [37 x i8] c"Error resetting to beginning of file\00"
@.str.20 = [32 x i8] c"Read: %zd bytes in %d reads\0A\00"
@.str.21 = [33 x i8] c"Written: %zd bytes in %d writes\0A\00"
@.str.22 = [30 x i8] c"Read input file in %d pass%s\0A\00"
@.str.23 = [3 x i8] c"es\00"
@.str.24 = [1 x i8] zeroinitializer
@.str.25 = [44 x i8] c"Processed %zd bytes in blocks of %zd bytes\0A\00"
@.str.26 = [28 x i8] c"Failed to close output file\00"
@.str.27 = [27 x i8] c"Failed to close input file\00"
@EXIT_SUCCESS = global i32 0
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 [80 x i8]
%10 = alloca [80 x i8]
%11 = alloca [80 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %12
store i32 0, i32* %13
store i8* null, i8** %14
store i32 0, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
store i32 0, i32* %19
store i32 0, i32* %20
store i32 0, i32* %21
store i32 0, i32* %22
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %26
25: ; preds = %2
store i32 102400, i32* %12
br label %39
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @atol(i8* %29)
store i32 %30, i32* %12
%31 = load i32, i32* %12
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %38
33: ; preds = %26
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %26
br label %39
39: ; preds = %38, %25
%40 = load i32, i32* %4
%41 = icmp slt i32 %40, 3
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 1024, i32* %13
br label %56
43: ; preds = %39
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @atol(i8* %46)
store i32 %47, i32* %13
%48 = load i32, i32* %13
%49 = icmp slt i32 %48, 1
br i1 %49, label %50, label %55
50: ; preds = %43
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %43
br label %56
56: ; preds = %55, %42
%57 = load i32, i32* %4
%58 = icmp slt i32 %57, 4
br i1 %58, label %59, label %70
59: ; preds = %56
%60 = call i32 @strnlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 80)
%61 = icmp sge i32 %60, 80
br i1 %61, label %62, label %67
62: ; preds = %59
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %59
%68 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%69 = call i32 @strncpy(i8* %68, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 80)
br label %87
70: ; preds = %56
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 3
%73 = load i8*, i8** %72
%74 = call i32 @strnlen(i8* %73, i32 80)
%75 = icmp sge i32 %74, 80
br i1 %75, label %76, label %81
76: ; preds = %70
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%79 = load i32, i32* @EXIT_FAILURE
%80 = call i32 @exit(i32 %79)
unreachable
81: ; preds = %70
%82 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 3
%85 = load i8*, i8** %84
%86 = call i32 @strncpy(i8* %82, i8* %85, i32 80)
br label %87
87: ; preds = %81, %67
%88 = load i32, i32* %4
%89 = icmp slt i32 %88, 5
br i1 %89, label %90, label %101
90: ; preds = %87
%91 = call i32 @strnlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 80)
%92 = icmp sge i32 %91, 80
br i1 %92, label %93, label %98
93: ; preds = %90
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%96 = load i32, i32* @EXIT_FAILURE
%97 = call i32 @exit(i32 %96)
unreachable
98: ; preds = %90
%99 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%100 = call i32 @strncpy(i8* %99, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 80)
br label %118
101: ; preds = %87
%102 = load i8**, i8*** %5
%103 = getelementptr inbounds i8*, i8** %102, i64 4
%104 = load i8*, i8** %103
%105 = call i32 @strnlen(i8* %104, i32 80)
%106 = icmp sge i32 %105, 80
br i1 %106, label %107, label %112
107: ; preds = %101
%108 = load i32, i32* @stderr
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%110 = load i32, i32* @EXIT_FAILURE
%111 = call i32 @exit(i32 %110)
unreachable
112: ; preds = %101
%113 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%114 = load i8**, i8*** %5
%115 = getelementptr inbounds i8*, i8** %114, i64 4
%116 = load i8*, i8** %115
%117 = call i32 @strncpy(i8* %113, i8* %116, i32 80)
br label %118
118: ; preds = %112, %98
%119 = load i32, i32* %13
%120 = load i32, i32* %12
%121 = icmp sgt i32 %119, %120
br i1 %121, label %122, label %127
122: ; preds = %118
%123 = load i32, i32* @stderr
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0))
%125 = load i32, i32* @EXIT_FAILURE
%126 = call i32 @exit(i32 %125)
unreachable
127: ; preds = %118
%128 = load i32, i32* %12
%129 = load i32, i32* %13
%130 = srem i32 %128, %129
%131 = icmp ne i32 %130, 0
br i1 %131, label %132, label %137
132: ; preds = %127
%133 = load i32, i32* @stderr
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %133, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0))
%135 = load i32, i32* @EXIT_FAILURE
%136 = call i32 @exit(i32 %135)
unreachable
137: ; preds = %127
%138 = load i32, i32* %13
store i32 %138, i32* %15
%139 = load i32, i32* %15
%140 = sext i32 %139 to i64
%141 = mul i64 %140, 1
%142 = trunc i64 %141 to i32
%143 = call i8* @malloc(i32 %142)
store i8* %143, i8** %14
%144 = icmp ne i8* %143, null
br i1 %144, label %149, label %145
145: ; preds = %137
%146 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0))
%147 = load i32, i32* @EXIT_FAILURE
%148 = call i32 @exit(i32 %147)
unreachable
149: ; preds = %137
%150 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%151 = load i32, i32* @O_RDONLY
%152 = load i32, i32* @O_SYNC
%153 = or i32 %151, %152
%154 = call i32 (i8*, i32, ...) @open(i8* %150, i32 %153)
store i32 %154, i32* %7
%155 = icmp slt i32 %154, 0
br i1 %155, label %156, label %160
156: ; preds = %149
%157 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0))
%158 = load i32, i32* @EXIT_FAILURE
%159 = call i32 @exit(i32 %158)
unreachable
160: ; preds = %149
%161 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%162 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%163 = call i32 (...) @getpid()
%164 = call i32 @snprintf(i8* %161, i32 80, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* %162, i32 %163)
store i32 %164, i32* %6
%165 = load i32, i32* %6
%166 = icmp sgt i32 %165, 80
br i1 %166, label %167, label %172
167: ; preds = %160
%168 = load i32, i32* @stderr
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %168, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.13, i64 0, i64 0), i32 80)
%170 = load i32, i32* @EXIT_FAILURE
%171 = call i32 @exit(i32 %170)
unreachable
172: ; preds = %160
%173 = load i32, i32* %6
%174 = icmp slt i32 %173, 0
br i1 %174, label %175, label %179
175: ; preds = %172
%176 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0))
%177 = load i32, i32* @EXIT_FAILURE
%178 = call i32 @exit(i32 %177)
unreachable
179: ; preds = %172
br label %180
180: ; preds = %179
%181 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%182 = load i32, i32* @O_WRONLY
%183 = load i32, i32* @O_CREAT
%184 = or i32 %182, %183
%185 = load i32, i32* @O_TRUNC
%186 = or i32 %184, %185
%187 = load i32, i32* @O_SYNC
%188 = or i32 %186, %187
%189 = load i32, i32* @S_IRUSR
%190 = load i32, i32* @S_IWUSR
%191 = or i32 %189, %190
%192 = load i32, i32* @S_IRGRP
%193 = or i32 %191, %192
%194 = load i32, i32* @S_IWGRP
%195 = or i32 %193, %194
%196 = load i32, i32* @S_IROTH
%197 = or i32 %195, %196
%198 = call i32 (i8*, i32, ...) @open(i8* %181, i32 %188, i32 %197)
store i32 %198, i32* %8
%199 = icmp slt i32 %198, 0
br i1 %199, label %200, label %204
200: ; preds = %180
%201 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.15, i64 0, i64 0))
%202 = load i32, i32* @EXIT_FAILURE
%203 = call i32 @exit(i32 %202)
unreachable
204: ; preds = %180
%205 = load i32, i32* @stdout
%206 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%207 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%208 = call i32 (i32, i8*, ...) @fprintf(i32 %205, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.16, i64 0, i64 0), i8* %206, i8* %207)
br label %209
209: ; preds = %261, %204
%210 = load i32, i32* %7
%211 = load i8*, i8** %14
%212 = load i32, i32* %15
%213 = call i32 @read(i32 %210, i8* %211, i32 %212)
store i32 %213, i32* %16
%214 = load i32, i32* %16
%215 = icmp slt i32 %214, 0
br i1 %215, label %216, label %220
216: ; preds = %209
%217 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.17, i64 0, i64 0))
%218 = load i32, i32* @EXIT_FAILURE
%219 = call i32 @exit(i32 %218)
unreachable
220: ; preds = %209
%221 = load i32, i32* %16
%222 = load i32, i32* %17
%223 = add nsw i32 %222, %221
store i32 %223, i32* %17
%224 = load i32, i32* %18
%225 = add nsw i32 %224, 1
store i32 %225, i32* %18
br label %226
226: ; preds = %220
%227 = load i32, i32* %16
%228 = load i32, i32* %13
%229 = icmp eq i32 %227, %228
br i1 %229, label %230, label %248
230: ; preds = %226
%231 = load i32, i32* %8
%232 = load i8*, i8** %14
%233 = load i32, i32* %16
%234 = call i32 @write(i32 %231, i8* %232, i32 %233)
store i32 %234, i32* %19
%235 = load i32, i32* %19
%236 = icmp slt i32 %235, 0
br i1 %236, label %237, label %241
237: ; preds = %230
%238 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.18, i64 0, i64 0))
%239 = load i32, i32* @EXIT_FAILURE
%240 = call i32 @exit(i32 %239)
unreachable
241: ; preds = %230
%242 = load i32, i32* %19
%243 = load i32, i32* %20
%244 = add nsw i32 %243, %242
store i32 %244, i32* %20
%245 = load i32, i32* %21
%246 = add nsw i32 %245, 1
store i32 %246, i32* %21
br label %247
247: ; preds = %241
br label %260
248: ; preds = %226
%249 = load i32, i32* %7
%250 = load i32, i32* @SEEK_SET
%251 = call i64 @lseek(i32 %249, i32 0, i32 %250)
%252 = icmp ne i64 %251, 0
br i1 %252, label %253, label %257
253: ; preds = %248
%254 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.19, i64 0, i64 0))
%255 = load i32, i32* @EXIT_FAILURE
%256 = call i32 @exit(i32 %255)
unreachable
257: ; preds = %248
%258 = load i32, i32* %22
%259 = add nsw i32 %258, 1
store i32 %259, i32* %22
br label %260
260: ; preds = %257, %247
br label %261
261: ; preds = %260
%262 = load i32, i32* %20
%263 = load i32, i32* %12
%264 = icmp slt i32 %262, %263
br i1 %264, label %209, label %265
265: ; preds = %261
%266 = load i32, i32* @stdout
%267 = load i32, i32* %17
%268 = load i32, i32* %18
%269 = call i32 (i32, i8*, ...) @fprintf(i32 %266, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.20, i64 0, i64 0), i32 %267, i32 %268)
%270 = load i32, i32* @stdout
%271 = load i32, i32* %20
%272 = load i32, i32* %21
%273 = call i32 (i32, i8*, ...) @fprintf(i32 %270, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.21, i64 0, i64 0), i32 %271, i32 %272)
%274 = load i32, i32* @stdout
%275 = load i32, i32* %22
%276 = add nsw i32 %275, 1
%277 = load i32, i32* %22
%278 = icmp ne i32 %277, 0
%279 = zext i1 %278 to i64
%280 = select i1 %278, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.23, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.24, i64 0, i64 0)
%281 = call i32 (i32, i8*, ...) @fprintf(i32 %274, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.22, i64 0, i64 0), i32 %276, i8* %280)
%282 = load i32, i32* @stdout
%283 = load i32, i32* %12
%284 = load i32, i32* %13
%285 = call i32 (i32, i8*, ...) @fprintf(i32 %282, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.25, i64 0, i64 0), i32 %283, i32 %284)
%286 = load i8*, i8** %14
%287 = call i32 @free(i8* %286)
%288 = load i32, i32* %8
%289 = call i64 @close(i32 %288)
%290 = icmp ne i64 %289, 0
br i1 %290, label %291, label %295
291: ; preds = %265
%292 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.26, i64 0, i64 0))
%293 = load i32, i32* @EXIT_FAILURE
%294 = call i32 @exit(i32 %293)
unreachable
295: ; preds = %265
%296 = load i32, i32* %7
%297 = call i64 @close(i32 %296)
%298 = icmp ne i64 %297, 0
br i1 %298, label %299, label %303
299: ; preds = %295
%300 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.27, i64 0, i64 0))
%301 = load i32, i32* @EXIT_FAILURE
%302 = call i32 @exit(i32 %301)
unreachable
303: ; preds = %295
%304 = load i32, i32* @EXIT_SUCCESS
ret i32 %304
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Bad transfersize value\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"Bad blocksize value\0A\00"
@.str.2 = [8 x i8] c"rwinput\00"
@.str.3 = [33 x i8] c"Default input filename too long\0A\00"
@.str.4 = [25 x i8] c"Input filename too long\0A\00"
@.str.5 = [9 x i8] c"rwoutput\00"
@.str.6 = [39 x i8] c"Default output filename base too long\0A\00"
@.str.7 = [34 x i8] c"Output filename base is too long\0A\00"
@.str.8 = [39 x i8] c"blocksize can not exceed transfersize\0A\00"
@.str.9 = [44 x i8] c"blocksize must be multiple of transfersize\0A\00"
@.str.10 = [35 x i8] c"Failed to allocate transfer buffer\00"
@O_RDONLY = global i32 0
@O_SYNC = global i32 0
@.str.11 = [26 x i8] c"Failed to open input file\00"
@.str.12 = [6 x i8] c"%s-%d\00"
@.str.13 = [56 x i8] c"Output filenmae length exceeds limit of %d characters.\0A\00"
@.str.14 = [35 x i8] c"Failed to generate output filename\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@.str.15 = [27 x i8] c"Failed to open output file\00"
@stdout = global i32 0
@.str.16 = [35 x i8] c"Reading from %s and writing to %s\0A\00"
@.str.17 = [25 x i8] c"Error reading input file\00"
@.str.18 = [26 x i8] c"Error writing output file\00"
@SEEK_SET = global i32 0
@.str.19 = [37 x i8] c"Error resetting to beginning of file\00"
@.str.20 = [32 x i8] c"Read: %zd bytes in %d reads\0A\00"
@.str.21 = [33 x i8] c"Written: %zd bytes in %d writes\0A\00"
@.str.22 = [30 x i8] c"Read input file in %d pass%s\0A\00"
@.str.23 = [3 x i8] c"es\00"
@.str.24 = [1 x i8] zeroinitializer
@.str.25 = [44 x i8] c"Processed %zd bytes in blocks of %zd bytes\0A\00"
@.str.26 = [28 x i8] c"Failed to close output file\00"
@.str.27 = [27 x i8] c"Failed to close input file\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca [80 x i8]
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%9 = icmp slt i32 %0, 2
br i1 %9, label %34, label %10
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atol(i8* %12)
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = icmp ult i32 %0, 3
br i1 %21, label %34, label %22
22: ; preds = %20
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32 @atol(i8* %24)
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
32: ; preds = %22
%33 = icmp ult i32 %0, 4
br i1 %33, label %34, label %46
34: ; preds = %2, %20, %32
%35 = phi i32 [ %25, %32 ], [ 1024, %20 ], [ 1024, %2 ]
%36 = phi i32 [ %13, %32 ], [ %13, %20 ], [ 102400, %2 ]
%37 = tail call i32 @strnlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 80)
%38 = icmp sgt i32 %37, 79
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = tail call i32 @exit(i32 %42)
unreachable
44: ; preds = %34
%45 = call i32 @strncpy(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 80)
br label %60
46: ; preds = %32
%47 = getelementptr inbounds i8*, i8** %1, i64 3
%48 = load i8*, i8** %47
%49 = tail call i32 @strnlen(i8* %48, i32 80)
%50 = icmp sgt i32 %49, 79
br i1 %50, label %51, label %56
51: ; preds = %46
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = tail call i32 @exit(i32 %54)
unreachable
56: ; preds = %46
%57 = load i8*, i8** %47
%58 = call i32 @strncpy(i8* %6, i8* %57, i32 80)
%59 = icmp ult i32 %0, 5
br i1 %59, label %60, label %70
60: ; preds = %44, %56
%61 = phi i32 [ %36, %44 ], [ %13, %56 ]
%62 = phi i32 [ %35, %44 ], [ %25, %56 ]
%63 = call i32 @strnlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 80)
%64 = icmp sgt i32 %63, 79
br i1 %64, label %65, label %82
65: ; preds = %60
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
70: ; preds = %56
%71 = getelementptr inbounds i8*, i8** %1, i64 4
%72 = load i8*, i8** %71
%73 = call i32 @strnlen(i8* %72, i32 80)
%74 = icmp sgt i32 %73, 79
br i1 %74, label %75, label %80
75: ; preds = %70
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; preds = %70
%81 = load i8*, i8** %71
br label %82
82: ; preds = %60, %80
%83 = phi i8* [ %81, %80 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), %60 ]
%84 = phi i32 [ %13, %80 ], [ %61, %60 ]
%85 = phi i32 [ %25, %80 ], [ %62, %60 ]
%86 = call i32 @strncpy(i8* %8, i8* %83, i32 80)
%87 = icmp ugt i32 %85, %84
br i1 %87, label %88, label %93
88: ; preds = %82
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0))
%91 = load i32, i32* @EXIT_FAILURE
%92 = call i32 @exit(i32 %91)
unreachable
93: ; preds = %82
%94 = urem i32 %84, %85
%95 = icmp eq i32 %94, 0
br i1 %95, label %101, label %96
96: ; preds = %93
%97 = load i32, i32* @stderr
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0))
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %93
%102 = call i8* @malloc(i32 %85)
%103 = icmp eq i8* %102, null
br i1 %103, label %104, label %108
104: ; preds = %101
%105 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0))
%106 = load i32, i32* @EXIT_FAILURE
%107 = call i32 @exit(i32 %106)
unreachable
108: ; preds = %101
%109 = load i32, i32* @O_RDONLY
%110 = load i32, i32* @O_SYNC
%111 = or i32 %110, %109
%112 = call i32 (i8*, i32, ...) @open(i8* %6, i32 %111)
%113 = icmp slt i32 %112, 0
br i1 %113, label %114, label %118
114: ; preds = %108
%115 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0))
%116 = load i32, i32* @EXIT_FAILURE
%117 = call i32 @exit(i32 %116)
unreachable
118: ; preds = %108
%119 = call i32 (...) @getpid()
%120 = call i32 @snprintf(i8* %7, i32 80, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i64 0, i64 0), i8* %8, i32 %119)
%121 = icmp sgt i32 %120, 80
br i1 %121, label %122, label %127
122: ; preds = %118
%123 = load i32, i32* @stderr
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.13, i64 0, i64 0), i32 80)
%125 = load i32, i32* @EXIT_FAILURE
%126 = call i32 @exit(i32 %125)
unreachable
127: ; preds = %118
%128 = icmp slt i32 %120, 0
br i1 %128, label %129, label %133
129: ; preds = %127
%130 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.14, i64 0, i64 0))
%131 = load i32, i32* @EXIT_FAILURE
%132 = call i32 @exit(i32 %131)
unreachable
133: ; preds = %127
%134 = load i32, i32* @O_WRONLY
%135 = load i32, i32* @O_CREAT
%136 = or i32 %135, %134
%137 = load i32, i32* @O_TRUNC
%138 = or i32 %136, %137
%139 = load i32, i32* @O_SYNC
%140 = or i32 %138, %139
%141 = load i32, i32* @S_IRUSR
%142 = load i32, i32* @S_IWUSR
%143 = or i32 %142, %141
%144 = load i32, i32* @S_IRGRP
%145 = or i32 %143, %144
%146 = load i32, i32* @S_IWGRP
%147 = or i32 %145, %146
%148 = load i32, i32* @S_IROTH
%149 = or i32 %147, %148
%150 = call i32 (i8*, i32, ...) @open(i8* %7, i32 %140, i32 %149)
%151 = icmp slt i32 %150, 0
br i1 %151, label %152, label %156
152: ; preds = %133
%153 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.15, i64 0, i64 0))
%154 = load i32, i32* @EXIT_FAILURE
%155 = call i32 @exit(i32 %154)
unreachable
156: ; preds = %133
%157 = load i32, i32* @stdout
%158 = call i32 (i32, i8*, ...) @fprintf(i32 %157, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.16, i64 0, i64 0), i8* %6, i8* %7)
br label %159
159: ; preds = %195, %156
%160 = phi i32 [ 0, %156 ], [ %172, %195 ]
%161 = phi i32 [ 0, %156 ], [ %173, %195 ]
%162 = phi i32 [ 0, %156 ], [ %196, %195 ]
%163 = phi i32 [ 0, %156 ], [ %197, %195 ]
%164 = phi i32 [ 0, %156 ], [ %198, %195 ]
%165 = call i32 @read(i32 %112, i8* %102, i32 %85)
%166 = icmp slt i32 %165, 0
br i1 %166, label %167, label %171
167: ; preds = %159
%168 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.17, i64 0, i64 0))
%169 = load i32, i32* @EXIT_FAILURE
%170 = call i32 @exit(i32 %169)
unreachable
171: ; preds = %159
%172 = add nsw i32 %165, %160
%173 = add nuw nsw i32 %161, 1
%174 = icmp eq i32 %165, %85
br i1 %174, label %175, label %185
175: ; preds = %171
%176 = call i32 @write(i32 %150, i8* %102, i32 %85)
%177 = icmp slt i32 %176, 0
br i1 %177, label %178, label %182
178: ; preds = %175
%179 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.18, i64 0, i64 0))
%180 = load i32, i32* @EXIT_FAILURE
%181 = call i32 @exit(i32 %180)
unreachable
182: ; preds = %175
%183 = add nsw i32 %176, %162
%184 = add nsw i32 %163, 1
br label %195
185: ; preds = %171
%186 = load i32, i32* @SEEK_SET
%187 = call i64 @lseek(i32 %112, i32 0, i32 %186)
%188 = icmp eq i64 %187, 0
br i1 %188, label %193, label %189
189: ; preds = %185
%190 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.19, i64 0, i64 0))
%191 = load i32, i32* @EXIT_FAILURE
%192 = call i32 @exit(i32 %191)
unreachable
193: ; preds = %185
%194 = add nsw i32 %164, 1
br label %195
195: ; preds = %182, %193
%196 = phi i32 [ %183, %182 ], [ %162, %193 ]
%197 = phi i32 [ %184, %182 ], [ %163, %193 ]
%198 = phi i32 [ %164, %182 ], [ %194, %193 ]
%199 = icmp slt i32 %196, %84
br i1 %199, label %159, label %200
200: ; preds = %195
%201 = load i32, i32* @stdout
%202 = call i32 (i32, i8*, ...) @fprintf(i32 %201, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.20, i64 0, i64 0), i32 %172, i32 %173)
%203 = load i32, i32* @stdout
%204 = call i32 (i32, i8*, ...) @fprintf(i32 %203, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.21, i64 0, i64 0), i32 %196, i32 %197)
%205 = load i32, i32* @stdout
%206 = add nsw i32 %198, 1
%207 = icmp eq i32 %198, 0
%208 = select i1 %207, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.24, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.23, i64 0, i64 0)
%209 = call i32 (i32, i8*, ...) @fprintf(i32 %205, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.22, i64 0, i64 0), i32 %206, i8* %208)
%210 = load i32, i32* @stdout
%211 = call i32 (i32, i8*, ...) @fprintf(i32 %210, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.25, i64 0, i64 0), i32 %84, i32 %85)
%212 = call i32 @free(i8* %102)
%213 = call i64 @close(i32 %150)
%214 = icmp eq i64 %213, 0
br i1 %214, label %219, label %215
215: ; preds = %200
%216 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.26, i64 0, i64 0))
%217 = load i32, i32* @EXIT_FAILURE
%218 = call i32 @exit(i32 %217)
unreachable
219: ; preds = %200
%220 = call i64 @close(i32 %112)
%221 = icmp eq i64 %220, 0
br i1 %221, label %226, label %222
222: ; preds = %219
%223 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.27, i64 0, i64 0))
%224 = load i32, i32* @EXIT_FAILURE
%225 = call i32 @exit(i32 %224)
unreachable
226: ; preds = %219
%227 = load i32, i32* @EXIT_SUCCESS
ret i32 %227
}