#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 */

/* Variables and functions */
scalar_t__ EPERM;
int /*<<< orphan*/ _IO(int, int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int /*<<< orphan*/, unsigned long *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
unsigned long get_bmap(int fd, unsigned long block) {
  int ret;
  unsigned long b;
  b = block;
  ret = ioctl(fd, _IO(0x00, 1), &b);
  if (ret < 0) {
    if (errno == EPERM) {
      fprintf(stderr,
              "No permission to use FIBMAP ioctl; must have root privileges\n");
      exit(1);
    }
    perror("FIBMAP");
  }
  return b;
}


x86 assembly (clang, -O0):
<get_bmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d9 <get_bmap+0x89>
mov    0x2e3d(%rip),%rax
mov    (%rax),%rax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
jne    11cd <get_bmap+0x7d>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe6a(%rip),%rdi
call   1060 <perror@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bmap>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %rsi,0x8(%rsp)
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
test   %eax,%eax
js     1185 <get_bmap+0x35>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
je     11a9 <get_bmap+0x59>
lea    0xe9c(%rip),%rdi
call   1060 <perror@plt>
jmp    117a <get_bmap+0x2a>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EPERM = global i64 0
@stderr = global i32 0
@.str = [62 x i8] c"No permission to use FIBMAP ioctl; must have root privileges\0A\00"
@.str.1 = [7 x i8] c"FIBMAP\00"
define i64 @get_bmap(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
store i64 %7, i64* %6
%8 = load i32, i32* %3
%9 = call i32 @_IO(i32 0, i32 1)
%10 = call i32 @ioctl(i32 %8, i32 %9, i64* %6)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %2
%14 = load i64, i64* @errno
%15 = load i64, i64* @EPERM
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %2
%24 = load i64, i64* %6
ret i64 %24
}

LLVM IR (-O2):
@errno = global i64 0
@EPERM = global i64 0
@stderr = global i32 0
@.str = [62 x i8] c"No permission to use FIBMAP ioctl; must have root privileges\0A\00"
@.str.1 = [7 x i8] c"FIBMAP\00"
define i64 @get_bmap(i32 %0, i64 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
store i64 %1, i64* %3
%5 = tail call i32 @_IO(i32 0, i32 1)
%6 = call i32 @ioctl(i32 %0, i32 %5, i64* %3)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = load i64, i64* @errno
%10 = load i64, i64* @EPERM
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i64, i64* %3
ret i64 %19
}