#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ librpip_sysfs_node_file_open(int, int, int /*<<< orphan*/, int *);
scalar_t__ write(int, char *, int);
uint32_t librpip_sysfs_node_file_set_str(uint32_t sysfsid, uint32_t fileid,
                                         char *value, uint32_t len) {
  int fd, result;
  result = 0;
  if (librpip_sysfs_node_file_open(sysfsid, fileid, O_RDWR, &fd)) {
    if (write(fd, value, len)) {
      result = 1;
    }
    close(fd);
  }
  return result;
}


x86 assembly (clang, -O0):
<librpip_sysfs_node_file_set_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
call   1050 <librpip_sysfs_node_file_open@plt>
cmp    $0x0,%rax
je     1196 <librpip_sysfs_node_file_set_str+0x66>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
cmp    $0x0,%rax
je     118e <librpip_sysfs_node_file_set_str+0x5e>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<librpip_sysfs_node_file_set_str>:
push   %rbp
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    0x2ea9(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
call   1050 <librpip_sysfs_node_file_open@plt>
test   %rax,%rax
je     1171 <librpip_sysfs_node_file_set_str+0x41>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    0x4(%rsp),%edi
call   1040 <close@plt>
jmp    1173 <librpip_sysfs_node_file_set_str+0x43>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@O_RDWR = global i32 0
define i32 @librpip_sysfs_node_file_set_str(i32 %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = load i32, i32* @O_RDWR
%8 = call i64 @librpip_sysfs_node_file_open(i32 %0, i32 %1, i32 %7, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %4
%11 = load i32, i32* %5
%12 = call i64 @write(i32 %11, i8* %2, i32 %3)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i32
%15 = load i32, i32* %5
%16 = call i32 @close(i32 %15)
br label %17
17: ; preds = %10, %4
%18 = phi i32 [ %14, %10 ], [ 0, %4 ]
ret i32 %18
}