#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*/ FIBMAP;
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*/ errno;
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*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syncmap(int);
int write(int, unsigned char *, int);
int /*<<< orphan*/ writemap(int, int);
int main(int argc, char **argv) {
  struct stat statinfo1;
  int fd1, fd2, fd3;
  int num_blocks;
  int block_size;
  int i;
  int sparse_blocks;
  int zero_blocks;
  int copied_blocks;
  int percent = -1;
  unsigned char *buffer1;
  if (argc != 4) {
    fprintf(stderr,
            "%s create a sparsemap and a data file from a sparsefile.\n",
            argv[0]);
    fprintf(stderr, "Usage: %s FILE MAPFILE DATA\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 (fstat(fd1, &statinfo1) < 0) {
    fprintf(stderr, "Cannot stat %s\n", argv[1]);
    close(fd1);
    exit(EXIT_FAILURE);
  }
  if (ioctl(fd1, FIGETBSZ, &block_size) < 0) {
    fprintf(stderr, "Cannot get block size\n");
    close(fd1);
    exit(EXIT_FAILURE);
  }
  num_blocks = (statinfo1.st_size + block_size - 1) / block_size;
  if ((fd2 = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0777)) < 0) {
    fprintf(stderr, "Cannot open %s\n", argv[2]);
    close(fd1);
    exit(EXIT_FAILURE);
  }
  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;
  zero_blocks = 0;
  copied_blocks = 0;
  for (i = 0; i < num_blocks; i++) {
    int block = i;
    int nread = 0;
    if (ioctl(fd1, FIBMAP, &block)) {
      printf("ioctl failed: %s in block %d, are you root ?\n", strerror(errno),
             i);
      close(fd1);
      close(fd2);
      close(fd3);
      exit(EXIT_FAILURE);
    }
    if (percent != ((i + 1) * 100 / num_blocks)) {
      percent = (i + 1) * 100 / num_blocks;
      printf("%08d/%08d (%d%%), S:%08d, Z:%08d, C:%08d  \r", i + 1, num_blocks,
             percent, sparse_blocks, zero_blocks, copied_blocks);
      fflush(0);
    }
    if (!block && i != (num_blocks - 1)) {
      if (lseek(fd1, block_size, SEEK_CUR) < 0) {
        fprintf(stderr, "Seek failed.\n");
        close(fd1);
        close(fd2);
        close(fd3);
        exit(EXIT_FAILURE);
      }
      sparse_blocks++;
      writemap(fd2, 0);
      continue;
    } else {
      nread = read(fd1, buffer1, block_size);
      if (nread < block_size) {
        if (i != (num_blocks - 1)) {
          fprintf(stderr, "Unexpected short read.\n");
          close(fd1);
          close(fd2);
          exit(EXIT_FAILURE);
        }
      }
      if (nread == -1) {
        fprintf(stderr, "Cannot read block %d on %s\n", i, argv[2]);
      } else {
        int n;
        for (n = 0; n < nread; n++) {
          if (buffer1[n])
            break;
        }
        if (n == nread && i != (num_blocks - 1)) {
          writemap(fd2, 0);
          zero_blocks++;
          continue;
        } else {
          if (write(fd3, buffer1, nread) != nread) {
            fprintf(stderr, "Cannot write block %d on %s\n", i, argv[3]);
          } else {
            writemap(fd2, 1);
            copied_blocks++;
            continue;
          }
        }
      }
    }
  }
  close(fd1);
  free(buffer1);
  syncmap(fd2);
  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("Skipped %08d sparse blocks\n", sparse_blocks);
  printf("  found %08d zero blocks (now sparse)\n", zero_blocks);
  printf(" copied %08d blocks\n", copied_blocks);
  printf("  ------------------------------------\n");
  printf("  Sum:  %08d blocks accounted for.\n",
         (sparse_blocks + zero_blocks + copied_blocks));
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x40(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1271 <main+0x71>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10f0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12c2 <main+0xc2>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1120 <fstat@plt>
cmp    $0x0,%rax
jge    130d <main+0x10d>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    0x2cb9(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
call   1080 <ioctl@plt>
cmp    $0x0,%rax
jge    1359 <main+0x159>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
lea    0xd3b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
call   1100 <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    0x10(%rax),%rdi
mov    0x2c10(%rip),%rax
mov    (%rax),%esi
mov    0x2c77(%rip),%rax
or     (%rax),%esi
mov    0x2c66(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   10f0 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    13d9 <main+0x1d9>
mov    0x2c0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xc9b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    0x2bce(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2ba0(%rip),%rax
mov    (%rax),%esi
mov    0x2c07(%rip),%rax
or     (%rax),%esi
mov    0x2bf6(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   10f0 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1451 <main+0x251>
mov    0x2b9d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xc2b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    0x2b56(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x2c(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    14a5 <main+0x2a5>
mov    0x2b49(%rip),%rax
mov    (%rax),%edi
lea    0xc16(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    0x2b02(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    17b6 <main+0x5b6>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2ac4(%rip),%rax
mov    (%rax),%esi
lea    -0x4c(%rbp),%rdx
call   1080 <ioctl@plt>
cmp    $0x0,%rax
je     1541 <main+0x341>
mov    0x2ab0(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    %rax,%rsi
mov    -0x30(%rbp),%edx
lea    0xb92(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    0x2a66(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
imul   $0x64,%eax,%eax
cltd
idivl  -0x28(%rbp)
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
cmp    %ecx,%eax
je     15a0 <main+0x3a0>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
imul   $0x64,%eax,%eax
cltd
idivl  -0x28(%rbp)
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%esi
add    $0x1,%esi
mov    -0x28(%rbp),%edx
mov    -0x40(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x38(%rbp),%r9d
mov    -0x3c(%rbp),%eax
lea    0xb45(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10d0 <fflush@plt>
cmpl   $0x0,-0x4c(%rbp)
jne    162e <main+0x42e>
mov    -0x30(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     162e <main+0x42e>
mov    -0x1c(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    0x2a10(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
cmp    $0x0,%rax
jge    1616 <main+0x416>
mov    0x29d8(%rip),%rax
mov    (%rax),%edi
lea    0xb17(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    0x2991(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%edi
xor    %esi,%esi
call   1050 <writemap@plt>
jmp    17a8 <main+0x5a8>
mov    -0x1c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   10a0 <read@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1697 <main+0x497>
mov    -0x30(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1692 <main+0x492>
mov    0x2954(%rip),%rax
mov    (%rax),%edi
lea    0xaa1(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    0x2915(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    1697 <main+0x497>
cmpl   $0xffffffff,-0x50(%rbp)
jne    16c8 <main+0x4c8>
mov    0x2910(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xa6a(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    179e <main+0x59e>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    1705 <main+0x505>
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     16f2 <main+0x4f2>
jmp    1705 <main+0x505>
jmp    16f7 <main+0x4f7>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    16cf <main+0x4cf>
mov    -0x54(%rbp),%eax
cmp    -0x50(%rbp),%eax
jne    173a <main+0x53a>
mov    -0x30(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     173a <main+0x53a>
mov    -0x20(%rbp),%edi
xor    %esi,%esi
call   1050 <writemap@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    17a8 <main+0x5a8>
mov    -0x24(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%edx
call   1040 <write@plt>
cmp    -0x50(%rbp),%eax
je     1779 <main+0x579>
mov    0x285f(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
lea    0x9d5(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    1794 <main+0x594>
mov    -0x20(%rbp),%edi
mov    $0x1,%esi
call   1050 <writemap@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    17a8 <main+0x5a8>
jmp    1799 <main+0x599>
jmp    179e <main+0x59e>
jmp    17a3 <main+0x5a3>
jmp    17a8 <main+0x5a8>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    14c1 <main+0x2c1>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%edi
call   10e0 <syncmap@plt>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
lea    0x9ec(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0x96b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0x963(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0x966(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x34(%rbp),%esi
lea    0x96a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%esi
lea    0x975(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x3c(%rbp),%esi
lea    0x98b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0x992(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x34(%rbp),%esi
add    -0x38(%rbp),%esi
add    -0x3c(%rbp),%esi
lea    0x9a3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x271c(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r12
cmp    $0x4,%edi
jne    1266 <main+0x46>
mov    0x8(%r12),%rdi
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1110 <open@plt>
test   %eax,%eax
jns    1297 <main+0x77>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r12),%rdx
lea    0xdf3(%rip),%rsi
jmp    128e <main+0x6e>
mov    0x2d4b(%rip),%rbx
mov    (%rbx),%edi
mov    (%r12),%rdx
lea    0xd86(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    (%rbx),%edi
mov    (%r12),%rdx
lea    0xdac(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    1300 <main+0xe0>
mov    %eax,%ebx
lea    0x38(%rsp),%rsi
mov    %eax,%edi
call   1140 <fstat@plt>
test   %rax,%rax
jns    12c8 <main+0xa8>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r12),%rdx
lea    0xda8(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    12f9 <main+0xd9>
mov    0x2d01(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rdx
mov    %ebx,%edi
call   10a0 <ioctl@plt>
test   %rax,%rax
jns    130e <main+0xee>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %ebx,%edi
call   10b0 <close@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    %ebx,0x18(%rsp)
mov    0x38(%rsp),%eax
mov    0x20(%rsp),%ecx
add    %ecx,%eax
add    $0xffffffff,%eax
cltd
idiv   %ecx
mov    %eax,%ebp
mov    0x2c5d(%rip),%r14
mov    0x2cc6(%rip),%rbx
mov    (%rbx),%esi
or     (%r14),%esi
mov    0x10(%r12),%rdi
mov    0x2cad(%rip),%r15
or     (%r15),%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1110 <open@plt>
mov    %eax,0x14(%rsp)
test   %eax,%eax
jns    137f <main+0x15f>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
mov    0x10(%r12),%rdx
lea    0xce8(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x18(%rsp),%edi
jmp    12fb <main+0xdb>
mov    0x18(%r12),%rdi
mov    (%rbx),%esi
or     (%r14),%esi
or     (%r15),%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1110 <open@plt>
mov    %eax,0x1c(%rsp)
test   %eax,%eax
jns    13ce <main+0x1ae>
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
mov    0x18(%r12),%rdx
lea    0xca2(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x18(%rsp),%edi
call   10b0 <close@plt>
mov    0x14(%rsp),%edi
jmp    12fb <main+0xdb>
mov    0x20(%rsp),%edi
call   10e0 <malloc@plt>
test   %rax,%rax
mov    0x18(%rsp),%ebx
jne    1410 <main+0x1f0>
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
lea    0xc9e(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %ebx,%edi
call   10b0 <close@plt>
mov    0x14(%rsp),%edi
call   10b0 <close@plt>
mov    0x1c(%rsp),%edi
jmp    12fb <main+0xdb>
mov    %rax,%r15
mov    %r12,0x40(%rsp)
movl   $0x0,0x2c(%rsp)
movl   $0x0,0x28(%rsp)
movl   $0x0,0x24(%rsp)
test   %ebp,%ebp
jle    160b <main+0x3eb>
lea    -0x1(%rbp),%eax
mov    %eax,0x30(%rsp)
mov    $0xffffffff,%r14d
xor    %r12d,%r12d
movl   $0x0,0x24(%rsp)
movl   $0x0,0x28(%rsp)
movl   $0x0,0x2c(%rsp)
jmp    148d <main+0x26d>
mov    0x14(%rsp),%edi
mov    $0x1,%esi
call   1070 <writemap@plt>
addl   $0x1,0x24(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x18(%rsp),%ebx
cmp    %ebp,%r12d
je     160b <main+0x3eb>
mov    %r12d,%r13d
mov    %r12d,0x34(%rsp)
mov    0x2b0c(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
lea    0x34(%rsp),%rdx
call   10a0 <ioctl@plt>
test   %rax,%rax
jne    16da <main+0x4ba>
lea    0x1(%r13),%r12d
imul   $0x64,%r12d,%eax
cltd
idiv   %ebp
cmp    %eax,%r14d
je     14f5 <main+0x2d5>
mov    %eax,%ebx
mov    0x24(%rsp),%eax
mov    %eax,(%rsp)
lea    0xc01(%rip),%rdi
mov    %r12d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    0x2c(%rsp),%r8d
mov    0x28(%rsp),%r9d
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   10f0 <fflush@plt>
mov    %ebx,%r14d
cmpl   $0x0,0x34(%rsp)
mov    0x20(%rsp),%edx
jne    1550 <main+0x330>
cmp    0x30(%rsp),%r13d
je     1550 <main+0x330>
mov    0x2aca(%rip),%rax
mov    (%rax),%eax
mov    0x18(%rsp),%ebx
mov    %ebx,%edi
mov    %edx,%esi
mov    %eax,%edx
call   1090 <lseek@plt>
test   %rax,%rax
js     171f <main+0x4ff>
addl   $0x1,0x2c(%rsp)
mov    0x14(%rsp),%edi
xor    %esi,%esi
call   1070 <writemap@plt>
cmp    %ebp,%r12d
jne    148d <main+0x26d>
jmp    160b <main+0x3eb>
cs nopw 0x0(%rax,%rax,1)
mov    0x18(%rsp),%ebx
mov    %ebx,%edi
mov    %r15,%rsi
call   10c0 <read@plt>
cmp    0x20(%rsp),%eax
jge    156f <main+0x34f>
cmp    0x30(%rsp),%r13d
jne    1701 <main+0x4e1>
mov    %eax,%ebx
cmp    $0xffffffff,%ebx
je     15b2 <main+0x392>
xor    %eax,%eax
test   %ebx,%ebx
jle    1592 <main+0x372>
nopl   0x0(%rax)
cmpb   $0x0,(%r15,%rax,1)
jne    1592 <main+0x372>
add    $0x1,%rax
cmp    %rax,%rbx
jne    1580 <main+0x360>
mov    %ebx,%eax
cmp    %ebx,%eax
jne    15cd <main+0x3ad>
cmp    0x30(%rsp),%r13d
je     15cd <main+0x3ad>
mov    0x14(%rsp),%edi
xor    %esi,%esi
call   1070 <writemap@plt>
addl   $0x1,0x28(%rsp)
jmp    1480 <main+0x260>
mov    0x29ff(%rip),%rax
mov    (%rax),%edi
mov    0x40(%rsp),%rax
mov    0x10(%rax),%rcx
lea    0xb5b(%rip),%rsi
jmp    15fc <main+0x3dc>
mov    0x1c(%rsp),%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <write@plt>
cmp    %ebx,%eax
je     1462 <main+0x242>
mov    0x29ce(%rip),%rax
mov    (%rax),%edi
mov    0x40(%rsp),%rax
mov    0x18(%rax),%rcx
lea    0xb46(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    1480 <main+0x260>
mov    %ebx,%edi
call   10b0 <close@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x14(%rsp),%ebx
mov    %ebx,%edi
call   1100 <syncmap@plt>
mov    %ebx,%edi
call   10b0 <close@plt>
mov    0x1c(%rsp),%edi
call   10b0 <close@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xbbe(%rip),%rdi
call   1050 <puts@plt>
mov    0x20(%rsp),%esi
lea    0xb09(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xb0f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xb14(%rip),%rdi
mov    0x2c(%rsp),%r14d
mov    %r14d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xb1a(%rip),%rdi
mov    0x28(%rsp),%ebx
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xb2d(%rip),%rdi
mov    0x24(%rsp),%ebp
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xb5a(%rip),%rdi
call   1050 <puts@plt>
add    %r14d,%ebx
add    %ebp,%ebx
lea    0xb1d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x28c5(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    0x28cf(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0x9b7(%rip),%rdi
mov    %rax,%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
jmp    13f7 <main+0x1d7>
mov    0x28b0(%rip),%rax
mov    (%rax),%edi
lea    0x9fd(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %ebx,%edi
jmp    13c0 <main+0x1a0>
mov    0x2892(%rip),%rax
mov    (%rax),%edi
lea    0x9d1(%rip),%rsi
jmp    13f0 <main+0x1d0>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [58 x i8] c"%s create a sparsemap and a data file from a sparsefile.\0A\00"
@.str.1 = [29 x i8] c"Usage: %s FILE MAPFILE DATA\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.2 = [16 x i8] c"Cannot open %s\0A\00"
@.str.3 = [16 x i8] c"Cannot stat %s\0A\00"
@FIGETBSZ = global i32 0
@.str.4 = [23 x i8] c"Cannot get block size\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"
@FIBMAP = global i32 0
@.str.6 = [46 x i8] c"ioctl failed: %s in block %d, are you root ?\0A\00"
@errno = global i32 0
@.str.7 = [44 x i8] c"%08d/%08d (%d%%), S:%08d, Z:%08d, C:%08d \0D\00"
@SEEK_CUR = global i32 0
@.str.8 = [14 x i8] c"Seek failed.\0A\00"
@.str.9 = [24 x i8] c"Unexpected short read.\0A\00"
@.str.10 = [28 x i8] c"Cannot read block %d on %s\0A\00"
@.str.11 = [29 x i8] c"Cannot write block %d on %s\0A\00"
@.str.12 = [2 x i8] c"\0A\00"
@.str.13 = [9 x i8] c"Report:\0A\00"
@.str.14 = [20 x i8] c"%d byte block size\0A\00"
@.str.15 = [21 x i8] c" total %08d blocks\0A\00"
@.str.16 = [28 x i8] c"Skipped %08d sparse blocks\0A\00"
@.str.17 = [39 x i8] c" found %08d zero blocks (now sparse)\0A\00"
@.str.18 = [21 x i8] c" copied %08d blocks\0A\00"
@.str.19 = [40 x i8] c" ------------------------------------\0A\00"
@.str.20 = [36 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 i32
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %16
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 4
br i1 %22, label %23, label %36
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %2
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_RDONLY
%41 = call i32 (i8*, i32, ...) @open(i8* %39, i32 %40)
store i32 %41, i32* %7
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %36
%44 = load i32, i32* @stderr
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %36
%52 = load i32, i32* %7
%53 = call i64 @fstat(i32 %52, %struct.stat* %6)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, 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 = %51
%66 = load i32, i32* %7
%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 %77
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.4, i64 0, i64 0))
%73 = load i32, i32* %7
%74 = call i32 @close(i32 %73)
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %65
%78 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%79 = load i32, i32* %78
%80 = load i32, i32* %11
%81 = add nsw i32 %79, %80
%82 = sub nsw i32 %81, 1
%83 = load i32, i32* %11
%84 = sdiv i32 %82, %83
store i32 %84, i32* %10
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 2
%87 = load i8*, i8** %86
%88 = load i32, i32* @O_WRONLY
%89 = load i32, i32* @O_CREAT
%90 = or i32 %88, %89
%91 = load i32, i32* @O_TRUNC
%92 = or i32 %90, %91
%93 = call i32 (i8*, i32, ...) @open(i8* %87, i32 %92, i32 511)
store i32 %93, i32* %8
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %105
95: ; preds = %77
%96 = load i32, i32* @stderr
%97 = load i8**, i8*** %5
%98 = getelementptr inbounds i8*, i8** %97, i64 2
%99 = load i8*, i8** %98
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %99)
%101 = load i32, i32* %7
%102 = call i32 @close(i32 %101)
%103 = load i32, i32* @EXIT_FAILURE
%104 = call i32 @exit(i32 %103)
unreachable
105: ; preds = %77
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 3
%108 = load i8*, i8** %107
%109 = load i32, i32* @O_WRONLY
%110 = load i32, i32* @O_CREAT
%111 = or i32 %109, %110
%112 = load i32, i32* @O_TRUNC
%113 = or i32 %111, %112
%114 = call i32 (i8*, i32, ...) @open(i8* %108, i32 %113, i32 511)
store i32 %114, i32* %9
%115 = icmp slt i32 %114, 0
br i1 %115, label %116, label %128
116: ; preds = %105
%117 = load i32, i32* @stderr
%118 = load i8**, i8*** %5
%119 = getelementptr inbounds i8*, i8** %118, i64 3
%120 = load i8*, i8** %119
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %120)
%122 = load i32, i32* %7
%123 = call i32 @close(i32 %122)
%124 = load i32, i32* %8
%125 = call i32 @close(i32 %124)
%126 = load i32, i32* @EXIT_FAILURE
%127 = call i32 @exit(i32 %126)
unreachable
128: ; preds = %105
%129 = load i32, i32* %11
%130 = call i8* @malloc(i32 %129)
store i8* %130, i8** %17
%131 = load i8*, i8** %17
%132 = icmp ne i8* %131, null
br i1 %132, label %144, label %133
133: ; preds = %128
%134 = load i32, i32* @stderr
%135 = call i32 (i32, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%136 = load i32, i32* %7
%137 = call i32 @close(i32 %136)
%138 = load i32, i32* %8
%139 = call i32 @close(i32 %138)
%140 = load i32, i32* %9
%141 = call i32 @close(i32 %140)
%142 = load i32, i32* @EXIT_FAILURE
%143 = call i32 @exit(i32 %142)
unreachable
144: ; preds = %128
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %12
br label %145
145: ; preds = %308, %144
%146 = load i32, i32* %12
%147 = load i32, i32* %10
%148 = icmp slt i32 %146, %147
br i1 %148, label %149, label %311
149: ; preds = %145
%150 = load i32, i32* %12
store i32 %150, i32* %18
store i32 0, i32* %19
%151 = load i32, i32* %7
%152 = load i32, i32* @FIBMAP
%153 = call i64 @ioctl(i32 %151, i32 %152, i32* %18)
%154 = icmp ne i64 %153, 0
br i1 %154, label %155, label %168
155: ; preds = %149
%156 = load i32, i32* @errno
%157 = call i8* @strerror(i32 %156)
%158 = load i32, i32* %12
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* %157, i32 %158)
%160 = load i32, i32* %7
%161 = call i32 @close(i32 %160)
%162 = load i32, i32* %8
%163 = call i32 @close(i32 %162)
%164 = load i32, i32* %9
%165 = call i32 @close(i32 %164)
%166 = load i32, i32* @EXIT_FAILURE
%167 = call i32 @exit(i32 %166)
unreachable
168: ; preds = %149
%169 = load i32, i32* %16
%170 = load i32, i32* %12
%171 = add nsw i32 %170, 1
%172 = mul nsw i32 %171, 100
%173 = load i32, i32* %10
%174 = sdiv i32 %172, %173
%175 = icmp ne i32 %169, %174
br i1 %175, label %176, label %191
176: ; preds = %168
%177 = load i32, i32* %12
%178 = add nsw i32 %177, 1
%179 = mul nsw i32 %178, 100
%180 = load i32, i32* %10
%181 = sdiv i32 %179, %180
store i32 %181, i32* %16
%182 = load i32, i32* %12
%183 = add nsw i32 %182, 1
%184 = load i32, i32* %10
%185 = load i32, i32* %16
%186 = load i32, i32* %13
%187 = load i32, i32* %14
%188 = load i32, i32* %15
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i32 %183, i32 %184, i32 %185, i32 %186, i32 %187, i32 %188)
%190 = call i32 @fflush(i32 0)
br label %191
191: ; preds = %176, %168
%192 = load i32, i32* %18
%193 = icmp ne i32 %192, 0
br i1 %193, label %221, label %194
194: ; preds = %191
%195 = load i32, i32* %12
%196 = load i32, i32* %10
%197 = sub nsw i32 %196, 1
%198 = icmp ne i32 %195, %197
br i1 %198, label %199, label %221
199: ; preds = %194
%200 = load i32, i32* %7
%201 = load i32, i32* %11
%202 = load i32, i32* @SEEK_CUR
%203 = call i64 @lseek(i32 %200, i32 %201, i32 %202)
%204 = icmp slt i64 %203, 0
br i1 %204, label %205, label %216
205: ; preds = %199
%206 = load i32, i32* @stderr
%207 = call i32 (i32, i8*, ...) @fprintf(i32 %206, i8* getelementptr inbounds ([14 x i8], [14 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 = %199
%217 = load i32, i32* %13
%218 = add nsw i32 %217, 1
store i32 %218, i32* %13
%219 = load i32, i32* %8
%220 = call i32 @writemap(i32 %219, i32 0)
br label %308
221: ; preds = %194, %191
%222 = load i32, i32* %7
%223 = load i8*, i8** %17
%224 = load i32, i32* %11
%225 = call i32 @read(i32 %222, i8* %223, i32 %224)
store i32 %225, i32* %19
%226 = load i32, i32* %19
%227 = load i32, i32* %11
%228 = icmp slt i32 %226, %227
br i1 %228, label %229, label %244
229: ; preds = %221
%230 = load i32, i32* %12
%231 = load i32, i32* %10
%232 = sub nsw i32 %231, 1
%233 = icmp ne i32 %230, %232
br i1 %233, label %234, label %243
234: ; preds = %229
%235 = load i32, i32* @stderr
%236 = call i32 (i32, i8*, ...) @fprintf(i32 %235, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%237 = load i32, i32* %7
%238 = call i32 @close(i32 %237)
%239 = load i32, i32* %8
%240 = call i32 @close(i32 %239)
%241 = load i32, i32* @EXIT_FAILURE
%242 = call i32 @exit(i32 %241)
unreachable
243: ; preds = %229
br label %244
244: ; preds = %243, %221
%245 = load i32, i32* %19
%246 = icmp eq i32 %245, -1
br i1 %246, label %247, label %254
247: ; preds = %244
%248 = load i32, i32* @stderr
%249 = load i32, i32* %12
%250 = load i8**, i8*** %5
%251 = getelementptr inbounds i8*, i8** %250, i64 2
%252 = load i8*, i8** %251
%253 = call i32 (i32, i8*, ...) @fprintf(i32 %248, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i32 %249, i8* %252)
br label %306
254: ; preds = %244
store i32 0, i32* %20
br label %255
255: ; preds = %268, %254
%256 = load i32, i32* %20
%257 = load i32, i32* %19
%258 = icmp slt i32 %256, %257
br i1 %258, label %259, label %271
259: ; preds = %255
%260 = load i8*, i8** %17
%261 = load i32, i32* %20
%262 = sext i32 %261 to i64
%263 = getelementptr inbounds i8, i8* %260, i64 %262
%264 = load i8, i8* %263
%265 = icmp ne i8 %264, 0
br i1 %265, label %266, label %267
266: ; preds = %259
br label %271
267: ; preds = %259
br label %268
268: ; preds = %267
%269 = load i32, i32* %20
%270 = add nsw i32 %269, 1
store i32 %270, i32* %20
br label %255
271: ; preds = %266, %255
%272 = load i32, i32* %20
%273 = load i32, i32* %19
%274 = icmp eq i32 %272, %273
br i1 %274, label %275, label %285
275: ; preds = %271
%276 = load i32, i32* %12
%277 = load i32, i32* %10
%278 = sub nsw i32 %277, 1
%279 = icmp ne i32 %276, %278
br i1 %279, label %280, label %285
280: ; preds = %275
%281 = load i32, i32* %8
%282 = call i32 @writemap(i32 %281, i32 0)
%283 = load i32, i32* %14
%284 = add nsw i32 %283, 1
store i32 %284, i32* %14
br label %308
285: ; preds = %275, %271
%286 = load i32, i32* %9
%287 = load i8*, i8** %17
%288 = load i32, i32* %19
%289 = call i32 @write(i32 %286, i8* %287, i32 %288)
%290 = load i32, i32* %19
%291 = icmp ne i32 %289, %290
br i1 %291, label %292, label %299
292: ; preds = %285
%293 = load i32, i32* @stderr
%294 = load i32, i32* %12
%295 = load i8**, i8*** %5
%296 = getelementptr inbounds i8*, i8** %295, i64 3
%297 = load i8*, i8** %296
%298 = call i32 (i32, i8*, ...) @fprintf(i32 %293, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i32 %294, i8* %297)
br label %304
299: ; preds = %285
%300 = load i32, i32* %8
%301 = call i32 @writemap(i32 %300, i32 1)
%302 = load i32, i32* %15
%303 = add nsw i32 %302, 1
store i32 %303, i32* %15
br label %308
304: ; preds = %292
br label %305
305: ; preds = %304
br label %306
306: ; preds = %305, %247
br label %307
307: ; preds = %306
br label %308
308: ; preds = %307, %299, %280, %216
%309 = load i32, i32* %12
%310 = add nsw i32 %309, 1
store i32 %310, i32* %12
br label %145
311: ; preds = %145
%312 = load i32, i32* %7
%313 = call i32 @close(i32 %312)
%314 = load i8*, i8** %17
%315 = call i32 @free(i8* %314)
%316 = load i32, i32* %8
%317 = call i32 @syncmap(i32 %316)
%318 = load i32, i32* %8
%319 = call i32 @close(i32 %318)
%320 = load i32, i32* %9
%321 = call i32 @close(i32 %320)
%322 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%323 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0))
%324 = load i32, i32* %11
%325 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i32 %324)
%326 = load i32, i32* %10
%327 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.15, i64 0, i64 0), i32 %326)
%328 = load i32, i32* %13
%329 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.16, i64 0, i64 0), i32 %328)
%330 = load i32, i32* %14
%331 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.17, i64 0, i64 0), i32 %330)
%332 = load i32, i32* %15
%333 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.18, i64 0, i64 0), i32 %332)
%334 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.19, i64 0, i64 0))
%335 = load i32, i32* %13
%336 = load i32, i32* %14
%337 = add nsw i32 %335, %336
%338 = load i32, i32* %15
%339 = add nsw i32 %337, %338
%340 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.20, i64 0, i64 0), i32 %339)
%341 = load i32, i32* @EXIT_SUCCESS
%342 = call i32 @exit(i32 %341)
unreachable
}

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