#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*/ FIBMAP;
int /*<<< orphan*/ FIGETBSZ;
int /*<<< orphan*/ O_RDONLY;
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 *, ...);
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 /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int write(int, unsigned char *, int);
int main(int argc, char **argv) {
  struct stat statinfo1;
  int fd1;
  int num_blocks;
  int block_size;
  int i;
  unsigned char *buffer1, *buffer2;
  if (argc != 2) {
    fprintf(stderr, "%s a fast sparse-aware cat.\n", argv[0]);
    fprintf(stderr, "Usage: %s FILE1\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;
  buffer1 = malloc(block_size);
  if (!buffer1) {
    fprintf(stderr, "Cannot allocate buffer\n");
    close(fd1);
    exit(EXIT_FAILURE);
  }
  buffer2 = malloc(block_size);
  if (!buffer1) {
    fprintf(stderr, "Cannot allocate buffer\n");
    close(fd1);
    exit(EXIT_FAILURE);
  }
  memset(buffer2, 0, 4096);
  for (i = 0; i < num_blocks; i++) {
    int block = i;
    int nread = 0;
    if (ioctl(fd1, FIBMAP, &block)) {
      fprintf(stderr, "ioctl failed: %s in block %d, are you root ?\n",
              strerror(errno), i);
      close(fd1);
      exit(EXIT_FAILURE);
    }
    if (!block) {
      if (lseek(fd1, block_size, SEEK_CUR) < 0) {
        fprintf(stderr, "Seek failed.\n");
        close(fd1);
        exit(EXIT_FAILURE);
      }
      if (write(1, buffer2, block_size) != block_size) {
        fprintf(stderr, "Cannot write block %d on STDOUT\n", i);
        close(fd1);
        exit(EXIT_FAILURE);
      }
      fflush(stdout);
      continue;
    }
    nread = read(fd1, buffer1, block_size);
    if (nread < block_size) {
      if (i != (num_blocks - 1)) {
        fprintf(stderr, "Unexpected short read.\n");
        close(fd1);
        exit(EXIT_FAILURE);
      }
    }
    if (write(1, buffer1, nread) != nread) {
      fprintf(stderr, "Cannot write block %d on STDOUT\n", i);
      close(fd1);
      exit(EXIT_FAILURE);
    }
  }
  close(fd1);
  fflush(stdout);
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     123a <main+0x6a>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1289 <main+0xb9>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    12d5 <main+0x105>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
lea    0xd86(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10f0 <fstat@plt>
cmp    $0x0,%rax
jge    1320 <main+0x150>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0x24(%rbp)
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1374 <main+0x1a4>
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
lea    0xd0e(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x24(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    13b8 <main+0x1e8>
mov    0x2c36(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    15be <main+0x3ee>
mov    -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2bc6(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
je     144e <main+0x27e>
mov    0x2bba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2ba6(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
mov    -0x28(%rbp),%ecx
lea    0xc4c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2b69(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x3c(%rbp)
jne    1500 <main+0x330>
mov    -0x1c(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    0x2b83(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0x0,%rax
jge    14a3 <main+0x2d3>
mov    0x2b4b(%rip),%rax
mov    (%rax),%edi
lea    0xc25(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2b14(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x38(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmp    -0x24(%rbp),%eax
je     14ed <main+0x31d>
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xbe9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2aca(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x2ab4(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
jmp    15b0 <main+0x3e0>
mov    -0x1c(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1080 <read@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1561 <main+0x391>
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     155c <main+0x38c>
mov    0x2a92(%rip),%rax
mov    (%rax),%edi
lea    0xb9b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2a5b(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    1561 <main+0x391>
mov    -0x30(%rbp),%rsi
mov    -0x40(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmp    -0x40(%rbp),%eax
je     15ab <main+0x3db>
mov    0x2a46(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xb2b(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2a0c(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    15b0 <main+0x3e0>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    13cf <main+0x1ff>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x29db(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    0x29d5(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1212 <main+0x42>
mov    0x8(%rbx),%rdi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
test   %eax,%eax
jns    1243 <main+0x73>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe1e(%rip),%rsi
jmp    123a <main+0x6a>
mov    0x2daf(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xdda(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xde3(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12ad <main+0xdd>
mov    %eax,%r14d
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %r14d,%edi
call   1060 <ioctl@plt>
test   %rax,%rax
jns    1278 <main+0xa8>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12a5 <main+0xd5>
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
call   10f0 <fstat@plt>
test   %rax,%rax
jns    12bb <main+0xeb>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdb7(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x8(%rsp),%eax
mov    (%rsp),%ebx
add    %ebx,%eax
add    $0xffffffff,%eax
cltd
idiv   %ebx
mov    %eax,%ebp
mov    %ebx,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
jne    12ea <main+0x11a>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
lea    0xd7d(%rip),%rsi
jmp    126f <main+0x9f>
mov    %rax,%r15
mov    %ebx,%edi
call   10a0 <malloc@plt>
xor    %ebx,%ebx
mov    %rax,0x10(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
test   %ebp,%ebp
jle    13e8 <main+0x218>
neg    %ebp
lea    0x4(%rsp),%r13
jmp    1346 <main+0x176>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <write@plt>
cmp    %r12d,%eax
jne    1434 <main+0x264>
add    $0x1,%ebx
mov    %ebp,%eax
add    %ebx,%eax
je     13e8 <main+0x218>
mov    %ebx,0x4(%rsp)
mov    0x2c67(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %r13,%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
jne    1403 <main+0x233>
cmpl   $0x0,0x4(%rsp)
mov    (%rsp),%edx
je     13a0 <main+0x1d0>
mov    %r14d,%edi
mov    %r15,%rsi
call   1080 <read@plt>
mov    %eax,%r12d
cmp    (%rsp),%eax
jge    1320 <main+0x150>
lea    (%rbx,%rbp,1),%eax
cmp    $0xffffffff,%eax
je     1320 <main+0x150>
jmp    1452 <main+0x282>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2c41(%rip),%rax
mov    (%rax),%eax
mov    %r14d,%edi
mov    %edx,%esi
mov    %eax,%edx
call   1040 <lseek@plt>
test   %rax,%rax
js     1467 <main+0x297>
mov    (%rsp),%edx
mov    $0x1,%edi
mov    0x10(%rsp),%rsi
call   1030 <write@plt>
cmp    (%rsp),%eax
jne    1434 <main+0x264>
mov    0x2bcc(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
jmp    1339 <main+0x169>
mov    %r14d,%edi
call   1070 <close@plt>
mov    0x2bb1(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
jmp    12ad <main+0xdd>
mov    0x2bbe(%rip),%rax
mov    (%rax),%ebp
mov    0x2bad(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc5c(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12a5 <main+0xd5>
mov    0x2b8d(%rip),%rax
mov    (%rax),%edi
lea    0xc75(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    12a5 <main+0xd5>
mov    0x2b6f(%rip),%rax
mov    (%rax),%edi
lea    0xc78(%rip),%rsi
jmp    126f <main+0x9f>
mov    0x2b5a(%rip),%rax
mov    (%rax),%edi
lea    0xc34(%rip),%rsi
jmp    126f <main+0x9f>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"%s a fast sparse-aware cat.\0A\00"
@.str.1 = [17 x i8] c"Usage: %s FILE1\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"
@.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
@SEEK_CUR = global i32 0
@.str.7 = [14 x i8] c"Seek failed.\0A\00"
@.str.8 = [33 x i8] c"Cannot write block %d on STDOUT\0A\00"
@stdout = global i32 0
@.str.9 = [24 x i8] c"Unexpected short read.\0A\00"
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 i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %30
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %21)
%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 ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %2
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i32, i32* @O_RDONLY
%35 = call i32 @open(i8* %33, i32 %34)
store i32 %35, i32* %7
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %30
%38 = load i32, i32* @stderr
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %30
%46 = load i32, i32* %7
%47 = load i32, i32* @FIGETBSZ
%48 = call i64 @ioctl(i32 %46, i32 %47, i32* %9)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%53 = load i32, i32* %7
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %45
%58 = load i32, i32* %7
%59 = call i64 @fstat(i32 %58, %struct.stat* %6)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %71
61: ; preds = %57
%62 = load i32, i32* @stderr
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %65)
%67 = load i32, i32* %7
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %57
%72 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%73 = load i32, i32* %72
%74 = load i32, i32* %9
%75 = add nsw i32 %73, %74
%76 = sub nsw i32 %75, 1
%77 = load i32, i32* %9
%78 = sdiv i32 %76, %77
store i32 %78, i32* %8
%79 = load i32, i32* %9
%80 = call i8* @malloc(i32 %79)
store i8* %80, i8** %11
%81 = load i8*, i8** %11
%82 = icmp ne i8* %81, null
br i1 %82, label %90, label %83
83: ; preds = %71
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%86 = load i32, i32* %7
%87 = call i32 @close(i32 %86)
%88 = load i32, i32* @EXIT_FAILURE
%89 = call i32 @exit(i32 %88)
unreachable
90: ; preds = %71
%91 = load i32, i32* %9
%92 = call i8* @malloc(i32 %91)
store i8* %92, i8** %12
%93 = load i8*, i8** %11
%94 = icmp ne i8* %93, null
br i1 %94, label %102, label %95
95: ; preds = %90
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%98 = load i32, i32* %7
%99 = call i32 @close(i32 %98)
%100 = load i32, i32* @EXIT_FAILURE
%101 = call i32 @exit(i32 %100)
unreachable
102: ; preds = %90
%103 = load i8*, i8** %12
%104 = call i32 @memset(i8* %103, i32 0, i32 4096)
store i32 0, i32* %10
br label %105
105: ; preds = %194, %102
%106 = load i32, i32* %10
%107 = load i32, i32* %8
%108 = icmp slt i32 %106, %107
br i1 %108, label %109, label %197
109: ; preds = %105
%110 = load i32, i32* %10
store i32 %110, i32* %13
store i32 0, i32* %14
%111 = load i32, i32* %7
%112 = load i32, i32* @FIBMAP
%113 = call i64 @ioctl(i32 %111, i32 %112, i32* %13)
%114 = icmp ne i64 %113, 0
br i1 %114, label %115, label %125
115: ; preds = %109
%116 = load i32, i32* @stderr
%117 = load i32, i32* @errno
%118 = call i8* @strerror(i32 %117)
%119 = load i32, i32* %10
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* %118, i32 %119)
%121 = load i32, i32* %7
%122 = call i32 @close(i32 %121)
%123 = load i32, i32* @EXIT_FAILURE
%124 = call i32 @exit(i32 %123)
unreachable
125: ; preds = %109
%126 = load i32, i32* %13
%127 = icmp ne i32 %126, 0
br i1 %127, label %158, label %128
128: ; preds = %125
%129 = load i32, i32* %7
%130 = load i32, i32* %9
%131 = load i32, i32* @SEEK_CUR
%132 = call i64 @lseek(i32 %129, i32 %130, i32 %131)
%133 = icmp slt i64 %132, 0
br i1 %133, label %134, label %141
134: ; preds = %128
%135 = load i32, i32* @stderr
%136 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%137 = load i32, i32* %7
%138 = call i32 @close(i32 %137)
%139 = load i32, i32* @EXIT_FAILURE
%140 = call i32 @exit(i32 %139)
unreachable
141: ; preds = %128
%142 = load i8*, i8** %12
%143 = load i32, i32* %9
%144 = call i32 @write(i32 1, i8* %142, i32 %143)
%145 = load i32, i32* %9
%146 = icmp ne i32 %144, %145
br i1 %146, label %147, label %155
147: ; preds = %141
%148 = load i32, i32* @stderr
%149 = load i32, i32* %10
%150 = call i32 (i32, i8*, ...) @fprintf(i32 %148, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %149)
%151 = load i32, i32* %7
%152 = call i32 @close(i32 %151)
%153 = load i32, i32* @EXIT_FAILURE
%154 = call i32 @exit(i32 %153)
unreachable
155: ; preds = %141
%156 = load i32, i32* @stdout
%157 = call i32 @fflush(i32 %156)
br label %194
158: ; preds = %125
%159 = load i32, i32* %7
%160 = load i8*, i8** %11
%161 = load i32, i32* %9
%162 = call i32 @read(i32 %159, i8* %160, i32 %161)
store i32 %162, i32* %14
%163 = load i32, i32* %14
%164 = load i32, i32* %9
%165 = icmp slt i32 %163, %164
br i1 %165, label %166, label %179
166: ; preds = %158
%167 = load i32, i32* %10
%168 = load i32, i32* %8
%169 = sub nsw i32 %168, 1
%170 = icmp ne i32 %167, %169
br i1 %170, label %171, label %178
171: ; preds = %166
%172 = load i32, i32* @stderr
%173 = call i32 (i32, i8*, ...) @fprintf(i32 %172, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%174 = load i32, i32* %7
%175 = call i32 @close(i32 %174)
%176 = load i32, i32* @EXIT_FAILURE
%177 = call i32 @exit(i32 %176)
unreachable
178: ; preds = %166
br label %179
179: ; preds = %178, %158
%180 = load i8*, i8** %11
%181 = load i32, i32* %14
%182 = call i32 @write(i32 1, i8* %180, i32 %181)
%183 = load i32, i32* %14
%184 = icmp ne i32 %182, %183
br i1 %184, label %185, label %193
185: ; preds = %179
%186 = load i32, i32* @stderr
%187 = load i32, i32* %10
%188 = call i32 (i32, i8*, ...) @fprintf(i32 %186, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %187)
%189 = load i32, i32* %7
%190 = call i32 @close(i32 %189)
%191 = load i32, i32* @EXIT_FAILURE
%192 = call i32 @exit(i32 %191)
unreachable
193: ; preds = %179
br label %194
194: ; preds = %193, %155
%195 = load i32, i32* %10
%196 = add nsw i32 %195, 1
store i32 %196, i32* %10
br label %105
197: ; preds = %105
%198 = load i32, i32* %7
%199 = call i32 @close(i32 %198)
%200 = load i32, i32* @stdout
%201 = call i32 @fflush(i32 %200)
%202 = load i32, i32* @EXIT_FAILURE
%203 = call i32 @exit(i32 %202)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"%s a fast sparse-aware cat.\0A\00"
@.str.1 = [17 x i8] c"Usage: %s FILE1\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"
@.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
@SEEK_CUR = global i32 0
@.str.7 = [14 x i8] c"Seek failed.\0A\00"
@.str.8 = [33 x i8] c"Cannot write block %d on STDOUT\0A\00"
@stdout = global i32 0
@.str.9 = [24 x i8] c"Unexpected short read.\0A\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, 2
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 ([29 x i8], [29 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 ([17 x i8], [17 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 @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 = call i8* @malloc(i32 %53)
%58 = icmp eq i8* %57, null
br i1 %58, label %59, label %65
59: ; preds = %50
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%62 = call i32 @close(i32 %22)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %50
%66 = call i8* @malloc(i32 %53)
%67 = call i32 @memset(i8* %66, i32 0, i32 4096)
%68 = icmp sgt i32 %56, 0
br i1 %68, label %69, label %137
69: ; preds = %65
%70 = bitcast i32* %5 to i8*
%71 = add nsw i32 %56, -1
br label %72
72: ; preds = %69, %134
%73 = phi i32 [ 0, %69 ], [ %135, %134 ]
store i32 %73, i32* %5
%74 = load i32, i32* @FIBMAP
%75 = call i64 @ioctl(i32 %22, i32 %74, i32* %5)
%76 = icmp eq i64 %75, 0
br i1 %76, label %85, label %77
77: ; preds = %72
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* %80, i32 %73)
%82 = call i32 @close(i32 %22)
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %72
%86 = load i32, i32* %5
%87 = icmp eq i32 %86, 0
%88 = load i32, i32* %4
br i1 %87, label %89, label %113
89: ; preds = %85
%90 = load i32, i32* @SEEK_CUR
%91 = call i64 @lseek(i32 %22, i32 %88, i32 %90)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %99
93: ; preds = %89
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%96 = call i32 @close(i32 %22)
%97 = load i32, i32* @EXIT_FAILURE
%98 = call i32 @exit(i32 %97)
unreachable
99: ; preds = %89
%100 = load i32, i32* %4
%101 = call i32 @write(i32 1, i8* %66, i32 %100)
%102 = load i32, i32* %4
%103 = icmp eq i32 %101, %102
br i1 %103, label %110, label %104
104: ; preds = %99
%105 = load i32, i32* @stderr
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %73)
%107 = call i32 @close(i32 %22)
%108 = load i32, i32* @EXIT_FAILURE
%109 = call i32 @exit(i32 %108)
unreachable
110: ; preds = %99
%111 = load i32, i32* @stdout
%112 = call i32 @fflush(i32 %111)
br label %134
113: ; preds = %85
%114 = call i32 @read(i32 %22, i8* %57, i32 %88)
%115 = load i32, i32* %4
%116 = icmp sge i32 %114, %115
%117 = icmp eq i32 %73, %71
%118 = select i1 %116, i1 true, i1 %117
br i1 %118, label %125, label %119
119: ; preds = %113
%120 = load i32, i32* @stderr
%121 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%122 = call i32 @close(i32 %22)
%123 = load i32, i32* @EXIT_FAILURE
%124 = call i32 @exit(i32 %123)
unreachable
125: ; preds = %113
%126 = call i32 @write(i32 1, i8* %57, i32 %114)
%127 = icmp eq i32 %126, %114
br i1 %127, label %134, label %128
128: ; preds = %125
%129 = load i32, i32* @stderr
%130 = call i32 (i32, i8*, ...) @fprintf(i32 %129, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %73)
%131 = call i32 @close(i32 %22)
%132 = load i32, i32* @EXIT_FAILURE
%133 = call i32 @exit(i32 %132)
unreachable
134: ; preds = %125, %110
%135 = add nuw nsw i32 %73, 1
%136 = icmp eq i32 %135, %56
br i1 %136, label %137, label %72
137: ; preds = %134, %65
%138 = call i32 @close(i32 %22)
%139 = load i32, i32* @stdout
%140 = call i32 @fflush(i32 %139)
%141 = load i32, i32* @EXIT_FAILURE
%142 = call i32 @exit(i32 %141)
unreachable
}