#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;
  int /*<<< orphan*/ st_mode;
  int /*<<< orphan*/ st_gid;
  int /*<<< orphan*/ st_uid;
};

/* 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*/ fchmod(int, int /*<<< orphan*/);
int /*<<< orphan*/ fchown(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ ftruncate(int, int);
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 write(int, unsigned char *, int);
int main(int argc, char **argv) {
  struct stat statinfo1;
  int fd1, fd2;
  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 != 3) {
    fprintf(stderr, "%s a fast sparse-aware binary file copy.\n", argv[0]);
    fprintf(stderr, "Usage: %s FILE1 FILE2\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 (ioctl(fd1, FIGETBSZ, &block_size) < 0) {
    fprintf(stderr, "Cannot get block size\n");
    close(fd1);
    exit(EXIT_FAILURE);
  }
  if (fstat(fd1, &statinfo1) < 0) {
    fprintf(stderr, "Cannot stat %s\n", argv[1]);
    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[3]);
    close(fd1);
    exit(EXIT_FAILURE);
  }
  buffer1 = malloc(block_size);
  if (!buffer1) {
    fprintf(stderr, "Cannot allocate buffer\n");
    close(fd1);
    close(fd2);
    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);
      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) {
      if (lseek(fd1, block_size, SEEK_CUR) < 0 ||
          lseek(fd2, block_size, SEEK_CUR) < 0) {
        fprintf(stderr, "Seek failed.\n");
        close(fd1);
        close(fd2);
        exit(EXIT_FAILURE);
      }
      sparse_blocks++;
      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) {
          if (lseek(fd2, nread, SEEK_CUR) < 0) {
            fprintf(stderr, "Seek failed.\n");
            close(fd1);
            close(fd2);
            exit(EXIT_FAILURE);
          }
          zero_blocks++;
          continue;
        } else {
          if (write(fd2, buffer1, nread) != nread) {
            fprintf(stderr, "Cannot write block %d on %s\n", i, argv[3]);
          } else {
            copied_blocks++;
            continue;
          }
        }
      }
    }
  }
  close(fd1);
  free(buffer1);
  ftruncate(fd2, statinfo1.st_size);
  fchown(fd2, statinfo1.st_uid, statinfo1.st_gid);
  fchmod(fd2, statinfo1.st_mode);
  close(fd2);
  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    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x44(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1281 <main+0x71>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10f0 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    12d2 <main+0xc2>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x24(%rbp),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1080 <ioctl@plt>
cmp    $0x0,%rax
jge    131e <main+0x10e>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1130 <fstat@plt>
cmp    $0x0,%rax
jge    1369 <main+0x159>
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    0x2c3e(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x20(%rbp),%eax
add    -0x30(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0x30(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2c00(%rip),%rax
mov    (%rax),%esi
mov    0x2c67(%rip),%rax
or     (%rax),%esi
mov    0x2c56(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   10f0 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    13e9 <main+0x1d9>
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xc75(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x30(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1435 <main+0x225>
mov    0x2bb1(%rip),%rax
mov    (%rax),%edi
lea    0xc68(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
mov    0x2b72(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1764 <main+0x554>
mov    -0x34(%rbp),%eax
mov    %eax,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2b34(%rip),%rax
mov    (%rax),%esi
lea    -0x54(%rbp),%rdx
call   1080 <ioctl@plt>
cmp    $0x0,%rax
je     14c9 <main+0x2b9>
mov    0x2b20(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
mov    %rax,%rsi
mov    -0x34(%rbp),%edx
lea    0xbec(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
mov    0x2ade(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
imul   $0x64,%eax,%eax
cltd
idivl  -0x2c(%rbp)
mov    %eax,%ecx
mov    -0x60(%rbp),%eax
cmp    %ecx,%eax
je     1528 <main+0x318>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
imul   $0x64,%eax,%eax
cltd
idivl  -0x2c(%rbp)
mov    %eax,-0x44(%rbp)
mov    -0x34(%rbp),%esi
add    $0x1,%esi
mov    -0x2c(%rbp),%edx
mov    -0x44(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
mov    -0x40(%rbp),%eax
lea    0xba7(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10d0 <fflush@plt>
cmpl   $0x0,-0x54(%rbp)
jne    15b1 <main+0x3a1>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    0x2a99(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
cmp    $0x0,%rax
jl     156e <main+0x35e>
mov    -0x28(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    0x2a7b(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
cmp    $0x0,%rax
jge    15a3 <main+0x393>
mov    0x2a43(%rip),%rax
mov    (%rax),%edi
lea    0xb6c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
mov    0x2a04(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1756 <main+0x546>
mov    -0x24(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   10a0 <read@plt>
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    161a <main+0x40a>
mov    -0x34(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1615 <main+0x405>
mov    0x29d1(%rip),%rax
mov    (%rax),%edi
lea    0xb08(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
mov    0x2992(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
jmp    161a <main+0x40a>
cmpl   $0xffffffff,-0x58(%rbp)
jne    164b <main+0x43b>
mov    0x298d(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xad1(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    174c <main+0x53c>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x58(%rbp),%eax
jge    1688 <main+0x478>
mov    -0x50(%rbp),%rax
movslq -0x5c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1675 <main+0x465>
jmp    1688 <main+0x478>
jmp    167a <main+0x46a>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1652 <main+0x442>
mov    -0x5c(%rbp),%eax
cmp    -0x58(%rbp),%eax
jne    16f5 <main+0x4e5>
mov    -0x28(%rbp),%edi
mov    -0x58(%rbp),%esi
mov    0x2937(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
cmp    $0x0,%rax
jge    16e7 <main+0x4d7>
mov    0x28ff(%rip),%rax
mov    (%rax),%edi
lea    0xa28(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
mov    0x28c0(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1756 <main+0x546>
mov    -0x28(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x58(%rbp),%edx
call   1040 <write@plt>
cmp    -0x58(%rbp),%eax
je     1734 <main+0x524>
mov    0x28a4(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
lea    0xa04(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    1742 <main+0x532>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1756 <main+0x546>
jmp    1747 <main+0x537>
jmp    174c <main+0x53c>
jmp    1751 <main+0x541>
jmp    1756 <main+0x546>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1451 <main+0x241>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1060 <ftruncate@plt>
mov    -0x28(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1100 <fchown@plt>
mov    -0x28(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10e0 <fchmod@plt>
mov    -0x28(%rbp),%edi
call   1090 <close@plt>
lea    0xa14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0x993(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%esi
lea    0x98b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0x98e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%esi
lea    0x992(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3c(%rbp),%esi
lea    0x99d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%esi
lea    0x9b3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0x9ba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%esi
add    -0x3c(%rbp),%esi
add    -0x40(%rbp),%esi
lea    0x9cb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x275a(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1274 <main+0x44>
mov    0x8(%rbx),%rdi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1110 <open@plt>
test   %eax,%eax
jns    12a8 <main+0x78>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdcf(%rip),%rsi
jmp    129c <main+0x6c>
mov    0x2d3d(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xd78(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xd8e(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    1376 <main+0x146>
mov    %eax,%r14d
mov    0x2d1e(%rip),%rax
mov    (%rax),%esi
lea    0x1c(%rsp),%rdx
mov    %r14d,%edi
call   10a0 <ioctl@plt>
test   %rax,%rax
jns    12e2 <main+0xb2>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
jmp    136e <main+0x13e>
lea    0x40(%rsp),%rsi
mov    %r14d,%edi
call   1150 <fstat@plt>
test   %rax,%rax
jns    130a <main+0xda>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xd60(%rip),%rsi
jmp    1367 <main+0x137>
mov    0x40(%rsp),%r15d
mov    0x1c(%rsp),%ecx
lea    (%r15,%rcx,1),%eax
add    $0xffffffff,%eax
cltd
idiv   %ecx
mov    %eax,%r12d
mov    0x2c61(%rip),%rax
mov    0x2cca(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbx),%rdi
mov    0x2cb3(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1110 <open@plt>
mov    %eax,0x10(%rsp)
test   %eax,%eax
jns    1384 <main+0x154>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rbx),%rdx
lea    0xcda(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
mov    0x1c(%rsp),%edi
call   10e0 <malloc@plt>
test   %rax,%rax
jne    13b7 <main+0x187>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
lea    0xcd6(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    0x10(%rsp),%edi
jmp    1371 <main+0x141>
mov    %rax,%rbp
mov    %r15,0x50(%rsp)
mov    %rbx,0x38(%rsp)
movl   $0x0,0x28(%rsp)
movl   $0x0,0x24(%rsp)
movl   $0x0,0x20(%rsp)
mov    %r12,%rbx
test   %ebx,%ebx
mov    %r14d,%edi
jle    15dc <main+0x3ac>
lea    -0x1(%rbx),%eax
mov    %eax,0x34(%rsp)
movl   $0xffffffff,0x2c(%rsp)
ff
mov    0x2bd8(%rip),%r13
xor    %eax,%eax
movl   $0x0,0x20(%rsp)
movl   $0x0,0x24(%rsp)
movl   $0x0,0x28(%rsp)
mov    %edi,0x14(%rsp)
jmp    1453 <main+0x223>
mov    0x2b91(%rip),%rax
mov    (%rax),%edi
mov    0x38(%rsp),%rax
mov    0x10(%rax),%rcx
lea    0xcd7(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x14(%rsp),%edi
mov    0x18(%rsp),%eax
cmp    %ebx,%eax
je     15dc <main+0x3ac>
mov    %eax,%r12d
mov    %eax,0x30(%rsp)
mov    0x2b47(%rip),%rax
mov    (%rax),%esi
mov    %edi,%r14d
lea    0x30(%rsp),%rdx
call   10a0 <ioctl@plt>
test   %rax,%rax
jne    16c2 <main+0x492>
mov    %rbp,%r15
lea    0x1(%r12),%eax
mov    %eax,0x18(%rsp)
imul   $0x64,%eax,%eax
cltd
mov    %rbx,%rbp
idiv   %ebx
cmp    %eax,0x2c(%rsp)
je     14c8 <main+0x298>
mov    %eax,%ebx
mov    0x20(%rsp),%eax
mov    %eax,(%rsp)
lea    0xc1a(%rip),%rdi
mov    0x18(%rsp),%esi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    0x28(%rsp),%r8d
mov    0x24(%rsp),%r9d
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10f0 <fflush@plt>
mov    %ebx,0x2c(%rsp)
cmpl   $0x0,0x30(%rsp)
mov    0x1c(%rsp),%edx
je     1530 <main+0x300>
mov    %rbp,%rbx
mov    %r14d,%edi
mov    %r15,%rbp
mov    %r15,%rsi
call   10c0 <read@plt>
mov    %eax,%r14d
cmp    0x1c(%rsp),%eax
jge    14f8 <main+0x2c8>
cmp    0x34(%rsp),%r12d
jne    16fe <main+0x4ce>
cmp    $0xffffffff,%r14d
je     1420 <main+0x1f0>
test   %r14d,%r14d
jle    1576 <main+0x346>
mov    %r14d,%ecx
xor    %eax,%eax
nopl   0x0(%rax)
cmpb   $0x0,0x0(%rbp,%rax,1)
jne    1578 <main+0x348>
add    $0x1,%rax
cmp    %rax,%rcx
jne    1510 <main+0x2e0>
jmp    157d <main+0x34d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%eax
mov    %r14d,%edi
mov    %edx,%esi
mov    %eax,%edx
call   1090 <lseek@plt>
test   %rax,%rax
js     16e9 <main+0x4b9>
mov    %rbp,%rbx
mov    0x1c(%rsp),%esi
mov    0x0(%r13),%edx
mov    0x10(%rsp),%edi
call   1090 <lseek@plt>
test   %rax,%rax
js     16e9 <main+0x4b9>
addl   $0x1,0x28(%rsp)
mov    %r14d,%edi
mov    %r15,%rbp
jmp    1447 <main+0x217>
xor    %eax,%eax
cmp    %r14d,%eax
jne    15a0 <main+0x370>
mov    0x0(%r13),%edx
mov    0x10(%rsp),%edi
mov    %r14d,%esi
call   1090 <lseek@plt>
test   %rax,%rax
js     1710 <main+0x4e0>
addl   $0x1,0x24(%rsp)
jmp    1443 <main+0x213>
mov    0x10(%rsp),%edi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1060 <write@plt>
cmp    %r14d,%eax
jne    15be <main+0x38e>
addl   $0x1,0x20(%rsp)
jmp    1443 <main+0x213>
mov    0x29f3(%rip),%rax
mov    (%rax),%edi
mov    0x38(%rsp),%rax
mov    0x18(%rax),%rcx
lea    0xb55(%rip),%rsi
jmp    1439 <main+0x209>
call   10b0 <close@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rbp
mov    0x10(%rsp),%ebx
mov    %ebx,%edi
mov    0x50(%rsp),%rsi
call   1080 <ftruncate@plt>
mov    0x48(%rsp),%edx
mov    0x4c(%rsp),%esi
mov    %ebx,%edi
call   1120 <fchown@plt>
mov    0x44(%rsp),%esi
mov    %ebx,%edi
call   1100 <fchmod@plt>
mov    %ebx,%edi
call   10b0 <close@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xbc0(%rip),%rdi
call   1050 <puts@plt>
mov    0x1c(%rsp),%esi
lea    0xb0b(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xb11(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xb16(%rip),%rdi
mov    0x28(%rsp),%r14d
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xb1c(%rip),%rdi
mov    0x24(%rsp),%ebx
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xb2f(%rip),%rdi
mov    0x20(%rsp),%ebp
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xb5c(%rip),%rdi
call   1050 <puts@plt>
add    %r14d,%ebx
add    %ebp,%ebx
lea    0xb1f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x28dd(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
mov    0x28e7(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0x9b9(%rip),%rdi
mov    %rax,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    13a9 <main+0x179>
mov    0x28c8(%rip),%rax
mov    (%rax),%edi
lea    0x9f1(%rip),%rsi
jmp    13a2 <main+0x172>
mov    0x28b3(%rip),%rax
mov    (%rax),%edi
lea    0x9ea(%rip),%rsi
jmp    1720 <main+0x4f0>
mov    0x28a1(%rip),%rax
mov    (%rax),%edi
lea    0x9ca(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x14(%rsp),%edi
jmp    13ac <main+0x17c>

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

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32, i32 }
@stderr = global i32 0
@.str = [42 x i8] c"%s a fast sparse-aware binary file copy.\0A\00"
@.str.1 = [23 x i8] c"Usage: %s FILE1 FILE2\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"
@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, 3
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 ([42 x i8], [42 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 ([23 x i8], [23 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 = load i32, i32* @FIGETBSZ
%32 = call i64 @ioctl(i32 %22, i32 %31, i32* %4)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @close(i32 %22)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %30
%41 = call i64 @fstat(i32 %22, %struct.stat* %3)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %19
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %45)
%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 %74
66: ; preds = %50
%67 = load i32, i32* @stderr
%68 = getelementptr inbounds i8*, i8** %1, i64 3
%69 = load i8*, i8** %68
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %69)
%71 = call i32 @close(i32 %22)
%72 = load i32, i32* @EXIT_FAILURE
%73 = call i32 @exit(i32 %72)
unreachable
74: ; preds = %50
%75 = load i32, i32* %4
%76 = call i8* @malloc(i32 %75)
%77 = icmp eq i8* %76, null
br i1 %77, label %84, label %78
78: ; preds = %74
%79 = icmp sgt i32 %56, 0
br i1 %79, label %80, label %202
80: ; preds = %78
%81 = bitcast i32* %5 to i8*
%82 = add nsw i32 %56, -1
%83 = getelementptr inbounds i8*, i8** %1, i64 3
br label %91
84: ; preds = %74
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%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 = %80, %197
%92 = phi i32 [ 0, %80 ], [ %109, %197 ]
%93 = phi i32 [ -1, %80 ], [ %117, %197 ]
%94 = phi i32 [ 0, %80 ], [ %200, %197 ]
%95 = phi i32 [ 0, %80 ], [ %199, %197 ]
%96 = phi i32 [ 0, %80 ], [ %198, %197 ]
store i32 %92, i32* %5
%97 = load i32, i32* @FIBMAP
%98 = call i64 @ioctl(i32 %22, i32 %97, i32* %5)
%99 = icmp eq i64 %98, 0
br i1 %99, label %108, label %100
100: ; preds = %91
%101 = load i32, i32* @errno
%102 = call i8* @strerror(i32 %101)
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* %102, i32 %92)
%104 = call i32 @close(i32 %22)
%105 = call i32 @close(i32 %64)
%106 = load i32, i32* @EXIT_FAILURE
%107 = call i32 @exit(i32 %106)
unreachable
108: ; preds = %91
%109 = add nuw nsw i32 %92, 1
%110 = mul nsw i32 %109, 100
%111 = sdiv i32 %110, %56
%112 = icmp eq i32 %93, %111
br i1 %112, label %116, label %113
113: ; preds = %108
%114 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i32 %109, i32 %56, i32 %111, i32 %96, i32 %95, i32 %94)
%115 = call i32 @fflush(i32 0)
br label %116
116: ; preds = %113, %108
%117 = phi i32 [ %111, %113 ], [ %93, %108 ]
%118 = load i32, i32* %5
%119 = icmp eq i32 %118, 0
%120 = load i32, i32* %4
br i1 %119, label %121, label %139
121: ; preds = %116
%122 = load i32, i32* @SEEK_CUR
%123 = call i64 @lseek(i32 %22, i32 %120, i32 %122)
%124 = icmp slt i64 %123, 0
br i1 %124, label %130, label %125
125: ; preds = %121
%126 = load i32, i32* %4
%127 = load i32, i32* @SEEK_CUR
%128 = call i64 @lseek(i32 %64, i32 %126, i32 %127)
%129 = icmp slt i64 %128, 0
br i1 %129, label %130, label %137
130: ; preds = %125, %121
%131 = load i32, i32* @stderr
%132 = call i32 (i32, i8*, ...) @fprintf(i32 %131, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%133 = call i32 @close(i32 %22)
%134 = call i32 @close(i32 %64)
%135 = load i32, i32* @EXIT_FAILURE
%136 = call i32 @exit(i32 %135)
unreachable
137: ; preds = %125
%138 = add nsw i32 %96, 1
br label %197
139: ; preds = %116
%140 = call i32 @read(i32 %22, i8* %76, i32 %120)
%141 = load i32, i32* %4
%142 = icmp sge i32 %140, %141
%143 = icmp eq i32 %92, %82
%144 = select i1 %142, i1 true, i1 %143
br i1 %144, label %152, label %145
145: ; preds = %139
%146 = load i32, i32* @stderr
%147 = call i32 (i32, i8*, ...) @fprintf(i32 %146, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%148 = call i32 @close(i32 %22)
%149 = call i32 @close(i32 %64)
%150 = load i32, i32* @EXIT_FAILURE
%151 = call i32 @exit(i32 %150)
unreachable
152: ; preds = %139
%153 = icmp eq i32 %140, -1
br i1 %153, label %158, label %154
154: ; preds = %152
%155 = icmp sgt i32 %140, 0
br i1 %155, label %156, label %172
156: ; preds = %154
%157 = zext i32 %140 to i64
br label %162
158: ; preds = %152
%159 = load i32, i32* @stderr
%160 = load i8*, i8** %57
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %159, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i32 %92, i8* %160)
br label %197
162: ; preds = %156, %167
%163 = phi i64 [ 0, %156 ], [ %168, %167 ]
%164 = getelementptr inbounds i8, i8* %76, i64 %163
%165 = load i8, i8* %164
%166 = icmp eq i8 %165, 0
br i1 %166, label %167, label %170
167: ; preds = %162
%168 = add nuw nsw i64 %163, 1
%169 = icmp eq i64 %168, %157
br i1 %169, label %175, label %162
170: ; preds = %162
%171 = trunc i64 %163 to i32
br label %172
172: ; preds = %170, %154
%173 = phi i32 [ 0, %154 ], [ %171, %170 ]
%174 = icmp eq i32 %173, %140
br i1 %174, label %175, label %188
175: ; preds = %167, %172
%176 = load i32, i32* @SEEK_CUR
%177 = call i64 @lseek(i32 %64, i32 %140, i32 %176)
%178 = icmp slt i64 %177, 0
br i1 %178, label %179, label %186
179: ; preds = %175
%180 = load i32, i32* @stderr
%181 = call i32 (i32, i8*, ...) @fprintf(i32 %180, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%182 = call i32 @close(i32 %22)
%183 = call i32 @close(i32 %64)
%184 = load i32, i32* @EXIT_FAILURE
%185 = call i32 @exit(i32 %184)
unreachable
186: ; preds = %175
%187 = add nsw i32 %95, 1
br label %197
188: ; preds = %172
%189 = call i32 @write(i32 %64, i8* %76, i32 %140)
%190 = icmp eq i32 %189, %140
br i1 %190, label %195, label %191
191: ; preds = %188
%192 = load i32, i32* @stderr
%193 = load i8*, i8** %83
%194 = call i32 (i32, i8*, ...) @fprintf(i32 %192, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i32 %92, i8* %193)
br label %197
195: ; preds = %188
%196 = add nsw i32 %94, 1
br label %197
197: ; preds = %186, %195, %191, %158, %137
%198 = phi i32 [ %138, %137 ], [ %96, %158 ], [ %96, %191 ], [ %96, %195 ], [ %96, %186 ]
%199 = phi i32 [ %95, %137 ], [ %95, %158 ], [ %95, %191 ], [ %95, %195 ], [ %187, %186 ]
%200 = phi i32 [ %94, %137 ], [ %94, %158 ], [ %94, %191 ], [ %196, %195 ], [ %94, %186 ]
%201 = icmp eq i32 %109, %56
br i1 %201, label %202, label %91
202: ; preds = %197, %78
%203 = phi i32 [ 0, %78 ], [ %198, %197 ]
%204 = phi i32 [ 0, %78 ], [ %199, %197 ]
%205 = phi i32 [ 0, %78 ], [ %200, %197 ]
%206 = call i32 @close(i32 %22)
%207 = call i32 @free(i8* %76)
%208 = call i32 @ftruncate(i32 %64, i32 %52)
%209 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 3
%210 = load i32, i32* %209
%211 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%212 = load i32, i32* %211
%213 = call i32 @fchown(i32 %64, i32 %210, i32 %212)
%214 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%215 = load i32, i32* %214
%216 = call i32 @fchmod(i32 %64, i32 %215)
%217 = call i32 @close(i32 %64)
%218 = call i32 @putchar(i32 10)
%219 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%220 = load i32, i32* %4
%221 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i32 %220)
%222 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.15, i64 0, i64 0), i32 %56)
%223 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.16, i64 0, i64 0), i32 %203)
%224 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.17, i64 0, i64 0), i32 %204)
%225 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.18, i64 0, i64 0), i32 %205)
%226 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.21, i64 0, i64 0))
%227 = add nsw i32 %204, %203
%228 = add nsw i32 %227, %205
%229 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.20, i64 0, i64 0), i32 %228)
%230 = load i32, i32* @EXIT_SUCCESS
%231 = call i32 @exit(i32 %230)
unreachable
}