#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 O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int open(char const *, int, int);
int /*<<< orphan*/ strlen(char const *);
int write(int, char const *, int /*<<< orphan*/);
int set_sysfs_str(const char *path, const char *val) {
  int fd;
  int bytes;
  fd = open(path, O_CREAT | O_RDWR | O_TRUNC, 0644);
  if (fd >= 0) {
    bytes = write(fd, val, strlen(val));
    close(fd);
    return 0;
  } else {
  }
  return -1;
}


x86 assembly (clang, -O0):
<set_sysfs_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    0x2e74(%rip),%rax
or     (%rax),%esi
mov    0x2e83(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11c2 <set_sysfs_str+0x82>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ce <set_sysfs_str+0x8e>
jmp    11c7 <set_sysfs_str+0x87>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_sysfs_str>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rcx
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %rsi,%rbx
mov    0x2e91(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
mov    $0x1a4,%edx
call   1060 <open@plt>
test   %eax,%eax
js     1192 <set_sysfs_str+0x52>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1197 <set_sysfs_str+0x57>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
define i32 @set_sysfs_str(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_RDWR
%11 = or i32 %9, %10
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = call i32 @open(i8* %8, i32 %13, i32 420)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp sge i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* %6
%19 = load i8*, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 %18, i8* %19, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = call i32 @close(i32 %23)
store i32 0, i32* %3
br label %27
25: ; preds = %2
br label %26
26: ; preds = %25
store i32 -1, i32* %3
br label %27
27: ; preds = %26, %17
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
define i32 @set_sysfs_str(i8* nocapture %0, i8* %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_RDWR
%5 = or i32 %4, %3
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* %0, i32 %7, i32 420)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = tail call i32 @strlen(i8* %1)
%12 = tail call i32 @write(i32 %8, i8* %1, i32 %11)
%13 = tail call i32 @close(i32 %8)
br label %14
14: ; preds = %2, %10
%15 = phi i32 [ 0, %10 ], [ -1, %2 ]
ret i32 %15
}