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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int write(int, void *, int);
int write_brightness_values(uint8_t led_no, int value) {
  int fd, ret = 0;
  char buf[100];
  snprintf(buf, sizeof(buf),
           "/sys/class/leds"
           "/beaglebone:green:usr%d/brightness",
           led_no);
  fd = open(buf, O_WRONLY);
  if (fd < 0) {
    perror(" write trigger error\n");
    return -1;
  }
  ret = write(fd, (void *)&value, sizeof(value));
  if (ret <= 0) {
    printf("trigger value write error\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<write_brightness_values>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x64,%esi
lea    0xe85(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11b7 <write_brightness_values+0x67>
lea    0xe8c(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <write_brightness_values+0xa4>
mov    -0x10(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11ed <write_brightness_values+0x9d>
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <write_brightness_values+0xa4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_brightness_values>:
push   %rbx
sub    $0x80,%rsp
mov    %edi,%ecx
mov    %esi,0xc(%rsp)
lea    0xe9b(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1050 <snprintf@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11bf <write_brightness_values+0x6f>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jg     11b6 <write_brightness_values+0x66>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x80,%rsp
pop    %rbx
ret
lea    0xe6c(%rip),%rdi
call   1070 <perror@plt>
jmp    11b1 <write_brightness_values+0x61>

LLVM IR (-O0):
@.str = [50 x i8] c"/sys/class/leds/beaglebone:green:usr%d/brightness\00"
@O_WRONLY = global i32 0
@.str.1 = [22 x i8] c" write trigger error\0A\00"
@.str.2 = [27 x i8] c"trigger value write error\0A\00"
define i32 @write_brightness_values(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %7
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%10 = load i32, i32* %4
%11 = call i32 @snprintf(i8* %9, i32 100, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %28
19: ; preds = %2
%20 = load i32, i32* %6
%21 = bitcast i32* %5 to i8*
%22 = call i32 @write(i32 %20, i8* %21, i32 4)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %28
27: ; preds = %19
store i32 0, i32* %3
br label %28
28: ; preds = %27, %25, %17
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [50 x i8] c"/sys/class/leds/beaglebone:green:usr%d/brightness\00"
@O_WRONLY = global i32 0
@.str.1 = [22 x i8] c" write trigger error\0A\00"
@str = [26 x i8] c"trigger value write error\00"
define i32 @write_brightness_values(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca [100 x i8]
store i32 %1, i32* %3
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 100, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* %5, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %18
12: ; preds = %2
%13 = bitcast i32* %3 to i8*
%14 = call i32 @write(i32 %8, i8* %13, i32 4)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %12, %16, %10
%19 = phi i32 [ -1, %10 ], [ -1, %16 ], [ 0, %12 ]
ret i32 %19
}