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

/* Forward declarations */

/* Type definitions */
typedef unsigned int uint64_t;
struct stat {
  scalar_t__ st_rdev;
  scalar_t__ st_dev;
  unsigned int st_size;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ BLKDISCARDZEROES;
int /*<<< orphan*/ BLKGETSIZE64;
int /*<<< orphan*/ FIBMAP;
int /*<<< orphan*/ FIGETBSZ;
unsigned int O_EXCL;
unsigned int O_RDWR;
int /*<<< orphan*/ S_ISBLK(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dbz_discard(int, unsigned int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fstat(int, struct stat *);
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned int *);
int open(char const *, unsigned int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
bool dbz(const char *devpath, const char *fname, bool query) {
  bool ret = false;
  int fd = -1, fdr = -1;
  unsigned does_zero, blksz, blk, i, flags = O_RDWR;
  uint64_t range[2];
  struct stat stdev, stfile;
  if (!query && fname == NULL)
    flags |= O_EXCL;
  fd = open(devpath, flags);
  if (fd < 0) {
    perror("open(devnode)");
    goto fail;
  }
  if (fstat(fd, &stdev) != 0) {
    perror("stat(devnode)");
    goto fail;
  }
  if (!S_ISBLK(stdev.st_mode)) {
    fprintf(stderr, "%s is not a block device\n", devpath);
    goto fail;
  }
  if (query) {
    if (ioctl(fd, BLKDISCARDZEROES, &does_zero) != 0) {
      perror("ioctl(BLKDISCARDZEROES)");
      goto fail;
    }
    if (does_zero == 0) {
      fprintf(stderr, "Device does NOT return zeroes for discarded blocks.\n");
      goto fail;
    }
    fprintf(stderr, "Device DOES return zeroes for discarded blocks.\n");
  } else {
    if (fname != NULL) {
      fdr = open(fname, O_RDWR);
      if (fdr < 0) {
        perror("open(file)");
        goto fail;
      }
      if (fstat(fdr, &stfile) != 0) {
        perror("stat(file)");
        goto fail;
      }
      if (!S_ISREG(stfile.st_mode)) {
        fprintf(stderr, "%s is not a regular file\n", fname);
        goto fail;
      }
      if (stdev.st_rdev != stfile.st_dev) {
        fprintf(stderr, "%s is not the mounted device containing %s\n", devpath,
                fname);
        goto fail;
      }
      if (ioctl(fdr, FIGETBSZ, &blksz) != 0) {
        perror("ioctl(FIGETBSZ)");
        goto fail;
      }
      range[0] = 0;
      range[1] = 0;
      for (i = 0; i < stfile.st_size / blksz; i++) {
        blk = i;
        if (ioctl(fdr, FIBMAP, &blk) != 0) {
          perror("ioctl(FIBMAP)");
          goto fail;
        }
        if (blk == 0)
          continue;
        if (blk == (range[0] + range[1]) / blksz) {
          range[1] += blksz;
          continue;
        }
        if (!dbz_discard(fd, range))
          goto fail;
        range[0] = (uint64_t)blk * blksz;
        range[1] = blksz;
      }
      if (!dbz_discard(fd, range))
        goto fail;
    } else {
      range[0] = 0;
      if (ioctl(fd, BLKGETSIZE64, &range[1]) != 0) {
        perror("ioctl(BLKGETSIZE64)");
        goto fail;
      }
      if (!dbz_discard(fd, range))
        goto fail;
    }
  }
  ret = true;
fail:
  if (fd >= 0)
    close(fd);
  if (fdr >= 0)
    close(fdr);
  return ret;
}


x86 assembly (clang, -O0):
<dbz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11eb <dbz+0x5b>
cmpq   $0x0,-0x10(%rbp)
jne    11eb <dbz+0x5b>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
or     -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1215 <dbz+0x85>
lea    0xdf5(%rip),%rdi
call   10a0 <perror@plt>
jmp    153c <dbz+0x3ac>
mov    -0x1c(%rbp),%edi
lea    -0x58(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0x0,%rax
je     123c <dbz+0xac>
lea    0xddc(%rip),%rdi
call   10a0 <perror@plt>
jmp    153c <dbz+0x3ac>
mov    -0x44(%rbp),%edi
call   1080 <S_ISBLK@plt>
cmp    $0x0,%eax
jne    126d <dbz+0xdd>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    153c <dbz+0x3ac>
cmpl   $0x0,-0x14(%rbp)
je     12e9 <dbz+0x159>
mov    -0x1c(%rbp),%edi
mov    0x2d2f(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     12a7 <dbz+0x117>
lea    0xd99(%rip),%rdi
call   10a0 <perror@plt>
jmp    153c <dbz+0x3ac>
cmpl   $0x0,-0x24(%rbp)
jne    12cd <dbz+0x13d>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    153c <dbz+0x3ac>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1535 <dbz+0x3a5>
cmpq   $0x0,-0x10(%rbp)
je     14d6 <dbz+0x346>
mov    -0x10(%rbp),%rdi
mov    0x2ce9(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1324 <dbz+0x194>
lea    0xd9a(%rip),%rdi
call   10a0 <perror@plt>
jmp    153c <dbz+0x3ac>
mov    -0x20(%rbp),%edi
lea    -0x70(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0x0,%rax
je     134b <dbz+0x1bb>
lea    0xd7e(%rip),%rdi
call   10a0 <perror@plt>
jmp    153c <dbz+0x3ac>
mov    -0x5c(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%eax
jne    137c <dbz+0x1ec>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    153c <dbz+0x3ac>
mov    -0x58(%rbp),%rax
cmp    -0x68(%rbp),%rax
je     13ae <dbz+0x21e>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd42(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    153c <dbz+0x3ac>
mov    -0x20(%rbp),%edi
mov    0x2c28(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     13de <dbz+0x24e>
lea    0xd3c(%rip),%rdi
call   10a0 <perror@plt>
jmp    153c <dbz+0x3ac>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x60(%rbp),%eax
xor    %edx,%edx
divl   -0x28(%rbp)
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
cmp    %ecx,%eax
jae    14b7 <dbz+0x327>
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2b9a(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     1444 <dbz+0x2b4>
lea    0xce6(%rip),%rdi
call   10a0 <perror@plt>
jmp    153c <dbz+0x3ac>
cmpl   $0x0,-0x2c(%rbp)
jne    1453 <dbz+0x2c3>
jmp    14a9 <dbz+0x319>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x3c(%rbp),%eax
add    -0x38(%rbp),%eax
xor    %edx,%edx
divl   -0x28(%rbp)
mov    %eax,%ecx
mov    -0x78(%rbp),%eax
cmp    %ecx,%eax
jne    147f <dbz+0x2ef>
mov    -0x28(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    14a9 <dbz+0x319>
mov    -0x1c(%rbp),%edi
lea    -0x3c(%rbp),%rsi
call   1030 <dbz_discard@plt>
cmp    $0x0,%eax
jne    1499 <dbz+0x309>
jmp    153c <dbz+0x3ac>
mov    -0x2c(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    13f3 <dbz+0x263>
mov    -0x1c(%rbp),%edi
lea    -0x3c(%rbp),%rsi
call   1030 <dbz_discard@plt>
cmp    $0x0,%eax
jne    14d1 <dbz+0x341>
jmp    153c <dbz+0x3ac>
jmp    1530 <dbz+0x3a0>
movl   $0x0,-0x3c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2af1(%rip),%rax
mov    (%rax),%esi
lea    -0x3c(%rbp),%rdx
add    $0x4,%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
je     1511 <dbz+0x381>
lea    0xc27(%rip),%rdi
call   10a0 <perror@plt>
jmp    153c <dbz+0x3ac>
mov    -0x1c(%rbp),%edi
lea    -0x3c(%rbp),%rsi
call   1030 <dbz_discard@plt>
cmp    $0x0,%eax
jne    152b <dbz+0x39b>
jmp    153c <dbz+0x3ac>
jmp    1530 <dbz+0x3a0>
jmp    1535 <dbz+0x3a5>
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     154e <dbz+0x3be>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x0,-0x20(%rbp)
jl     1560 <dbz+0x3d0>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r13
mov    0x2e3b(%rip),%r14
xor    %esi,%esi
mov    $0x0,%eax
test   %edx,%edx
jne    11c1 <dbz+0x31>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
test   %rbx,%rbx
cmove  %eax,%esi
or     (%r14),%esi
mov    %r13,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1393 <dbz+0x203>
mov    %eax,%r15d
lea    0x30(%rsp),%rsi
mov    %eax,%edi
call   10b0 <fstat@plt>
test   %rax,%rax
jne    13a4 <dbz+0x214>
mov    0x44(%rsp),%edi
call   1080 <S_ISBLK@plt>
test   %eax,%eax
je     126b <dbz+0xdb>
test   %ebp,%ebp
je     128d <dbz+0xfd>
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdx
mov    %r15d,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
jne    13ee <dbz+0x25e>
cmpl   $0x0,0x18(%rsp)
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
je     1336 <dbz+0x1a6>
lea    0xe42(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    $0x1,%r12d
test   %r15d,%r15d
jns    1403 <dbz+0x273>
test   %r14d,%r14d
jns    1410 <dbz+0x280>
jmp    1418 <dbz+0x288>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
xor    %r12d,%r12d
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    13fd <dbz+0x26d>
test   %rbx,%rbx
je     134c <dbz+0x1bc>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
js     14bb <dbz+0x32b>
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
call   10b0 <fstat@plt>
test   %rax,%rax
jne    14c4 <dbz+0x334>
mov    0x2c(%rsp),%edi
call   1070 <S_ISREG@plt>
test   %eax,%eax
je     13ad <dbz+0x21d>
mov    0x30(%rsp),%rax
cmp    0x20(%rsp),%rax
jne    13cc <dbz+0x23c>
mov    0x2cf6(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
mov    %r14d,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
jne    14d9 <dbz+0x349>
movq   $0x0,0x8(%rsp)
mov    0x28(%rsp),%ebx
cmp    %ebx,0x10(%rsp)
jbe    142a <dbz+0x29a>
lea    0x8(%rsp),%rsi
mov    %r15d,%edi
call   1030 <dbz_discard@plt>
test   %eax,%eax
jne    124e <dbz+0xbe>
xor    %r12d,%r12d
jmp    1254 <dbz+0xc4>
lea    0xd11(%rip),%rsi
xor    %r12d,%r12d
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    13fd <dbz+0x26d>
movl   $0x0,0x8(%rsp)
mov    0x2c7d(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %r15d,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
jne    14cd <dbz+0x33d>
lea    0x8(%rsp),%rsi
mov    %r15d,%edi
call   1030 <dbz_discard@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
jne    124e <dbz+0xbe>
xor    %r12d,%r12d
jmp    1403 <dbz+0x273>
lea    0xc66(%rip),%rdi
call   10a0 <perror@plt>
xor    %r12d,%r12d
jmp    1418 <dbz+0x288>
lea    0xc63(%rip),%rdi
jmp    13f5 <dbz+0x265>
mov    0x2c14(%rip),%rax
mov    (%rax),%edi
lea    0xd0d(%rip),%rsi
xor    %r12d,%r12d
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1403 <dbz+0x273>
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
lea    0xd08(%rip),%rsi
xor    %r12d,%r12d
mov    %r13,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1403 <dbz+0x273>
lea    0xc41(%rip),%rdi
call   10a0 <perror@plt>
xor    %r12d,%r12d
mov    $0xffffffff,%r14d
mov    %r15d,%edi
call   1050 <close@plt>
test   %r14d,%r14d
js     1418 <dbz+0x288>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r12d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    0x2b85(%rip),%r12
lea    0x14(%rsp),%r13
jmp    144f <dbz+0x2bf>
mov    0x10(%rsp),%ecx
add    $0x1,%ebp
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
cmp    %eax,%ebp
jae    1319 <dbz+0x189>
mov    %ebp,0x14(%rsp)
mov    (%r12),%esi
mov    %r14d,%edi
mov    %r13,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
jne    14ed <dbz+0x35d>
mov    0x14(%rsp),%edi
test   %edi,%edi
je     143a <dbz+0x2aa>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%eax
add    %esi,%eax
mov    0x10(%rsp),%ecx
xor    %edx,%edx
div    %ecx
cmp    %eax,%edi
jne    1491 <dbz+0x301>
add    %ecx,%esi
mov    %esi,0xc(%rsp)
jmp    143e <dbz+0x2ae>
mov    %r15d,%edi
lea    0x8(%rsp),%rsi
call   1030 <dbz_discard@plt>
test   %eax,%eax
je     132e <dbz+0x19e>
mov    0x10(%rsp),%ecx
mov    0x14(%rsp),%eax
imul   %ecx,%eax
mov    %eax,0x8(%rsp)
mov    %ecx,0xc(%rsp)
jmp    143e <dbz+0x2ae>
lea    0xbf2(%rip),%rdi
jmp    14e0 <dbz+0x350>
lea    0xbf4(%rip),%rdi
jmp    14e0 <dbz+0x350>
lea    0xc5a(%rip),%rdi
jmp    13f5 <dbz+0x265>
lea    0xc30(%rip),%rdi
call   10a0 <perror@plt>
xor    %r12d,%r12d
jmp    1403 <dbz+0x273>
lea    0xc2c(%rip),%rdi
call   10a0 <perror@plt>
xor    %r12d,%r12d
jmp    1254 <dbz+0xc4>

LLVM IR (-O0):
%struct.stat = type { i64, i64, i32, i32 }
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@.str = [14 x i8] c"open(devnode)\00"
@.str.1 = [14 x i8] c"stat(devnode)\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"%s is not a block device\0A\00"
@BLKDISCARDZEROES = global i32 0
@.str.3 = [24 x i8] c"ioctl(BLKDISCARDZEROES)\00"
@.str.4 = [53 x i8] c"Device does NOT return zeroes for discarded blocks.\0A\00"
@.str.5 = [49 x i8] c"Device DOES return zeroes for discarded blocks.\0A\00"
@.str.6 = [11 x i8] c"open(file)\00"
@.str.7 = [11 x i8] c"stat(file)\00"
@.str.8 = [26 x i8] c"%s is not a regular file\0A\00"
@.str.9 = [44 x i8] c"%s is not the mounted device containing %s\0A\00"
@FIGETBSZ = global i32 0
@.str.10 = [16 x i8] c"ioctl(FIGETBSZ)\00"
@FIBMAP = global i32 0
@.str.11 = [14 x i8] c"ioctl(FIBMAP)\00"
@BLKGETSIZE64 = global i32 0
@.str.12 = [20 x i8] c"ioctl(BLKGETSIZE64)\00"
define i32 @dbz(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%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 [2 x i32]
%16 = alloca %struct.stat
%17 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 -1, i32* %8
store i32 -1, i32* %9
%18 = load i32, i32* @O_RDWR
store i32 %18, i32* %14
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* @O_EXCL
%26 = load i32, i32* %14
%27 = or i32 %26, %25
store i32 %27, i32* %14
br label %28
28: ; preds = %24, %21, %3
%29 = load i8*, i8** %4
%30 = load i32, i32* %14
%31 = call i32 @open(i8* %29, i32 %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %192
36: ; preds = %28
%37 = load i32, i32* %8
%38 = call i64 @fstat(i32 %37, %struct.stat* %16)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %192
42: ; preds = %36
%43 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 3
%44 = load i32, i32* %43
%45 = call i32 @S_ISBLK(i32 %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %4
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %49)
br label %192
51: ; preds = %42
%52 = load i32, i32* %6
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %70
54: ; preds = %51
%55 = load i32, i32* %8
%56 = load i32, i32* @BLKDISCARDZEROES
%57 = call i64 @ioctl(i32 %55, i32 %56, i32* %10)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %192
61: ; preds = %54
%62 = load i32, i32* %10
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
br label %192
67: ; preds = %61
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
br label %191
70: ; preds = %51
%71 = load i8*, i8** %5
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %174
73: ; preds = %70
%74 = load i8*, i8** %5
%75 = load i32, i32* @O_RDWR
%76 = call i32 @open(i8* %74, i32 %75)
store i32 %76, i32* %9
%77 = load i32, i32* %9
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %73
%80 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %192
81: ; preds = %73
%82 = load i32, i32* %9
%83 = call i64 @fstat(i32 %82, %struct.stat* %17)
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %192
87: ; preds = %81
%88 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 3
%89 = load i32, i32* %88
%90 = call i32 @S_ISREG(i32 %89)
%91 = icmp ne i32 %90, 0
br i1 %91, label %96, label %92
92: ; preds = %87
%93 = load i32, i32* @stderr
%94 = load i8*, i8** %5
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %94)
br label %192
96: ; preds = %87
%97 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%98 = load i64, i64* %97
%99 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 1
%100 = load i64, i64* %99
%101 = icmp ne i64 %98, %100
br i1 %101, label %102, label %107
102: ; preds = %96
%103 = load i32, i32* @stderr
%104 = load i8*, i8** %4
%105 = load i8*, i8** %5
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), i8* %104, i8* %105)
br label %192
107: ; preds = %96
%108 = load i32, i32* %9
%109 = load i32, i32* @FIGETBSZ
%110 = call i64 @ioctl(i32 %108, i32 %109, i32* %11)
%111 = icmp ne i64 %110, 0
br i1 %111, label %112, label %114
112: ; preds = %107
%113 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %192
114: ; preds = %107
%115 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
store i32 0, i32* %115
%116 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 1
store i32 0, i32* %116
store i32 0, i32* %13
br label %117
117: ; preds = %164, %114
%118 = load i32, i32* %13
%119 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 2
%120 = load i32, i32* %119
%121 = load i32, i32* %11
%122 = udiv i32 %120, %121
%123 = icmp ult i32 %118, %122
br i1 %123, label %124, label %167
124: ; preds = %117
%125 = load i32, i32* %13
store i32 %125, i32* %12
%126 = load i32, i32* %9
%127 = load i32, i32* @FIBMAP
%128 = call i64 @ioctl(i32 %126, i32 %127, i32* %12)
%129 = icmp ne i64 %128, 0
br i1 %129, label %130, label %132
130: ; preds = %124
%131 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
br label %192
132: ; preds = %124
%133 = load i32, i32* %12
%134 = icmp eq i32 %133, 0
br i1 %134, label %135, label %136
135: ; preds = %132
br label %164
136: ; preds = %132
%137 = load i32, i32* %12
%138 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%139 = load i32, i32* %138
%140 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 1
%141 = load i32, i32* %140
%142 = add i32 %139, %141
%143 = load i32, i32* %11
%144 = udiv i32 %142, %143
%145 = icmp eq i32 %137, %144
br i1 %145, label %146, label %151
146: ; preds = %136
%147 = load i32, i32* %11
%148 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 1
%149 = load i32, i32* %148
%150 = add i32 %149, %147
store i32 %150, i32* %148
br label %164
151: ; preds = %136
%152 = load i32, i32* %8
%153 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%154 = call i32 @dbz_discard(i32 %152, i32* %153)
%155 = icmp ne i32 %154, 0
br i1 %155, label %157, label %156
156: ; preds = %151
br label %192
157: ; preds = %151
%158 = load i32, i32* %12
%159 = load i32, i32* %11
%160 = mul i32 %158, %159
%161 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
store i32 %160, i32* %161
%162 = load i32, i32* %11
%163 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 1
store i32 %162, i32* %163
br label %164
164: ; preds = %157, %146, %135
%165 = load i32, i32* %13
%166 = add i32 %165, 1
store i32 %166, i32* %13
br label %117
167: ; preds = %117
%168 = load i32, i32* %8
%169 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%170 = call i32 @dbz_discard(i32 %168, i32* %169)
%171 = icmp ne i32 %170, 0
br i1 %171, label %173, label %172
172: ; preds = %167
br label %192
173: ; preds = %167
br label %190
174: ; preds = %70
%175 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
store i32 0, i32* %175
%176 = load i32, i32* %8
%177 = load i32, i32* @BLKGETSIZE64
%178 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 1
%179 = call i64 @ioctl(i32 %176, i32 %177, i32* %178)
%180 = icmp ne i64 %179, 0
br i1 %180, label %181, label %183
181: ; preds = %174
%182 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
br label %192
183: ; preds = %174
%184 = load i32, i32* %8
%185 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%186 = call i32 @dbz_discard(i32 %184, i32* %185)
%187 = icmp ne i32 %186, 0
br i1 %187, label %189, label %188
188: ; preds = %183
br label %192
189: ; preds = %183
br label %190
190: ; preds = %189, %173
br label %191
191: ; preds = %190, %67
store i32 1, i32* %7
br label %192
192: ; preds = %191, %188, %181, %172, %156, %130, %112, %102, %92, %85, %79, %64, %59, %47, %40, %34
%193 = load i32, i32* %8
%194 = icmp sge i32 %193, 0
br i1 %194, label %195, label %198
195: ; preds = %192
%196 = load i32, i32* %8
%197 = call i32 @close(i32 %196)
br label %198
198: ; preds = %195, %192
%199 = load i32, i32* %9
%200 = icmp sge i32 %199, 0
br i1 %200, label %201, label %204
201: ; preds = %198
%202 = load i32, i32* %9
%203 = call i32 @close(i32 %202)
br label %204
204: ; preds = %201, %198
%205 = load i32, i32* %7
ret i32 %205
}

LLVM IR (-O2):
%struct.stat = type { i64, i64, i32, i32 }
@O_RDWR = global i32 0
@O_EXCL = global i32 0
@.str = [14 x i8] c"open(devnode)\00"
@.str.1 = [14 x i8] c"stat(devnode)\00"
@stderr = global i32 0
@.str.2 = [26 x i8] c"%s is not a block device\0A\00"
@BLKDISCARDZEROES = global i32 0
@.str.3 = [24 x i8] c"ioctl(BLKDISCARDZEROES)\00"
@.str.4 = [53 x i8] c"Device does NOT return zeroes for discarded blocks.\0A\00"
@.str.5 = [49 x i8] c"Device DOES return zeroes for discarded blocks.\0A\00"
@.str.6 = [11 x i8] c"open(file)\00"
@.str.7 = [11 x i8] c"stat(file)\00"
@.str.8 = [26 x i8] c"%s is not a regular file\0A\00"
@.str.9 = [44 x i8] c"%s is not the mounted device containing %s\0A\00"
@FIGETBSZ = global i32 0
@.str.10 = [16 x i8] c"ioctl(FIGETBSZ)\00"
@FIBMAP = global i32 0
@.str.11 = [14 x i8] c"ioctl(FIBMAP)\00"
@BLKGETSIZE64 = global i32 0
@.str.12 = [20 x i8] c"ioctl(BLKGETSIZE64)\00"
define i32 @dbz(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca %struct.stat
%9 = alloca %struct.stat
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = load i32, i32* @O_RDWR
%14 = bitcast [2 x i32]* %7 to i8*
%15 = bitcast %struct.stat* %8 to i8*
%16 = bitcast %struct.stat* %9 to i8*
%17 = icmp eq i32 %2, 0
%18 = icmp eq i8* %1, null
%19 = and i1 %18, %17
%20 = load i32, i32* @O_EXCL
%21 = select i1 %19, i32 %20, i32 0
%22 = or i32 %21, %13
%23 = tail call i32 @open(i8* %0, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %3
%26 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %160
27: ; preds = %3
%28 = call i64 @fstat(i32 %23, %struct.stat* %8)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %150
32: ; preds = %27
%33 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 3
%34 = load i32, i32* %33
%35 = tail call i32 @S_ISBLK(i32 %34)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %150
40: ; preds = %32
br i1 %17, label %55, label %41
41: ; preds = %40
%42 = load i32, i32* @BLKDISCARDZEROES
%43 = call i64 @ioctl(i32 %23, i32 %42, i32* %4)
%44 = icmp eq i64 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %41
%46 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %150
47: ; preds = %41
%48 = load i32, i32* %4
%49 = icmp eq i32 %48, 0
%50 = load i32, i32* @stderr
br i1 %49, label %51, label %53
51: ; preds = %47
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0))
br label %150
53: ; preds = %47
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0))
br label %144
55: ; preds = %40
br i1 %18, label %133, label %56
56: ; preds = %55
%57 = load i32, i32* @O_RDWR
%58 = tail call i32 @open(i8* %1, i32 %57)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %150
62: ; preds = %56
%63 = call i64 @fstat(i32 %58, %struct.stat* %9)
%64 = icmp eq i64 %63, 0
br i1 %64, label %67, label %65
65: ; preds = %62
%66 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %150
67: ; preds = %62
%68 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 3
%69 = load i32, i32* %68
%70 = tail call i32 @S_ISREG(i32 %69)
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %67
%73 = load i32, i32* @stderr
%74 = tail call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %1)
br label %150
75: ; preds = %67
%76 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 0
%77 = load i64, i64* %76
%78 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 1
%79 = load i64, i64* %78
%80 = icmp eq i64 %77, %79
br i1 %80, label %84, label %81
81: ; preds = %75
%82 = load i32, i32* @stderr
%83 = tail call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), i8* %0, i8* %1)
br label %150
84: ; preds = %75
%85 = load i32, i32* @FIGETBSZ
%86 = call i64 @ioctl(i32 %58, i32 %85, i32* %5)
%87 = icmp eq i64 %86, 0
br i1 %87, label %90, label %88
88: ; preds = %84
%89 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %150
90: ; preds = %84
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 0, i32* %91
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
store i32 0, i32* %92
%93 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 2
%94 = load i32, i32* %93
%95 = load i32, i32* %5
%96 = icmp ugt i32 %95, %94
br i1 %96, label %130, label %97
97: ; preds = %90, %125
%98 = phi i32 [ %127, %125 ], [ 0, %90 ]
store i32 %98, i32* %6
%99 = load i32, i32* @FIBMAP
%100 = call i64 @ioctl(i32 %58, i32 %99, i32* %6)
%101 = icmp eq i64 %100, 0
br i1 %101, label %104, label %102
102: ; preds = %97
%103 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
br label %146
104: ; preds = %97
%105 = load i32, i32* %6
%106 = icmp eq i32 %105, 0
br i1 %106, label %107, label %109
107: ; preds = %104
%108 = load i32, i32* %5
br label %125
109: ; preds = %104
%110 = load i32, i32* %91
%111 = load i32, i32* %92
%112 = add i32 %111, %110
%113 = load i32, i32* %5
%114 = udiv i32 %112, %113
%115 = icmp eq i32 %105, %114
br i1 %115, label %116, label %118
116: ; preds = %109
%117 = add i32 %113, %111
store i32 %117, i32* %92
br label %125
118: ; preds = %109
%119 = call i32 @dbz_discard(i32 %23, i32* %91)
%120 = icmp eq i32 %119, 0
br i1 %120, label %146, label %121
121: ; preds = %118
%122 = load i32, i32* %6
%123 = load i32, i32* %5
%124 = mul i32 %123, %122
store i32 %124, i32* %91
store i32 %123, i32* %92
br label %125
125: ; preds = %107, %121, %116
%126 = phi i32 [ %108, %107 ], [ %123, %121 ], [ %113, %116 ]
%127 = add nuw i32 %98, 1
%128 = udiv i32 %94, %126
%129 = icmp ult i32 %127, %128
br i1 %129, label %97, label %130
130: ; preds = %125, %90
%131 = call i32 @dbz_discard(i32 %23, i32* %91)
%132 = icmp eq i32 %131, 0
br i1 %132, label %146, label %144
133: ; preds = %55
%134 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
store i32 0, i32* %134
%135 = load i32, i32* @BLKGETSIZE64
%136 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%137 = call i64 @ioctl(i32 %23, i32 %135, i32* %136)
%138 = icmp eq i64 %137, 0
br i1 %138, label %141, label %139
139: ; preds = %133
%140 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
br label %150
141: ; preds = %133
%142 = call i32 @dbz_discard(i32 %23, i32* %134)
%143 = icmp eq i32 %142, 0
br i1 %143, label %150, label %144
144: ; preds = %130, %141, %53
%145 = phi i32 [ -1, %53 ], [ %58, %130 ], [ -1, %141 ]
br label %146
146: ; preds = %118, %130, %144, %102
%147 = phi i32 [ 1, %144 ], [ 0, %102 ], [ 0, %130 ], [ 0, %118 ]
%148 = phi i32 [ %145, %144 ], [ %58, %102 ], [ %58, %130 ], [ %58, %118 ]
%149 = icmp sgt i32 %23, -1
br i1 %149, label %150, label %154
150: ; preds = %30, %37, %45, %51, %60, %65, %72, %81, %88, %139, %141, %146
%151 = phi i32 [ %148, %146 ], [ -1, %37 ], [ -1, %141 ], [ -1, %139 ], [ %58, %72 ], [ %58, %88 ], [ %58, %81 ], [ %58, %65 ], [ %58, %60 ], [ -1, %51 ], [ -1, %45 ], [ -1, %30 ]
%152 = phi i32 [ %147, %146 ], [ 0, %37 ], [ 0, %141 ], [ 0, %139 ], [ 0, %72 ], [ 0, %88 ], [ 0, %81 ], [ 0, %65 ], [ 0, %60 ], [ 0, %51 ], [ 0, %45 ], [ 0, %30 ]
%153 = call i32 @close(i32 %23)
br label %154
154: ; preds = %150, %146
%155 = phi i32 [ %151, %150 ], [ %148, %146 ]
%156 = phi i32 [ %152, %150 ], [ %147, %146 ]
%157 = icmp sgt i32 %155, -1
br i1 %157, label %158, label %160
158: ; preds = %154
%159 = call i32 @close(i32 %155)
br label %160
160: ; preds = %25, %158, %154
%161 = phi i32 [ 0, %25 ], [ %156, %158 ], [ %156, %154 ]
ret i32 %161
}