#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*/ F_OK;
int access(char *, int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int input;
  FILE *fp;
  if (argc != 2) {
    printf("Expected an integer argument.\n");
    return 1;
  }
  input = atoi(argv[1]);
  if (input <= 0) {
    printf("Input is out of bounds [%d]\n", input);
    return 1;
  }
  if (access("/sys/class/backlight/intel_backlight/brightness", F_OK) == -1) {
    printf("Brightness file does not exist\n");
    return 1;
  }
  fp = fopen("/sys/class/backlight/intel_backlight/brightness", "w");
  if (fp == NULL) {
    printf("Failed to open brightness file\n");
    return 1;
  }
  if (fprintf(fp, "%d", input) < 1) {
    printf("Failed to write to brightness file\n");
    fclose(fp);
    return 1;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119a <main+0x3a>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1294 <main+0x134>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     11d1 <main+0x71>
mov    -0x14(%rbp),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1294 <main+0x134>
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
jne    1209 <main+0xa9>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1294 <main+0x134>
lea    0xe2c(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1245 <main+0xe5>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1294 <main+0x134>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
cmp    $0x1,%eax
jge    1284 <main+0x124>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1294 <main+0x134>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11de <main+0x6e>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    11ec <main+0x7c>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     11fe <main+0x8e>
lea    0xe74(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1207 <main+0x97>
mov    %rax,%r14
lea    0xe8b(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1060 <fprintf@plt>
test   %eax,%eax
jle    1210 <main+0xa0>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1229 <main+0xb9>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
jmp    1224 <main+0xb4>
lea    0xe0d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1224 <main+0xb4>
lea    0xe8f(%rip),%rdi
jmp    11e5 <main+0x75>
lea    0xe67(%rip),%rdi
jmp    11e5 <main+0x75>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Expected an integer argument.\0A\00"
@.str.1 = [29 x i8] c"Input is out of bounds [%d]\0A\00"
@.str.2 = [48 x i8] c"/sys/class/backlight/intel_backlight/brightness\00"
@F_OK = global i32 0
@.str.3 = [32 x i8] c"Brightness file does not exist\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [32 x i8] c"Failed to open brightness file\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [36 x i8] c"Failed to write to brightness file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %46
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %20)
store i32 1, i32* %3
br label %46
22: ; preds = %12
%23 = load i32, i32* @F_OK
%24 = call i32 @access(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %46
28: ; preds = %22
%29 = call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %29, i32** %7
%30 = load i32*, i32** %7
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %46
34: ; preds = %28
%35 = load i32*, i32** %7
%36 = load i32, i32* %6
%37 = call i32 @fprintf(i32* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %36)
%38 = icmp slt i32 %37, 1
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
%41 = load i32*, i32** %7
%42 = call i32 @fclose(i32* %41)
store i32 1, i32* %3
br label %46
43: ; preds = %34
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
store i32 0, i32* %3
br label %46
46: ; preds = %43, %39, %32, %26, %19, %10
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str.1 = [29 x i8] c"Input is out of bounds [%d]\0A\00"
@.str.2 = [48 x i8] c"/sys/class/backlight/intel_backlight/brightness\00"
@F_OK = global i32 0
@.str.4 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"%d\00"
@str = [35 x i8] c"Failed to write to brightness file\00"
@str.8 = [31 x i8] c"Failed to open brightness file\00"
@str.9 = [31 x i8] c"Brightness file does not exist\00"
@str.10 = [30 x i8] c"Expected an integer argument.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.10, i64 0, i64 0))
br label %32
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %32
13: ; preds = %6
%14 = load i32, i32* @F_OK
%15 = tail call i32 @access(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.9, i64 0, i64 0))
br label %32
19: ; preds = %13
%20 = tail call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.8, i64 0, i64 0))
br label %32
24: ; preds = %19
%25 = tail call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %9)
%26 = icmp slt i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%29 = tail call i32 @fclose(i32* %20)
br label %32
30: ; preds = %24
%31 = tail call i32 @fclose(i32* %20)
br label %32
32: ; preds = %30, %27, %22, %17, %11, %4
%33 = phi i32 [ 1, %4 ], [ 1, %11 ], [ 1, %17 ], [ 1, %22 ], [ 1, %27 ], [ 0, %30 ]
ret i32 %33
}