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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main() {
  FILE *f = fopen("/sys/class/leds/smc::kbd_backlight/brightness", "wb");
  if (f == NULL) {
    printf("Can't open brightness.\n");
    return 1;
  }
  if (fwrite("0\n", 1, 2, f) != 2) {
    printf("Can't write brightness.\n");
    return 1;
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xed1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1189 <main+0x49>
lea    0xeb9(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d4 <main+0x94>
mov    -0x10(%rbp),%rcx
lea    0xeb5(%rip),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1060 <fwrite@plt>
cmp    $0x2,%eax
je     11c4 <main+0x84>
lea    0xe99(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d4 <main+0x94>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
lea    0xedd(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118d <main+0x4d>
mov    %rax,%rbx
lea    0xecc(%rip),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
cmp    $0x2,%eax
jne    11a0 <main+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebp,%ebp
jmp    11ac <main+0x6c>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
jmp    11ac <main+0x6c>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"/sys/class/leds/smc::kbd_backlight/brightness\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [24 x i8] c"Can't open brightness.\0A\00"
@.str.3 = [3 x i8] c"0\0A\00"
@.str.4 = [25 x i8] c"Can't write brightness.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %17
8: ; preds = %0
%9 = load i32*, i32** %2
%10 = call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 2, i32* %9)
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %17
14: ; preds = %8
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
store i32 0, i32* %1
br label %17
17: ; preds = %14, %12, %6
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [46 x i8] c"/sys/class/leds/smc::kbd_backlight/brightness\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.3 = [3 x i8] c"0\0A\00"
@str = [24 x i8] c"Can't write brightness.\00"
@str.5 = [23 x i8] c"Can't open brightness.\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
br label %12
5: ; preds = %0
%6 = tail call i32 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 2, i32* %1)
%7 = icmp eq i32 %6, 2
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %12
10: ; preds = %5
%11 = tail call i32 @fclose(i32* %1)
br label %12
12: ; preds = %10, %8, %3
%13 = phi i32 [ 1, %3 ], [ 1, %8 ], [ 0, %10 ]
ret i32 %13
}