#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 /*<<< orphan*/ O_RDWR;
scalar_t__ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(unsigned char *, char *);
int /*<<< orphan*/ strlen(unsigned char *);
int write(int, unsigned char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  int err = -1;
  unsigned char value[4];
  if (argc != 2) {
    printf("should input led status after process\n");
    return -1;
  }
  if (atoi(argv[1])) {
    strcpy(value, "1");
  } else {
    strcpy(value, "0");
  }
  fd = open("/sys/class/leds/led_framework/brightness", O_RDWR);
  if (fd < 0) {
    printf("open file err\n");
    exit(-1);
  }
  err = write(fd, value, strlen(value));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bf <main+0x3f>
lea    0xe52(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <main+0xea>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
cmp    $0x0,%rax
je     11eb <main+0x6b>
lea    -0x1c(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11fb <main+0x7b>
lea    -0x1c(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xe20(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1233 <main+0xb3>
lea    0xe30(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x1c(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11f0 <main+0x70>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
test   %rax,%rax
lea    0xe66(%rip),%rax
lea    0xe5d(%rip),%rsi
cmove  %rax,%rsi
lea    0x4(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
lea    0xe43(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1209 <main+0x89>
mov    %eax,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    1201 <main+0x81>
lea    0xe44(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1d(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"should input led status after process\0A\00"
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [41 x i8] c"/sys/class/leds/led_framework/brightness\00"
@O_RDWR = global i32 0
@.str.4 = [15 x i8] c"open file err\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %41
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @atoi(i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %25
22: ; preds = %13
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %22, %19
%26 = load i32, i32* @O_RDWR
%27 = call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %25
%34 = load i32, i32* %6
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @write(i32 %34, i8* %35, i32 %37)
store i32 %38, i32* %7
%39 = load i32, i32* %6
%40 = call i32 @close(i32 %39)
store i32 0, i32* %3
br label %41
41: ; preds = %33, %11
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [41 x i8] c"/sys/class/leds/led_framework/brightness\00"
@O_RDWR = global i32 0
@str = [14 x i8] c"open file err\00"
@str.5 = [38 x i8] c"should input led status after process\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
br label %25
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @atoi(i8* %10)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%14 = call i32 @strcpy(i8* %4, i8* %13)
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %8
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %8
%22 = call i32 @strlen(i8* %4)
%23 = call i32 @write(i32 %16, i8* %4, i32 %22)
%24 = call i32 @close(i32 %16)
br label %25
25: ; preds = %21, %6
%26 = phi i32 [ -1, %6 ], [ 0, %21 ]
ret i32 %26
}