#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, double *);
int /*<<< orphan*/ perror(char *);
double get_max_brightness(void) {
  double max_brightness;
  FILE *f = fopen("/sys/class/backlight/radeon_bl0/max_brightness", "r");
  if (f == NULL) {
    perror("get_max_brightness fopen()");
    exit(EXIT_FAILURE);
  }
  if (fscanf(f, "%lf", &max_brightness) != 1) {
    perror("get_max_brightness fscanf()");
    if (fclose(f) != 0) {
      perror("get_max_brightness fclose()");
    }
    exit(EXIT_FAILURE);
  }
  if (fclose(f) != 0) {
    perror("get_max_brightness fclose()");
    exit(EXIT_FAILURE);
  }
  return max_brightness;
}


x86 assembly (clang, -O0):
<get_max_brightness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1194 <get_max_brightness+0x44>
lea    0xeb0(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xead(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
je     11ea <get_max_brightness+0x9a>
lea    0xe98(%rip),%rdi
call   1060 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11dc <get_max_brightness+0x8c>
lea    0xe95(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1217 <get_max_brightness+0xc7>
lea    0xe68(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_max_brightness>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0xecc(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11d5 <get_max_brightness+0x85>
mov    %rax,%rbx
lea    0xed5(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11a2 <get_max_brightness+0x52>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    11bb <get_max_brightness+0x6b>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret
lea    0xea7(%rip),%rdi
call   1060 <perror@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
je     11c7 <get_max_brightness+0x77>
lea    0xeaa(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe55(%rip),%rdi
jmp    11c2 <get_max_brightness+0x72>

LLVM IR (-O0):
@.str = [47 x i8] c"/sys/class/backlight/radeon_bl0/max_brightness\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"get_max_brightness fopen()\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [28 x i8] c"get_max_brightness fscanf()\00"
@.str.5 = [28 x i8] c"get_max_brightness fclose()\00"
define double @get_max_brightness() {
%1 = alloca double
%2 = alloca i32*
%3 = call i32* @fopen(i8* getelementptr inbounds ([47 x i8], [47 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 %10
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %1)
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32*, i32** %2
%17 = call i64 @fclose(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %10
%25 = load i32*, i32** %2
%26 = call i64 @fclose(i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %24
%33 = load double, double* %1
ret double %33
}

LLVM IR (-O2):
@.str = [47 x i8] c"/sys/class/backlight/radeon_bl0/max_brightness\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"get_max_brightness fopen()\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%lf\00"
@.str.4 = [28 x i8] c"get_max_brightness fscanf()\00"
@.str.5 = [28 x i8] c"get_max_brightness fclose()\00"
define double @get_max_brightness() {
%1 = alloca double
%2 = bitcast double* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([47 x i8], [47 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 %9
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double* %1)
%11 = icmp eq i32 %10, 1
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%14 = call i64 @fclose(i32* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %9
%22 = call i64 @fclose(i32* %3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %21
%29 = load double, double* %1
ret double %29
}