#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*/ err(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int read_max_brightness() {
  int max_br = 0;
  FILE *f = fopen("/sys/class/backlight/acpi_video0"
                  "/max_brightness",
                  "r");
  if (f == NULL)
    err("can't open screen brightness file to write");
  if (fscanf(f, "%d", &max_br) < 1)
    err("can't write new brightness");
  fclose(f);
  return max_br;
}


x86 assembly (clang, -O0):
<read_max_brightness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xed3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117d <read_max_brightness+0x3d>
lea    0xeba(%rip),%rdi
call   1050 <err@plt>
mov    -0x10(%rbp),%rdi
lea    0xed5(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jge    11a6 <read_max_brightness+0x66>
lea    0xebf(%rip),%rdi
call   1050 <err@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_max_brightness>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xeac(%rip),%rdi
lea    0xed5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1174 <read_max_brightness+0x34>
lea    0xec3(%rip),%rdi
call   1050 <err@plt>
lea    0xee2(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <fscanf@plt>
test   %eax,%eax
jg     1198 <read_max_brightness+0x58>
lea    0xecd(%rip),%rdi
call   1050 <err@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [48 x i8] c"/sys/class/backlight/acpi_video0/max_brightness\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c"can't open screen brightness file to write\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [27 x i8] c"can't write new brightness\00"
define i32 @read_max_brightness() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 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 @err(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = load i32*, i32** %2
%10 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @err(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [48 x i8] c"/sys/class/backlight/acpi_video0/max_brightness\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [43 x i8] c"can't open screen brightness file to write\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [27 x i8] c"can't write new brightness\00"
define i32 @read_max_brightness() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @err(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @err(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = call i32 @fclose(i32* %3)
%14 = load i32, i32* %1
ret i32 %14
}