#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*/ path;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
int open_sysfs(const char *sys_pfx, const char *node, int flags) {
  extern int errno;
  int fd;
  char path[0x200];
  snprintf(path, sizeof(path), "%s%s", sys_pfx, node);
  fd = open(path, flags);
  if (fd < 0) {
    fprintf(stderr, "unable to open %s\n", path);
    abort();
  }
  return fd;
}


x86 assembly (clang, -O0):
<open_sysfs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x200,%esi
lea    0xe8f(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x220(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11b5 <open_sysfs+0x75>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    -0x220(%rbp),%rdx
lea    0xe5c(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_sysfs>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %edx,%ebx
mov    %rsi,%r8
mov    %rdi,%rcx
lea    0xea7(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x200,%esi
call   1040 <snprintf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <open@plt>
test   %eax,%eax
js     1182 <open_sysfs+0x42>
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    %rsp,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"unable to open %s\0A\00"
define i32 @open_sysfs(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [512 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = call i32 @snprintf(i8* %9, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%14 = load i32, i32* %6
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %3
%24 = load i32, i32* %7
ret i32 %24
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"unable to open %s\0A\00"
define i32 @open_sysfs(i8* %0, i8* %1, i32 %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 512, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%7 = call i32 @open(i8* %5, i32 %2)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%12 = call i32 (...) @abort()
unreachable
13: ; preds = %3
ret i32 %7
}