#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 *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ perror(char *);
void set_brightness(double brightness) {
  FILE *f = fopen("/sys/class/backlight/radeon_bl0/brightness", "w");
  if (f == NULL) {
    perror("set_brightness fopen()");
    exit(EXIT_FAILURE);
  }
  if (fprintf(f, "%.0f", brightness) < 0) {
    perror("set_brightness fprintf()");
    if (fclose(f) != 0) {
      perror("set_brightness fclose()");
    }
    exit(EXIT_FAILURE);
  }
  if (fclose(f) != 0) {
    perror("set_brightness fclose()");
  }
  return;
}


x86 assembly (clang, -O0):
<set_brightness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
lea    0xe9c(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <set_brightness+0x49>
lea    0xea7(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
lea    0xe9b(%rip),%rsi
call   1040 <fprintf@plt>
cmp    $0x0,%rax
jge    11f1 <set_brightness+0xa1>
lea    0xe8a(%rip),%rdi
call   1060 <perror@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     11e3 <set_brightness+0x93>
lea    0xe84(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1210 <set_brightness+0xc0>
lea    0xe57(%rip),%rdi
call   1060 <perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_brightness>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
lea    0xe9e(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11e7 <set_brightness+0x97>
mov    %rax,%rbx
lea    0xec7(%rip),%rsi
mov    %rax,%rdi
movsd  0x8(%rsp),%xmm0
call   1040 <fprintf@plt>
test   %rax,%rax
js     11a3 <set_brightness+0x53>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    11d6 <set_brightness+0x86>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe9f(%rip),%rdi
call   1060 <perror@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
je     11c8 <set_brightness+0x78>
lea    0xe9f(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe85(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <perror@plt>
lea    0xe3f(%rip),%rdi
jmp    11c3 <set_brightness+0x73>

LLVM IR (-O0):
@.str = [43 x i8] c"/sys/class/backlight/radeon_bl0/brightness\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [23 x i8] c"set_brightness fopen()\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"%.0f\00"
@.str.4 = [25 x i8] c"set_brightness fprintf()\00"
@.str.5 = [24 x i8] c"set_brightness fclose()\00"
define void @set_brightness(double %0) {
%2 = alloca double
%3 = alloca i32*
store double %0, double* %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = load double, double* %2
%14 = call i64 @fprintf(i32* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%18 = load i32*, i32** %3
%19 = call i64 @fclose(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %11
%27 = load i32*, i32** %3
%28 = call i64 @fclose(i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"/sys/class/backlight/radeon_bl0/brightness\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [23 x i8] c"set_brightness fopen()\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"%.0f\00"
@.str.4 = [25 x i8] c"set_brightness fprintf()\00"
@.str.5 = [24 x i8] c"set_brightness fclose()\00"
define void @set_brightness(double %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %1
%9 = tail call i64 @fprintf(i32* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), double %0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i64 @fclose(i32* %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %8
%21 = tail call i64 @fclose(i32* %2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
ret void
}