#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 int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
unsigned long get_bmap(int fd, unsigned long block) {
  int ret;
  unsigned int 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    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d8 <get_bmap+0x88>
mov    0x2e3e(%rip),%rax
mov    (%rax),%rax
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%rax
jne    11cc <get_bmap+0x7c>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe6b(%rip),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_bmap>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,0xc(%rsp)
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
test   %eax,%eax
js     1183 <get_bmap+0x33>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e4e(%rip),%rax
mov    (%rax),%rax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%rax
je     11a7 <get_bmap+0x57>
lea    0xe9e(%rip),%rdi
call   1060 <perror@plt>
jmp    1179 <get_bmap+0x29>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%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 i32
store i32 %0, i32* %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = trunc i64 %7 to i32
store i32 %8, i32* %6
%9 = load i32, i32* %3
%10 = call i32 @_IO(i32 0, i32 1)
%11 = call i32 @ioctl(i32 %9, i32 %10, i32* %6)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load i64, i64* @errno
%16 = load i64, i64* @EPERM
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
%25 = load i32, i32* %6
%26 = zext i32 %25 to i64
ret i64 %26
}

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 i32
%4 = bitcast i32* %3 to i8*
%5 = trunc i64 %1 to i32
store i32 %5, i32* %3
%6 = tail call i32 @_IO(i32 0, i32 1)
%7 = call i32 @ioctl(i32 %0, i32 %6, i32* %3)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = load i64, i64* @errno
%11 = load i64, i64* @EPERM
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = load i32, i32* %3
%21 = zext i32 %20 to i64
ret i64 %21
}