#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 */

/* Variables and functions */
int EOF;
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *get_driver();
int read_max_backlight(char *);
int scanf(char *, int *);
int /*<<< orphan*/ set_backlight(char *, int);
int /*<<< orphan*/ stdin;
void set_backlight_from_stdin() {
  char *driver = get_driver();
  int ok = 1, value;
  int max_value = read_max_backlight(driver);
  while (ok && !feof(stdin)) {
    ok = scanf("%d", &value);
    if (ok != EOF && value > 0 && value <= max_value) {
      set_backlight(driver, value);
    }
  }
  free(driver);
}


x86 assembly (clang, -O0):
<set_backlight_from_stdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <get_driver@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <read_max_backlight@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x15(%rbp)
je     11ae <set_backlight_from_stdin+0x4e>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11be <set_backlight_from_stdin+0x5e>
jmp    120a <set_backlight_from_stdin+0xaa>
lea    0xe3b(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e05(%rip),%rcx
cmp    (%rcx),%eax
je     1205 <set_backlight_from_stdin+0xa5>
cmpl   $0x0,-0x10(%rbp)
jle    1205 <set_backlight_from_stdin+0xa5>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1205 <set_backlight_from_stdin+0xa5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1080 <set_backlight@plt>
jmp    1186 <set_backlight_from_stdin+0x26>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_backlight_from_stdin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <get_driver@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <read_max_backlight@plt>
mov    %eax,%ebp
mov    0x2e62(%rip),%r13
lea    0x4(%rsp),%r15
mov    0x2e4e(%rip),%r14
jmp    11a4 <set_backlight_from_stdin+0x44>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %ebx,%ebx
je     11dd <set_backlight_from_stdin+0x7d>
mov    0x0(%r13),%edi
call   1050 <feof@plt>
test   %eax,%eax
jne    11dd <set_backlight_from_stdin+0x7d>
lea    0xe48(%rip),%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    %eax,%ebx
cmp    (%r14),%eax
je     11a0 <set_backlight_from_stdin+0x40>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    11a0 <set_backlight_from_stdin+0x40>
cmp    %ebp,%esi
jg     11a0 <set_backlight_from_stdin+0x40>
mov    %r12,%rdi
call   1080 <set_backlight@plt>
jmp    11a0 <set_backlight_from_stdin+0x40>
mov    %r12,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
@EOF = global i32 0
define void @set_backlight_from_stdin() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i8* (...) @get_driver()
store i8* %5, i8** %1
store i32 1, i32* %2
%6 = load i8*, i8** %1
%7 = call i32 @read_max_backlight(i8* %6)
store i32 %7, i32* %4
br label %8
8: ; preds = %34, %0
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* @stdin
%13 = call i32 @feof(i32 %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br label %16
16: ; preds = %11, %8
%17 = phi i1 [ false, %8 ], [ %15, %11 ]
br i1 %17, label %18, label %35
18: ; preds = %16
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 %19, i32* %2
%20 = load i32, i32* %2
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %18
%24 = load i32, i32* %3
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = icmp sle i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i8*, i8** %1
%32 = load i32, i32* %3
%33 = call i32 @set_backlight(i8* %31, i32 %32)
br label %34
34: ; preds = %30, %26, %23, %18
br label %8
35: ; preds = %16
%36 = load i8*, i8** %1
%37 = call i32 @free(i8* %36)
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
@EOF = global i32 0
define void @set_backlight_from_stdin() {
%1 = alloca i32
%2 = tail call i8* (...) @get_driver()
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 @read_max_backlight(i8* %2)
br label %5
5: ; preds = %0, %20
%6 = load i32, i32* @stdin
%7 = call i32 @feof(i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %5
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 1
%15 = select i1 %12, i1 true, i1 %14
%16 = icmp sgt i32 %13, %4
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %20, label %18
18: ; preds = %9
%19 = call i32 @set_backlight(i8* %2, i32 %13)
br label %20
20: ; preds = %18, %9
%21 = icmp eq i32 %10, 0
br i1 %21, label %22, label %5
22: ; preds = %20, %5
%23 = call i32 @free(i8* %2)
ret void
}