#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 stat {
  int st_size;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ FIGETBSZ;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ fstat(int, struct stat *);
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
unsigned char *malloc(int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int /*<<< orphan*/ readmap(int);
int /*<<< orphan*/ stderr;
int write(int, unsigned char *, int);
int main(int argc, char **argv) {
  struct stat statinfo1;
  int fd1, fd2, fd3;
  int num_blocks;
  int block_size;
  unsigned int i;
  int sparse_blocks;
  int copied_blocks;
  int percent = -1;
  unsigned char *buffer1;
  if (argc != 4) {
    fprintf(stderr, "%s merge a sparsemap and a data file to a sparse file.\n",
            argv[0]);
    fprintf(stderr, "Usage: %s MAPFILE DATA SPARSEFILE\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fd1 = open(argv[1], O_RDONLY)) < 0) {
    fprintf(stderr, "Cannot open %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  if ((fd2 = open(argv[2], O_RDONLY)) < 0) {
    fprintf(stderr, "Cannot open %s\n", argv[2]);
    close(fd1);
    exit(EXIT_FAILURE);
  }
  if (ioctl(fd2, FIGETBSZ, &block_size) < 0) {
    fprintf(stderr, "Cannot get block size\n");
    close(fd1);
    close(fd2);
    exit(EXIT_FAILURE);
  }
  if (fstat(fd2, &statinfo1) < 0) {
    fprintf(stderr, "Cannot stat %s\n", argv[1]);
    close(fd1);
    close(fd2);
    exit(EXIT_FAILURE);
  }
  num_blocks = (statinfo1.st_size + block_size - 1) / block_size;
  if ((fd3 = open(argv[3], O_WRONLY | O_CREAT | O_TRUNC, 0777)) < 0) {
    fprintf(stderr, "Cannot open %s\n", argv[3]);
    close(fd1);
    close(fd2);
    exit(EXIT_FAILURE);
  }
  buffer1 = malloc(block_size);
  if (!buffer1) {
    fprintf(stderr, "Cannot allocate buffer\n");
    close(fd1);
    close(fd2);
    close(fd3);
    exit(EXIT_FAILURE);
  }
  sparse_blocks = 0;
  copied_blocks = 0;
  for (i = 0; i < num_blocks;) {
    int nread = 0;
    if (percent != ((i + 1) * 100 / num_blocks)) {
      percent = (i + 1) * 100 / num_blocks;
      printf("%08d/%08d (%d%%), S:%08d, C:%08d  \r", i + 1, num_blocks, percent,
             sparse_blocks, copied_blocks);
      fflush(0);
    }
    if (!readmap(fd1)) {
      if (lseek(fd3, block_size, SEEK_CUR) < 0) {
        fprintf(stderr, "Seek failed.\n");
        close(fd1);
        close(fd2);
        close(fd3);
        exit(EXIT_FAILURE);
      }
      sparse_blocks++;
      continue;
    }
    nread = read(fd2, buffer1, block_size);
    if (nread < block_size) {
      if (i != (num_blocks - 1)) {
        fprintf(stderr, "Unexpected short read.\n");
        close(fd1);
        close(fd2);
        close(fd3);
        exit(EXIT_FAILURE);
      }
    }
    if (nread == -1) {
      fprintf(stderr, "Cannot read block %d on %s\n", i, argv[2]);
    } else {
      if (write(fd3, buffer1, nread) != nread) {
        fprintf(stderr, "Cannot write block %d on %s\n", i, argv[3]);
        close(fd1);
        close(fd2);
        close(fd3);
        exit(EXIT_FAILURE);
      } else {
        copied_blocks++;
        i++;
      }
    }
  }
  close(fd1);
  free(buffer1);
  close(fd2);
  close(fd3);
  printf("\n");
  printf("Report:\n");
  printf("%d byte block size\n", block_size);
  printf("   total %08d blocks\n", num_blocks);
  printf("Inserted %08d sparse blocks\n", sparse_blocks);
  printf("  copied %08d data blocks\n", copied_blocks);
  printf("  ------------------------------------\n");
  printf("   Sum:  %08d blocks accounted for.\n",
         (sparse_blocks + copied_blocks));
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1251 <main+0x71>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12a2 <main+0xc2>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d17(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    12fb <main+0x11b>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x20(%rbp),%edi
mov    0x2ccb(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    134f <main+0x16f>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x20(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1100 <fstat@plt>
cmp    $0x0,%rax
jge    13a2 <main+0x1c2>
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd05(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    0x2c15(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%eax
add    -0x2c(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0x2c(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2bd7(%rip),%rax
mov    (%rax),%esi
mov    0x2c2e(%rip),%rax
or     (%rax),%esi
mov    0x2c1d(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    142a <main+0x24a>
mov    0x2bc4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xc56(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    0x2b8d(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x2c(%rbp),%edi
call   10b0 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    147e <main+0x29e>
mov    0x2b70(%rip),%rax
mov    (%rax),%edi
lea    0xc41(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jae    1699 <main+0x4b9>
movl   $0x0,-0x4c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
imul   $0x64,%eax,%eax
xor    %edx,%edx
divl   -0x28(%rbp)
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
cmp    %ecx,%eax
je     1501 <main+0x321>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
imul   $0x64,%eax,%eax
xor    %edx,%edx
divl   -0x28(%rbp)
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%esi
add    $0x1,%esi
mov    -0x28(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x38(%rbp),%r9d
lea    0xbb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10c0 <fflush@plt>
mov    -0x1c(%rbp),%edi
call   10e0 <readmap@plt>
cmp    $0x0,%eax
jne    157b <main+0x39b>
mov    -0x24(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    0x2ab9(%rip),%rax
mov    (%rax),%edx
call   1060 <lseek@plt>
cmp    $0x0,%rax
jge    156d <main+0x38d>
mov    0x2a81(%rip),%rax
mov    (%rax),%edi
lea    0xb8e(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    0x2a4a(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1493 <main+0x2b3>
mov    -0x20(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1090 <read@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    15ec <main+0x40c>
mov    -0x30(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     15e7 <main+0x407>
mov    0x2a07(%rip),%rax
mov    (%rax),%edi
lea    0xb22(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    0x29d0(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
jmp    15ec <main+0x40c>
cmpl   $0xffffffff,-0x4c(%rbp)
jne    161d <main+0x43d>
mov    0x29bb(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xae3(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    1694 <main+0x4b4>
mov    -0x24(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1040 <write@plt>
cmp    -0x4c(%rbp),%eax
je     167d <main+0x49d>
mov    0x297c(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
lea    0xac0(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    0x293a(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1694 <main+0x4b4>
jmp    1493 <main+0x2b3>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
lea    0xafd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xa5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xa56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xa59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%esi
lea    0xa5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%esi
lea    0xa6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xa77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%esi
add    -0x38(%rbp),%esi
lea    0xa8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2865(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    1249 <main+0x49>
mov    0x8(%rbx),%rdi
mov    0x2da7(%rip),%rbp
mov    0x0(%rbp),%esi
xor    %eax,%eax
call   10f0 <open@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
jns    127d <main+0x7d>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe14(%rip),%rsi
jmp    1271 <main+0x71>
mov    0x2d68(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xda3(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xdc7(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    1385 <main+0x185>
mov    0x10(%rbx),%rdi
mov    0x0(%rbp),%esi
xor    %eax,%eax
call   10f0 <open@plt>
test   %eax,%eax
jns    12b3 <main+0xb3>
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbx),%rdx
lea    0xdb8(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x4(%rsp),%edi
jmp    1380 <main+0x180>
mov    %eax,%ebp
mov    0x2d14(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   1090 <ioctl@plt>
test   %rax,%rax
jns    12eb <main+0xeb>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    1375 <main+0x175>
lea    0x28(%rsp),%rsi
mov    %ebp,%edi
call   1120 <fstat@plt>
test   %rax,%rax
jns    1312 <main+0x112>
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xd72(%rip),%rsi
jmp    136e <main+0x16e>
mov    0x28(%rsp),%eax
mov    0xc(%rsp),%ecx
add    %ecx,%eax
add    $0xffffffff,%eax
cltd
idiv   %ecx
mov    %rax,0x18(%rsp)
mov    0x2c6a(%rip),%rax
mov    0x2cc3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x18(%rbx),%rdi
mov    0x2cac(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   10f0 <open@plt>
mov    %eax,0x8(%rsp)
test   %eax,%eax
jns    1393 <main+0x193>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rbx),%rdx
lea    0xced(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x4(%rsp),%edi
call   10a0 <close@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    0xc(%rsp),%edi
call   10d0 <malloc@plt>
mov    %rax,0x20(%rsp)
test   %rax,%rax
jne    13d3 <main+0x1d3>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
lea    0xcdc(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x4(%rsp),%edi
call   10a0 <close@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    0x8(%rsp),%edi
jmp    1380 <main+0x180>
mov    %rbx,0x30(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x14(%rsp)
mov    0x18(%rsp),%rbx
test   %ebx,%ebx
jne    14a4 <main+0x2a4>
mov    0x4(%rsp),%edi
call   10a0 <close@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
mov    0x8(%rsp),%edi
call   10a0 <close@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xd8b(%rip),%rdi
call   1050 <puts@plt>
mov    0xc(%rsp),%esi
lea    0xcf4(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xcfa(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd00(%rip),%rdi
mov    0x10(%rsp),%ebp
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd09(%rip),%rdi
mov    0x14(%rsp),%ebx
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd3d(%rip),%rdi
call   1050 <puts@plt>
add    %ebp,%ebx
lea    0xd02(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2b0b(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
lea    -0x1(%rbx),%eax
mov    %eax,0x2c(%rsp)
mov    $0xffffffff,%r14d
xor    %r12d,%r12d
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
jmp    1503 <main+0x303>
cs nopw 0x0(%rax,%rax,1)
mov    0x2ae1(%rip),%rax
mov    (%rax),%edi
mov    0x30(%rsp),%rax
mov    0x10(%rax),%rcx
lea    0xc0b(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %ebx,%ebp
mov    0x18(%rsp),%rbx
cmp    %ebx,%r12d
jae    13f5 <main+0x1f5>
lea    0x1(%r12),%r13d
imul   $0x64,%r13d,%eax
xor    %edx,%edx
div    %ebx
cmp    %eax,%r14d
je     1541 <main+0x341>
mov    %eax,%r15d
lea    0xb8b(%rip),%rdi
mov    %r13d,%esi
mov    %ebx,%edx
mov    %eax,%ecx
mov    0x10(%rsp),%r8d
mov    0x14(%rsp),%r9d
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10e0 <fflush@plt>
mov    %r15d,%r14d
mov    0x4(%rsp),%edi
call   1100 <readmap@plt>
mov    0xc(%rsp),%edx
test   %eax,%eax
je     15a0 <main+0x3a0>
mov    %ebp,%ebx
mov    %ebp,%edi
mov    0x20(%rsp),%rsi
call   10b0 <read@plt>
mov    %eax,%ebp
cmp    0xc(%rsp),%eax
jge    156f <main+0x36f>
cmp    0x2c(%rsp),%r12d
jne    15ce <main+0x3ce>
cmp    $0xffffffff,%ebp
je     14d0 <main+0x2d0>
mov    0x8(%rsp),%edi
mov    0x20(%rsp),%rsi
mov    %ebp,%edx
call   1060 <write@plt>
cmp    %ebp,%eax
jne    15e7 <main+0x3e7>
addl   $0x1,0x14(%rsp)
mov    %r13d,%r12d
jmp    14f3 <main+0x2f3>
nopl   0x0(%rax)
mov    0x2a31(%rip),%rax
mov    (%rax),%eax
mov    0x8(%rsp),%edi
mov    %edx,%esi
mov    %eax,%edx
call   1080 <lseek@plt>
test   %rax,%rax
js     161a <main+0x41a>
addl   $0x1,0x10(%rsp)
cmp    %ebx,%r12d
jb     1503 <main+0x303>
jmp    13f5 <main+0x1f5>
mov    0x29e3(%rip),%rax
mov    (%rax),%edi
lea    0xafe(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
jmp    160a <main+0x40a>
mov    0x29ca(%rip),%rax
mov    (%rax),%edi
mov    0x30(%rsp),%rax
mov    0x18(%rax),%rcx
lea    0xb10(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x4(%rsp),%edi
call   10a0 <close@plt>
mov    %ebx,%edi
jmp    13c8 <main+0x1c8>
mov    0x2997(%rip),%rax
mov    (%rax),%edi
lea    0xaa4(%rip),%rsi
jmp    13b6 <main+0x1b6>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [56 x i8] c"%s merge a sparsemap and a data file to a sparse file.\0A\00"
@.str.1 = [35 x i8] c"Usage: %s MAPFILE DATA SPARSEFILE\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
@FIGETBSZ = global i32 0
@.str.3 = [23 x i8] c"Cannot get block size\0A\00"
@.str.4 = [16 x i8] c"Cannot stat %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.5 = [24 x i8] c"Cannot allocate buffer\0A\00"
@.str.6 = [36 x i8] c"%08d/%08d (%d%%), S:%08d, C:%08d \0D\00"
@SEEK_CUR = global i32 0
@.str.7 = [14 x i8] c"Seek failed.\0A\00"
@.str.8 = [24 x i8] c"Unexpected short read.\0A\00"
@.str.9 = [28 x i8] c"Cannot read block %d on %s\0A\00"
@.str.10 = [29 x i8] c"Cannot write block %d on %s\0A\00"
@.str.11 = [2 x i8] c"\0A\00"
@.str.12 = [9 x i8] c"Report:\0A\00"
@.str.13 = [20 x i8] c"%d byte block size\0A\00"
@.str.14 = [22 x i8] c" total %08d blocks\0A\00"
@.str.15 = [29 x i8] c"Inserted %08d sparse blocks\0A\00"
@.str.16 = [27 x i8] c" copied %08d data blocks\0A\00"
@.str.17 = [40 x i8] c" ------------------------------------\0A\00"
@.str.18 = [37 x i8] c" Sum: %08d blocks accounted for.\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 %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %15
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 4
br i1 %19, label %20, label %33
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_RDONLY
%38 = call i32 (i8*, i32, ...) @open(i8* %36, i32 %37)
store i32 %38, i32* %7
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %48
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %33
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = load i32, i32* @O_RDONLY
%53 = call i32 (i8*, i32, ...) @open(i8* %51, i32 %52)
store i32 %53, i32* %8
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %48
%56 = load i32, i32* @stderr
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %59)
%61 = load i32, i32* %7
%62 = call i32 @close(i32 %61)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %48
%66 = load i32, i32* %8
%67 = load i32, i32* @FIGETBSZ
%68 = call i64 @ioctl(i32 %66, i32 %67, i32* %11)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %79
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%73 = load i32, i32* %7
%74 = call i32 @close(i32 %73)
%75 = load i32, i32* %8
%76 = call i32 @close(i32 %75)
%77 = load i32, i32* @EXIT_FAILURE
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %65
%80 = load i32, i32* %8
%81 = call i64 @fstat(i32 %80, %struct.stat* %6)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %95
83: ; preds = %79
%84 = load i32, i32* @stderr
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 1
%87 = load i8*, i8** %86
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %87)
%89 = load i32, i32* %7
%90 = call i32 @close(i32 %89)
%91 = load i32, i32* %8
%92 = call i32 @close(i32 %91)
%93 = load i32, i32* @EXIT_FAILURE
%94 = call i32 @exit(i32 %93)
unreachable
95: ; preds = %79
%96 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%97 = load i32, i32* %96
%98 = load i32, i32* %11
%99 = add nsw i32 %97, %98
%100 = sub nsw i32 %99, 1
%101 = load i32, i32* %11
%102 = sdiv i32 %100, %101
store i32 %102, i32* %10
%103 = load i8**, i8*** %5
%104 = getelementptr inbounds i8*, i8** %103, i64 3
%105 = load i8*, i8** %104
%106 = load i32, i32* @O_WRONLY
%107 = load i32, i32* @O_CREAT
%108 = or i32 %106, %107
%109 = load i32, i32* @O_TRUNC
%110 = or i32 %108, %109
%111 = call i32 (i8*, i32, ...) @open(i8* %105, i32 %110, i32 511)
store i32 %111, i32* %9
%112 = icmp slt i32 %111, 0
br i1 %112, label %113, label %125
113: ; preds = %95
%114 = load i32, i32* @stderr
%115 = load i8**, i8*** %5
%116 = getelementptr inbounds i8*, i8** %115, i64 3
%117 = load i8*, i8** %116
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %117)
%119 = load i32, i32* %7
%120 = call i32 @close(i32 %119)
%121 = load i32, i32* %8
%122 = call i32 @close(i32 %121)
%123 = load i32, i32* @EXIT_FAILURE
%124 = call i32 @exit(i32 %123)
unreachable
125: ; preds = %95
%126 = load i32, i32* %11
%127 = call i8* @malloc(i32 %126)
store i8* %127, i8** %16
%128 = load i8*, i8** %16
%129 = icmp ne i8* %128, null
br i1 %129, label %141, label %130
130: ; preds = %125
%131 = load i32, i32* @stderr
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%133 = load i32, i32* %7
%134 = call i32 @close(i32 %133)
%135 = load i32, i32* %8
%136 = call i32 @close(i32 %135)
%137 = load i32, i32* %9
%138 = call i32 @close(i32 %137)
%139 = load i32, i32* @EXIT_FAILURE
%140 = call i32 @exit(i32 %139)
unreachable
141: ; preds = %125
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %12
br label %142
142: ; preds = %255, %189, %141
%143 = load i32, i32* %12
%144 = load i32, i32* %10
%145 = icmp ult i32 %143, %144
br i1 %145, label %146, label %256
146: ; preds = %142
store i32 0, i32* %17
%147 = load i32, i32* %15
%148 = load i32, i32* %12
%149 = add i32 %148, 1
%150 = mul i32 %149, 100
%151 = load i32, i32* %10
%152 = udiv i32 %150, %151
%153 = icmp ne i32 %147, %152
br i1 %153, label %154, label %168
154: ; preds = %146
%155 = load i32, i32* %12
%156 = add i32 %155, 1
%157 = mul i32 %156, 100
%158 = load i32, i32* %10
%159 = udiv i32 %157, %158
store i32 %159, i32* %15
%160 = load i32, i32* %12
%161 = add i32 %160, 1
%162 = load i32, i32* %10
%163 = load i32, i32* %15
%164 = load i32, i32* %13
%165 = load i32, i32* %14
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %161, i32 %162, i32 %163, i32 %164, i32 %165)
%167 = call i32 @fflush(i32 0)
br label %168
168: ; preds = %154, %146
%169 = load i32, i32* %7
%170 = call i32 @readmap(i32 %169)
%171 = icmp ne i32 %170, 0
br i1 %171, label %192, label %172
172: ; preds = %168
%173 = load i32, i32* %9
%174 = load i32, i32* %11
%175 = load i32, i32* @SEEK_CUR
%176 = call i64 @lseek(i32 %173, i32 %174, i32 %175)
%177 = icmp slt i64 %176, 0
br i1 %177, label %178, label %189
178: ; preds = %172
%179 = load i32, i32* @stderr
%180 = call i32 (i32, i8*, ...) @fprintf(i32 %179, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%181 = load i32, i32* %7
%182 = call i32 @close(i32 %181)
%183 = load i32, i32* %8
%184 = call i32 @close(i32 %183)
%185 = load i32, i32* %9
%186 = call i32 @close(i32 %185)
%187 = load i32, i32* @EXIT_FAILURE
%188 = call i32 @exit(i32 %187)
unreachable
189: ; preds = %172
%190 = load i32, i32* %13
%191 = add nsw i32 %190, 1
store i32 %191, i32* %13
br label %142
192: ; preds = %168
%193 = load i32, i32* %8
%194 = load i8*, i8** %16
%195 = load i32, i32* %11
%196 = call i32 @read(i32 %193, i8* %194, i32 %195)
store i32 %196, i32* %17
%197 = load i32, i32* %17
%198 = load i32, i32* %11
%199 = icmp slt i32 %197, %198
br i1 %199, label %200, label %217
200: ; preds = %192
%201 = load i32, i32* %12
%202 = load i32, i32* %10
%203 = sub nsw i32 %202, 1
%204 = icmp ne i32 %201, %203
br i1 %204, label %205, label %216
205: ; preds = %200
%206 = load i32, i32* @stderr
%207 = call i32 (i32, i8*, ...) @fprintf(i32 %206, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%208 = load i32, i32* %7
%209 = call i32 @close(i32 %208)
%210 = load i32, i32* %8
%211 = call i32 @close(i32 %210)
%212 = load i32, i32* %9
%213 = call i32 @close(i32 %212)
%214 = load i32, i32* @EXIT_FAILURE
%215 = call i32 @exit(i32 %214)
unreachable
216: ; preds = %200
br label %217
217: ; preds = %216, %192
%218 = load i32, i32* %17
%219 = icmp eq i32 %218, -1
br i1 %219, label %220, label %227
220: ; preds = %217
%221 = load i32, i32* @stderr
%222 = load i32, i32* %12
%223 = load i8**, i8*** %5
%224 = getelementptr inbounds i8*, i8** %223, i64 2
%225 = load i8*, i8** %224
%226 = call i32 (i32, i8*, ...) @fprintf(i32 %221, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i32 %222, i8* %225)
br label %255
227: ; preds = %217
%228 = load i32, i32* %9
%229 = load i8*, i8** %16
%230 = load i32, i32* %17
%231 = call i32 @write(i32 %228, i8* %229, i32 %230)
%232 = load i32, i32* %17
%233 = icmp ne i32 %231, %232
br i1 %233, label %234, label %249
234: ; preds = %227
%235 = load i32, i32* @stderr
%236 = load i32, i32* %12
%237 = load i8**, i8*** %5
%238 = getelementptr inbounds i8*, i8** %237, i64 3
%239 = load i8*, i8** %238
%240 = call i32 (i32, i8*, ...) @fprintf(i32 %235, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i32 %236, i8* %239)
%241 = load i32, i32* %7
%242 = call i32 @close(i32 %241)
%243 = load i32, i32* %8
%244 = call i32 @close(i32 %243)
%245 = load i32, i32* %9
%246 = call i32 @close(i32 %245)
%247 = load i32, i32* @EXIT_FAILURE
%248 = call i32 @exit(i32 %247)
unreachable
249: ; preds = %227
%250 = load i32, i32* %14
%251 = add nsw i32 %250, 1
store i32 %251, i32* %14
%252 = load i32, i32* %12
%253 = add i32 %252, 1
store i32 %253, i32* %12
br label %254
254: ; preds = %249
br label %255
255: ; preds = %254, %220
br label %142
256: ; preds = %142
%257 = load i32, i32* %7
%258 = call i32 @close(i32 %257)
%259 = load i8*, i8** %16
%260 = call i32 @free(i8* %259)
%261 = load i32, i32* %8
%262 = call i32 @close(i32 %261)
%263 = load i32, i32* %9
%264 = call i32 @close(i32 %263)
%265 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%266 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%267 = load i32, i32* %11
%268 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i32 %267)
%269 = load i32, i32* %10
%270 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i32 %269)
%271 = load i32, i32* %13
%272 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0), i32 %271)
%273 = load i32, i32* %14
%274 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.16, i64 0, i64 0), i32 %273)
%275 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.17, i64 0, i64 0))
%276 = load i32, i32* %13
%277 = load i32, i32* %14
%278 = add nsw i32 %276, %277
%279 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.18, i64 0, i64 0), i32 %278)
%280 = load i32, i32* @EXIT_SUCCESS
%281 = call i32 @exit(i32 %280)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [56 x i8] c"%s merge a sparsemap and a data file to a sparse file.\0A\00"
@.str.1 = [35 x i8] c"Usage: %s MAPFILE DATA SPARSEFILE\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
@FIGETBSZ = global i32 0
@.str.3 = [23 x i8] c"Cannot get block size\0A\00"
@.str.4 = [16 x i8] c"Cannot stat %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.5 = [24 x i8] c"Cannot allocate buffer\0A\00"
@.str.6 = [36 x i8] c"%08d/%08d (%d%%), S:%08d, C:%08d \0D\00"
@SEEK_CUR = global i32 0
@.str.7 = [14 x i8] c"Seek failed.\0A\00"
@.str.8 = [24 x i8] c"Unexpected short read.\0A\00"
@.str.9 = [28 x i8] c"Cannot read block %d on %s\0A\00"
@.str.10 = [29 x i8] c"Cannot write block %d on %s\0A\00"
@.str.13 = [20 x i8] c"%d byte block size\0A\00"
@.str.14 = [22 x i8] c" total %08d blocks\0A\00"
@.str.15 = [29 x i8] c"Inserted %08d sparse blocks\0A\00"
@.str.16 = [27 x i8] c" copied %08d data blocks\0A\00"
@.str.18 = [37 x i8] c" Sum: %08d blocks accounted for.\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [8 x i8] c"Report:\00"
@str.19 = [39 x i8] c" ------------------------------------\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca i32
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 4
br i1 %7, label %17, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = tail call i32 (i8*, i32, ...) @open(i8* %19, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %18
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %17
%30 = getelementptr inbounds i8*, i8** %1, i64 2
%31 = load i8*, i8** %30
%32 = load i32, i32* @O_RDONLY
%33 = tail call i32 (i8*, i32, ...) @open(i8* %31, i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %30
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = tail call i32 @close(i32 %21)
%40 = load i32, i32* @EXIT_FAILURE
%41 = tail call i32 @exit(i32 %40)
unreachable
42: ; preds = %29
%43 = load i32, i32* @FIGETBSZ
%44 = call i64 @ioctl(i32 %33, i32 %43, i32* %4)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @close(i32 %21)
%50 = call i32 @close(i32 %33)
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %42
%54 = call i64 @fstat(i32 %33, %struct.stat* %3)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %64
56: ; preds = %53
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %18
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %58)
%60 = call i32 @close(i32 %21)
%61 = call i32 @close(i32 %33)
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %53
%65 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%66 = load i32, i32* %65
%67 = load i32, i32* %4
%68 = add i32 %66, -1
%69 = add i32 %68, %67
%70 = sdiv i32 %69, %67
%71 = getelementptr inbounds i8*, i8** %1, i64 3
%72 = load i8*, i8** %71
%73 = load i32, i32* @O_WRONLY
%74 = load i32, i32* @O_CREAT
%75 = or i32 %74, %73
%76 = load i32, i32* @O_TRUNC
%77 = or i32 %75, %76
%78 = call i32 (i8*, i32, ...) @open(i8* %72, i32 %77, i32 511)
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %88
80: ; preds = %64
%81 = load i32, i32* @stderr
%82 = load i8*, i8** %71
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %82)
%84 = call i32 @close(i32 %21)
%85 = call i32 @close(i32 %33)
%86 = load i32, i32* @EXIT_FAILURE
%87 = call i32 @exit(i32 %86)
unreachable
88: ; preds = %64
%89 = load i32, i32* %4
%90 = call i8* @malloc(i32 %89)
%91 = icmp eq i8* %90, null
br i1 %91, label %96, label %92
92: ; preds = %88
%93 = icmp eq i32 %70, 0
br i1 %93, label %174, label %94
94: ; preds = %92
%95 = add nsw i32 %70, -1
br label %104
96: ; preds = %88
%97 = load i32, i32* @stderr
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%99 = call i32 @close(i32 %21)
%100 = call i32 @close(i32 %33)
%101 = call i32 @close(i32 %78)
%102 = load i32, i32* @EXIT_FAILURE
%103 = call i32 @exit(i32 %102)
unreachable
104: ; preds = %94, %169
%105 = phi i32 [ 0, %94 ], [ %172, %169 ]
%106 = phi i32 [ -1, %94 ], [ %117, %169 ]
%107 = phi i32 [ 0, %94 ], [ %171, %169 ]
%108 = phi i32 [ 0, %94 ], [ %170, %169 ]
%109 = add nuw i32 %105, 1
%110 = mul i32 %109, 100
%111 = udiv i32 %110, %70
%112 = icmp eq i32 %106, %111
br i1 %112, label %116, label %113
113: ; preds = %104
%114 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %109, i32 %70, i32 %111, i32 %108, i32 %107)
%115 = call i32 @fflush(i32 0)
br label %116
116: ; preds = %113, %104
%117 = phi i32 [ %111, %113 ], [ %106, %104 ]
%118 = call i32 @readmap(i32 %21)
%119 = icmp eq i32 %118, 0
%120 = load i32, i32* %4
br i1 %119, label %121, label %135
121: ; preds = %116
%122 = load i32, i32* @SEEK_CUR
%123 = call i64 @lseek(i32 %78, i32 %120, i32 %122)
%124 = icmp slt i64 %123, 0
br i1 %124, label %125, label %133
125: ; preds = %121
%126 = load i32, i32* @stderr
%127 = call i32 (i32, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%128 = call i32 @close(i32 %21)
%129 = call i32 @close(i32 %33)
%130 = call i32 @close(i32 %78)
%131 = load i32, i32* @EXIT_FAILURE
%132 = call i32 @exit(i32 %131)
unreachable
133: ; preds = %121
%134 = add nsw i32 %108, 1
br label %169
135: ; preds = %116
%136 = call i32 @read(i32 %33, i8* %90, i32 %120)
%137 = load i32, i32* %4
%138 = icmp sge i32 %136, %137
%139 = icmp eq i32 %105, %95
%140 = select i1 %138, i1 true, i1 %139
br i1 %140, label %149, label %141
141: ; preds = %135
%142 = load i32, i32* @stderr
%143 = call i32 (i32, i8*, ...) @fprintf(i32 %142, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%144 = call i32 @close(i32 %21)
%145 = call i32 @close(i32 %33)
%146 = call i32 @close(i32 %78)
%147 = load i32, i32* @EXIT_FAILURE
%148 = call i32 @exit(i32 %147)
unreachable
149: ; preds = %135
%150 = icmp eq i32 %136, -1
br i1 %150, label %151, label %155
151: ; preds = %149
%152 = load i32, i32* @stderr
%153 = load i8*, i8** %30
%154 = call i32 (i32, i8*, ...) @fprintf(i32 %152, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i32 %105, i8* %153)
br label %169
155: ; preds = %149
%156 = call i32 @write(i32 %78, i8* %90, i32 %136)
%157 = icmp eq i32 %156, %136
br i1 %157, label %167, label %158
158: ; preds = %155
%159 = load i32, i32* @stderr
%160 = load i8*, i8** %71
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %159, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i32 %105, i8* %160)
%162 = call i32 @close(i32 %21)
%163 = call i32 @close(i32 %33)
%164 = call i32 @close(i32 %78)
%165 = load i32, i32* @EXIT_FAILURE
%166 = call i32 @exit(i32 %165)
unreachable
167: ; preds = %155
%168 = add nsw i32 %107, 1
br label %169
169: ; preds = %151, %167, %133
%170 = phi i32 [ %134, %133 ], [ %108, %167 ], [ %108, %151 ]
%171 = phi i32 [ %107, %133 ], [ %168, %167 ], [ %107, %151 ]
%172 = phi i32 [ %105, %133 ], [ %109, %167 ], [ %105, %151 ]
%173 = icmp ult i32 %172, %70
br i1 %173, label %104, label %174
174: ; preds = %169, %92
%175 = phi i32 [ 0, %92 ], [ %170, %169 ]
%176 = phi i32 [ 0, %92 ], [ %171, %169 ]
%177 = call i32 @close(i32 %21)
%178 = call i32 @free(i8* %90)
%179 = call i32 @close(i32 %33)
%180 = call i32 @close(i32 %78)
%181 = call i32 @putchar(i32 10)
%182 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%183 = load i32, i32* %4
%184 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i32 %183)
%185 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i32 %70)
%186 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0), i32 %175)
%187 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.16, i64 0, i64 0), i32 %176)
%188 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.19, i64 0, i64 0))
%189 = add nsw i32 %176, %175
%190 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.18, i64 0, i64 0), i32 %189)
%191 = load i32, i32* @EXIT_SUCCESS
%192 = call i32 @exit(i32 %191)
unreachable
}