#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 *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strlen(char const *);
int sysfs_fd_get_ll(int, unsigned long long *);
int devpath_to_ll(const char *dev_path, const char *entry,
                  unsigned long long *val) {
  char path[strlen(dev_path) + strlen(entry) + 2];
  int fd;
  int n;
  sprintf(path, "%s/%s", dev_path, entry);
  fd = open(path, O_RDONLY);
  if (fd < 0)
    return -1;
  n = sysfs_fd_get_ll(fd, val);
  close(fd);
  return n;
}


x86 assembly (clang, -O0):
<devpath_to_ll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rcx
mov    %rax,%rdx
lea    0x2(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x28(%rbp)
lea    0x11(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe4a(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x48(%rbp),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11ed <devpath_to_ll+0x9d>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1211 <devpath_to_ll+0xc1>
mov    -0x34(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <sysfs_fd_get_ll@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devpath_to_ll>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %rbx,%rax
add    $0x11,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
call   1070 <sprintf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11cd <devpath_to_ll+0x7d>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14,%rsi
call   1030 <sysfs_fd_get_ll@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1050 <close@plt>
mov    %r14d,%eax
jmp    11d2 <devpath_to_ll+0x82>
mov    $0xffffffff,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@O_RDONLY = global i32 0
define i32 @devpath_to_ll(i8* %0, i8* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64* %2, i64** %7
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
%15 = load i8*, i8** %6
%16 = call i64 @strlen(i8* %15)
%17 = add nsw i64 %14, %16
%18 = add nsw i64 %17, 2
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %8
%20 = alloca i8, i64 %18
store i64 %18, i64* %9
%21 = load i8*, i8** %5
%22 = load i8*, i8** %6
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* %20, i32 %24)
store i32 %25, i32* %10
%26 = load i32, i32* %10
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %3
store i32 -1, i32* %4
store i32 1, i32* %12
br label %36
29: ; preds = %3
%30 = load i32, i32* %10
%31 = load i64*, i64** %7
%32 = call i32 @sysfs_fd_get_ll(i32 %30, i64* %31)
store i32 %32, i32* %11
%33 = load i32, i32* %10
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %11
store i32 %35, i32* %4
store i32 1, i32* %12
br label %36
36: ; preds = %29, %28
%37 = load i8*, i8** %8
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@O_RDONLY = global i32 0
define i32 @devpath_to_ll(i8* %0, i8* %1, i64* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add i64 %4, 2
%7 = add i64 %6, %5
%8 = alloca i8, i64 %7
%9 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* %8, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = tail call i32 @sysfs_fd_get_ll(i32 %11, i64* %2)
%15 = tail call i32 @close(i32 %11)
br label %16
16: ; preds = %3, %13
%17 = phi i32 [ %14, %13 ], [ -1, %3 ]
ret i32 %17
}