#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 */
struct mdinfo {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ close(int);
int sysfs_fd_get_ll(int, unsigned long long *);
int sysfs_get_fd(struct mdinfo *, struct mdinfo *, char *);
int sysfs_get_ll(struct mdinfo *sra, struct mdinfo *dev, char *name,
                 unsigned long long *val) {
  int n;
  int fd;
  fd = sysfs_get_fd(sra, dev, name);
  if (fd < 0)
    return -1;
  n = sysfs_fd_get_ll(fd, val);
  close(fd);
  return n;
}


x86 assembly (clang, -O0):
<sysfs_get_ll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <sysfs_get_fd@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    1172 <sysfs_get_ll+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    118f <sysfs_get_ll+0x5f>
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <sysfs_fd_get_ll@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%edi
call   1040 <close@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfs_get_ll>:
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%rbx
call   1050 <sysfs_get_fd@plt>
test   %eax,%eax
js     1158 <sysfs_get_ll+0x28>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1030 <sysfs_fd_get_ll@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
jmp    115d <sysfs_get_ll+0x2d>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.mdinfo = type { i32 }
define i32 @sysfs_get_ll(%struct.mdinfo* %0, %struct.mdinfo* %1, i8* %2, i64* %3) {
%5 = alloca i32
%6 = alloca %struct.mdinfo*
%7 = alloca %struct.mdinfo*
%8 = alloca i8*
%9 = alloca i64*
%10 = alloca i32
%11 = alloca i32
store %struct.mdinfo* %0, %struct.mdinfo** %6
store %struct.mdinfo* %1, %struct.mdinfo** %7
store i8* %2, i8** %8
store i64* %3, i64** %9
%12 = load %struct.mdinfo*, %struct.mdinfo** %6
%13 = load %struct.mdinfo*, %struct.mdinfo** %7
%14 = load i8*, i8** %8
%15 = call i32 @sysfs_get_fd(%struct.mdinfo* %12, %struct.mdinfo* %13, i8* %14)
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 -1, i32* %5
br label %26
19: ; preds = %4
%20 = load i32, i32* %11
%21 = load i64*, i64** %9
%22 = call i32 @sysfs_fd_get_ll(i32 %20, i64* %21)
store i32 %22, i32* %10
%23 = load i32, i32* %11
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %10
store i32 %25, i32* %5
br label %26
26: ; preds = %19, %18
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
%struct.mdinfo = type { i32 }
define i32 @sysfs_get_ll(%struct.mdinfo* %0, %struct.mdinfo* %1, i8* %2, i64* %3) {
%5 = tail call i32 @sysfs_get_fd(%struct.mdinfo* %0, %struct.mdinfo* %1, i8* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @sysfs_fd_get_ll(i32 %5, i64* %3)
%9 = tail call i32 @close(i32 %5)
br label %10
10: ; preds = %4, %7
%11 = phi i32 [ %8, %7 ], [ -1, %4 ]
ret i32 %11
}