#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
void set_brightness(int brightness_value) {
  if (brightness_value > 180)
    brightness_value = 180;
  if (brightness_value < 30)
    brightness_value = 30;
  FILE *brightness_file;
  brightness_file = fopen("/sys/class/backlight/rpi_backlight/brightness", "w");
  fprintf(brightness_file, "%d", brightness_value);
  fclose(brightness_file);
}


x86 assembly (clang, -O0):
<set_brightness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xb4,-0x4(%rbp)
jle    114f <set_brightness+0x1f>
movl   $0xb4,-0x4(%rbp)
cmpl   $0x1e,-0x4(%rbp)
jge    1160 <set_brightness+0x30>
movl   $0x1e,-0x4(%rbp)
lea    0xe99(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xeab(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_brightness>:
push   %r14
push   %rbx
push   %rax
cmp    $0xb4,%edi
mov    $0xb4,%eax
cmovl  %edi,%eax
cmp    $0x1f,%eax
mov    $0x1e,%ebx
cmovge %eax,%ebx
lea    0xeac(%rip),%rdi
lea    0xed3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
lea    0xec6(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"/sys/class/backlight/rpi_backlight/brightness\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
define void @set_brightness(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, 180
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 180, i32* %2
br label %7
7: ; preds = %6, %1
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 30
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 30, i32* %2
br label %11
11: ; preds = %10, %7
%12 = call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %3
%13 = load i32*, i32** %3
%14 = load i32, i32* %2
%15 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32*, i32** %3
%17 = call i32 @fclose(i32* %16)
ret void
}

LLVM IR (-O2):
@.str = [46 x i8] c"/sys/class/backlight/rpi_backlight/brightness\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
define void @set_brightness(i32 %0) {
%2 = icmp slt i32 %0, 180
%3 = select i1 %2, i32 %0, i32 180
%4 = icmp sgt i32 %3, 30
%5 = select i1 %4, i32 %3, i32 30
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%8 = tail call i32 @fclose(i32* %6)
ret void
}