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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int eng_lcdbacklight_test(int brightness) {
  int fd;
  int ret;
  char buffer[8];
  fd = open("/sys/class/leds/lcd-backlight/brightness", O_RDWR);
  if (fd < 0) {
    ;
    return -1;
  }
  memset(buffer, 0, sizeof(buffer));
  sprintf(buffer, "%d", brightness);
  ret = write(fd, buffer, strlen(buffer));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<eng_lcdbacklight_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1199 <eng_lcdbacklight_test+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <eng_lcdbacklight_test+0x93>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
lea    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe72(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eng_lcdbacklight_test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11c8 <eng_lcdbacklight_test+0x68>
mov    %eax,%ebp
mov    %rsp,%r15
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
lea    0xe89(%rip),%rsi
mov    %r15,%rdi
mov    %r14d,%edx
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11cd <eng_lcdbacklight_test+0x6d>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"/sys/class/leds/lcd-backlight/brightness\00"
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @eng_lcdbacklight_test(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8 x i8]
store i32 %0, i32* %3
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %25
12: ; preds = %1
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 8)
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%16 = load i32, i32* %3
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %4
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 %18, i8* %19, i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
store i32 0, i32* %2
br label %25
25: ; preds = %12, %11
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [41 x i8] c"/sys/class/leds/lcd-backlight/brightness\00"
@O_RDWR = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @eng_lcdbacklight_test(i32 %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = call i32 @memset(i8* %3, i32 0, i32 8)
%9 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%10 = call i32 @strlen(i8* %3)
%11 = call i32 @write(i32 %5, i8* %3, i32 %10)
%12 = call i32 @close(i32 %5)
br label %13
13: ; preds = %1, %7
%14 = phi i32 [ 0, %7 ], [ -1, %1 ]
ret i32 %14
}