#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 int int64_t;

/* Variables and functions */
int /*<<< orphan*/ BLKGETSIZE64;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, int *);
int open(char const *, int /*<<< orphan*/);
int64_t diskSize(const char *pathName) {
  if (!pathName)
    return -1;
  int fd = open(pathName, O_RDONLY);
  if (fd == -1) {
    return -1;
  }
  int64_t size = 0;
  int sc = ioctl(fd, BLKGETSIZE64, &size);
  close(fd);
  if (sc == -1) {
    return -1;
  }
  return size;
}


x86 assembly (clang, -O0):
<diskSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <diskSize+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <diskSize+0x91>
mov    -0x10(%rbp),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117e <diskSize+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <diskSize+0x91>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11bb <diskSize+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <diskSize+0x91>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diskSize>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     1181 <diskSize+0x51>
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1181 <diskSize+0x51>
mov    %eax,%ebp
movl   $0x0,0x4(%rsp)
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebp,%edi
call   1030 <ioctl@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
cmp    $0xffffffff,%ebx
je     1181 <diskSize+0x51>
mov    0x4(%rsp),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@BLKGETSIZE64 = global i32 0
define i32 @diskSize(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 -1, i32* %2
br label %28
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 -1, i32* %2
br label %28
17: ; preds = %10
store i32 0, i32* %5
%18 = load i32, i32* %4
%19 = load i32, i32* @BLKGETSIZE64
%20 = call i32 @ioctl(i32 %18, i32 %19, i32* %5)
store i32 %20, i32* %6
%21 = load i32, i32* %4
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 -1, i32* %2
br label %28
26: ; preds = %17
%27 = load i32, i32* %5
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %25, %16, %9
%29 = load i32, i32* %2
ret i32 %29
}

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