#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 /*<<< orphan*/ dev_t;
typedef int /*<<< orphan*/ __u64;
typedef int /*<<< orphan*/ __u32;

/* Variables and functions */
int O_NONBLOCK;
int O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int errno;
int find_dev_in_directory(int /*<<< orphan*/, char *, char *, int);
int get_dev_geometry(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                     int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                     int /*<<< orphan*/ *);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int get_dev_t_geometry(dev_t dev, __u32 *cyls, __u32 *heads, __u32 *sects,
                       __u64 *start_lba, __u64 *nsectors) {
  char path[PATH_MAX];
  int fd, err;
  err = find_dev_in_directory(dev, "/dev", path, 1);
  if (err)
    return err;
  fd = open(path, O_RDONLY | O_NONBLOCK);
  if (fd == -1) {
    err = errno;
    perror(path);
    return err;
  }
  err = get_dev_geometry(fd, cyls, heads, sects, start_lba, nsectors);
  close(fd);
  return err;
}


x86 assembly (clang, -O0):
<get_dev_t_geometry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe5b(%rip),%rsi
mov    $0x1,%ecx
call   1030 <find_dev_in_directory@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
je     11ce <get_dev_t_geometry+0x7e>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1251 <get_dev_t_geometry+0x101>
mov    -0x58(%rbp),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    0x2dfe(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    121d <get_dev_t_geometry+0xcd>
mov    -0x58(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
call   1070 <perror@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1251 <get_dev_t_geometry+0x101>
mov    -0x44(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
call   1050 <get_dev_geometry@plt>
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%edi
call   1040 <close@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dev_t_geometry>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,-0x38(%rbp)
mov    %r8,-0x30(%rbp)
mov    %rcx,%r13
mov    %rdx,%r12
mov    %rsi,%rbx
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe6d(%rip),%rsi
mov    %r14,%rdx
mov    $0x1,%ecx
call   1030 <find_dev_in_directory@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    11ef <get_dev_t_geometry+0x9f>
mov    %r12,%r15
mov    0x2e27(%rip),%rax
mov    0x2e28(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1201 <get_dev_t_geometry+0xb1>
mov    %eax,%r12d
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r13,%rcx
mov    -0x30(%rbp),%r8
mov    -0x38(%rbp),%r9
call   1050 <get_dev_geometry@plt>
mov    %eax,%r15d
mov    %r12d,%edi
call   1040 <close@plt>
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc0(%rip),%rax
mov    (%rax),%r15d
mov    %r14,%rdi
call   1070 <perror@plt>
jmp    11ef <get_dev_t_geometry+0x9f>

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"/dev\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@errno = global i32 0
define i32 @get_dev_t_geometry(i32 %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
%19 = load i32, i32* @PATH_MAX
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %14
%22 = alloca i8, i64 %20
store i64 %20, i64* %15
%23 = load i32, i32* %8
%24 = call i32 @find_dev_in_directory(i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %22, i32 1)
store i32 %24, i32* %17
%25 = load i32, i32* %17
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %6
%28 = load i32, i32* %17
store i32 %28, i32* %7
store i32 1, i32* %18
br label %51
29: ; preds = %6
%30 = load i32, i32* @O_RDONLY
%31 = load i32, i32* @O_NONBLOCK
%32 = or i32 %30, %31
%33 = call i32 @open(i8* %22, i32 %32)
store i32 %33, i32* %16
%34 = load i32, i32* %16
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %29
%37 = load i32, i32* @errno
store i32 %37, i32* %17
%38 = call i32 @perror(i8* %22)
%39 = load i32, i32* %17
store i32 %39, i32* %7
store i32 1, i32* %18
br label %51
40: ; preds = %29
%41 = load i32, i32* %16
%42 = load i32*, i32** %9
%43 = load i32*, i32** %10
%44 = load i32*, i32** %11
%45 = load i32*, i32** %12
%46 = load i32*, i32** %13
%47 = call i32 @get_dev_geometry(i32 %41, i32* %42, i32* %43, i32* %44, i32* %45, i32* %46)
store i32 %47, i32* %17
%48 = load i32, i32* %16
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* %17
store i32 %50, i32* %7
store i32 1, i32* %18
br label %51
51: ; preds = %40, %36, %27
%52 = load i8*, i8** %14
%53 = load i32, i32* %7
ret i32 %53
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [5 x i8] c"/dev\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@errno = global i32 0
define i32 @get_dev_t_geometry(i32 %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = load i32, i32* @PATH_MAX
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = call i32 @find_dev_in_directory(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %9, i32 1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %6
%13 = load i32, i32* @O_RDONLY
%14 = load i32, i32* @O_NONBLOCK
%15 = or i32 %14, %13
%16 = call i32 @open(i8* %9, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* @errno
%20 = call i32 @perror(i8* %9)
br label %24
21: ; preds = %12
%22 = call i32 @get_dev_geometry(i32 %16, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5)
%23 = call i32 @close(i32 %16)
br label %24
24: ; preds = %6, %21, %18
%25 = phi i32 [ %19, %18 ], [ %22, %21 ], [ %10, %6 ]
ret i32 %25
}