#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;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ librpip_sysfs_node_file_open(int, int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ write(int, char *, int);
uint32_t librpip_sysfs_node_file_set_int(uint32_t sysfsid, uint32_t fileid,
                                         int value) {
  int fd, result;
  char buf[20];
  result = 0;
  sprintf(buf, "%u", value);
  if (librpip_sysfs_node_file_open(sysfsid, fileid, O_RDWR, &fd)) {
    if (write(fd, buf, sizeof(buf))) {
      result = 1;
    }
    close(fd);
  }
  return result;
}


x86 assembly (clang, -O0):
<librpip_sysfs_node_file_set_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe9a(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
call   1050 <librpip_sysfs_node_file_open@plt>
cmp    $0x0,%rax
je     11b7 <librpip_sysfs_node_file_set_int+0x77>
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
je     11af <librpip_sysfs_node_file_set_int+0x6f>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<librpip_sysfs_node_file_set_int>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xeaf(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1060 <sprintf@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <librpip_sysfs_node_file_open@plt>
test   %rax,%rax
je     119d <librpip_sysfs_node_file_set_int+0x5d>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x14,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    0xc(%rsp),%edi
call   1040 <close@plt>
jmp    119f <librpip_sysfs_node_file_set_int+0x5f>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@O_RDWR = global i32 0
define i32 @librpip_sysfs_node_file_set_int(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [20 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%11 = load i32, i32* %6
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = load i32, i32* @O_RDWR
%16 = call i64 @librpip_sysfs_node_file_open(i32 %13, i32 %14, i32 %15, i32* %7)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %3
%19 = load i32, i32* %7
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%21 = call i64 @write(i32 %19, i8* %20, i32 20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %18
store i32 1, i32* %8
br label %24
24: ; preds = %23, %18
%25 = load i32, i32* %7
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %24, %3
%28 = load i32, i32* %8
ret i32 %28
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@O_RDWR = global i32 0
define i32 @librpip_sysfs_node_file_set_int(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %2)
%9 = load i32, i32* @O_RDWR
%10 = call i64 @librpip_sysfs_node_file_open(i32 %0, i32 %1, i32 %9, i32* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %3
%13 = load i32, i32* %4
%14 = call i64 @write(i32 %13, i8* %7, i32 20)
%15 = icmp ne i64 %14, 0
%16 = zext i1 %15 to i32
%17 = load i32, i32* %4
%18 = call i32 @close(i32 %17)
br label %19
19: ; preds = %12, %3
%20 = phi i32 [ %16, %12 ], [ 0, %3 ]
ret i32 %20
}