#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__ util_file_read_ul(unsigned long *, int, char *, unsigned int,
                             unsigned int);
int /*<<< orphan*/ util_path_is_dir(char *, unsigned int, unsigned int);
long get_partition_start(unsigned int major, unsigned int minor) {
  unsigned long val;
  if (!util_path_is_dir("/sys/dev/block/%u:%u", major, minor))
    return -1;
  if (util_file_read_ul(&val, 10, "/sys/dev/block/%u:%u/start", major, minor) !=
      0) {
    return 0;
  }
  return val;
}


x86 assembly (clang, -O0):
<get_partition_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xec5(%rip),%rdi
call   1040 <util_path_is_dir@plt>
cmp    $0x0,%eax
jne    1156 <get_partition_start+0x36>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1191 <get_partition_start+0x71>
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    -0x18(%rbp),%rdi
mov    $0xa,%esi
lea    0xea8(%rip),%rdx
call   1030 <util_file_read_ul@plt>
cmp    $0x0,%rax
je     1189 <get_partition_start+0x69>
movq   $0x0,-0x8(%rbp)
jmp    1191 <get_partition_start+0x71>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_partition_start>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xed2(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <util_path_is_dir@plt>
test   %eax,%eax
je     115f <get_partition_start+0x3f>
lea    0xed3(%rip),%rdx
mov    %rsp,%rdi
mov    $0xa,%esi
mov    %ebp,%ecx
mov    %ebx,%r8d
call   1030 <util_file_read_ul@plt>
test   %rax,%rax
jne    1168 <get_partition_start+0x48>
mov    (%rsp),%rax
jmp    116a <get_partition_start+0x4a>
mov    $0xffffffffffffffff,%rax
jmp    116a <get_partition_start+0x4a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"/sys/dev/block/%u:%u\00"
@.str.1 = [27 x i8] c"/sys/dev/block/%u:%u/start\00"
define i64 @get_partition_start(i32 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = load i32, i32* %5
%9 = call i32 @util_path_is_dir(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %2
store i64 -1, i64* %3
br label %20
12: ; preds = %2
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call i64 @util_file_read_ul(i64* %6, i32 10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i64 0, i64* %3
br label %20
18: ; preds = %12
%19 = load i64, i64* %6
store i64 %19, i64* %3
br label %20
20: ; preds = %18, %17, %11
%21 = load i64, i64* %3
ret i64 %21
}

LLVM IR (-O2):
@.str = [21 x i8] c"/sys/dev/block/%u:%u\00"
@.str.1 = [27 x i8] c"/sys/dev/block/%u:%u/start\00"
define i64 @get_partition_start(i32 %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = tail call i32 @util_path_is_dir(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = call i64 @util_file_read_ul(i64* %3, i32 10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1)
%9 = icmp eq i64 %8, 0
%10 = load i64, i64* %3
%11 = select i1 %9, i64 %10, i64 0
br label %12
12: ; preds = %7, %2
%13 = phi i64 [ -1, %2 ], [ %11, %7 ]
ret i64 %13
}