#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 */
int /*<<< orphan*/ BLKGETSIZE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, unsigned long *);
int open(char const *, int /*<<< orphan*/);
size_t _get_device_size(const char *device) {
  unsigned long size = 0;
  int fd;
  fd = open(device, O_RDONLY);
  if (fd == -1)
    return 0;
  (void)ioctl(fd, BLKGETSIZE, &size);
  close(fd);
  return size;
}


x86 assembly (clang, -O0):
<_get_device_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1170 <_get_device_size+0x40>
movq   $0x0,-0x8(%rbp)
jmp    1195 <_get_device_size+0x65>
mov    -0x1c(%rbp),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_device_size>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1176 <_get_device_size+0x46>
mov    %eax,%ebx
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x8(%rsp),%rax
jmp    1178 <_get_device_size+0x48>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@BLKGETSIZE = global i32 0
define i64 @_get_device_size(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
store i64 0, i64* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %1
store i64 0, i64* %2
br label %19
12: ; preds = %1
%13 = load i32, i32* %5
%14 = load i32, i32* @BLKGETSIZE
%15 = call i32 @ioctl(i32 %13, i32 %14, i64* %4)
%16 = load i32, i32* %5
%17 = call i32 @close(i32 %16)
%18 = load i64, i64* %4
store i64 %18, i64* %2
br label %19
19: ; preds = %12, %11
%20 = load i64, i64* %2
ret i64 %20
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@BLKGETSIZE = global i32 0
define i64 @_get_device_size(i8* nocapture %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = load i32, i32* @BLKGETSIZE
%9 = call i32 @ioctl(i32 %5, i32 %8, i64* %2)
%10 = call i32 @close(i32 %5)
%11 = load i64, i64* %2
br label %12
12: ; preds = %1, %7
%13 = phi i64 [ %11, %7 ], [ 0, %1 ]
ret i64 %13
}