#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_str(int, char *, int);
int sysfs_get_fd(struct mdinfo *, struct mdinfo *, char *);
int sysfs_get_str(struct mdinfo *sra, struct mdinfo *dev, char *name, char *val,
                  int size) {
  int n;
  int fd;
  fd = sysfs_get_fd(sra, dev, name);
  if (fd < 0)
    return -1;
  n = sysfs_fd_get_str(fd, val, size);
  close(fd);
  return n;
}


x86 assembly (clang, -O0):
<sysfs_get_str>:
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    %r8d,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <sysfs_get_fd@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1176 <sysfs_get_str+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <sysfs_get_str+0x66>
mov    -0x34(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1050 <sysfs_fd_get_str@plt>
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%edi
call   1030 <close@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfs_get_str>:
push   %rbp
push   %r14
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%rbx
call   1040 <sysfs_get_fd@plt>
test   %eax,%eax
js     115f <sysfs_get_str+0x2f>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <sysfs_fd_get_str@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
jmp    1164 <sysfs_get_str+0x34>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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