#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
int util_part_search_fh(int, size_t, size_t, size_t, int *);
int util_part_search(const char *device, size_t blk_start, size_t blk_cnt,
                     size_t blk_size, int *part_ext) {
  int rc, fh;
  fh = open(device, O_RDONLY);
  if (fh == -1)
    return -1;
  rc = util_part_search_fh(fh, blk_start, blk_cnt, blk_size, part_ext);
  close(fh);
  return rc;
}


x86 assembly (clang, -O0):
<util_part_search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1177 <util_part_search+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <util_part_search+0x70>
mov    -0x38(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1040 <util_part_search_fh@plt>
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%edi
call   1030 <close@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_part_search>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1179 <util_part_search+0x49>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <util_part_search_fh@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
jmp    117e <util_part_search+0x4e>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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