#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);
  if (driver == NULL) {
    return;
  }
  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)
cmpq   $0x0,-0x8(%rbp)
jne    1196 <set_backlight_from_stdin+0x36>
jmp    1228 <set_backlight_from_stdin+0xc8>
jmp    119b <set_backlight_from_stdin+0x3b>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x15(%rbp)
je     11c3 <set_backlight_from_stdin+0x63>
mov    0x2e37(%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    11d3 <set_backlight_from_stdin+0x73>
jmp    121f <set_backlight_from_stdin+0xbf>
lea    0xe26(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%eax
je     121a <set_backlight_from_stdin+0xba>
cmpl   $0x0,-0x10(%rbp)
jle    121a <set_backlight_from_stdin+0xba>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     121a <set_backlight_from_stdin+0xba>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1080 <set_backlight@plt>
jmp    119b <set_backlight_from_stdin+0x3b>
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>
test   %r12,%r12
je     11e5 <set_backlight_from_stdin+0x85>
mov    %eax,%ebp
mov    0x2e5d(%rip),%r13
lea    0x4(%rsp),%r15
mov    0x2e49(%rip),%r14
jmp    11a4 <set_backlight_from_stdin+0x44>
nopl   0x0(%rax)
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
%8 = load i8*, i8** %1
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
br label %42
11: ; preds = %0
br label %12
12: ; preds = %38, %11
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* @stdin
%17 = call i32 @feof(i32 %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br label %20
20: ; preds = %15, %12
%21 = phi i1 [ false, %12 ], [ %19, %15 ]
br i1 %21, label %22, label %39
22: ; preds = %20
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 %23, i32* %2
%24 = load i32, i32* %2
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %38
27: ; preds = %22
%28 = load i32, i32* %3
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i32, i32* %3
%32 = load i32, i32* %4
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i8*, i8** %1
%36 = load i32, i32* %3
%37 = call i32 @set_backlight(i8* %35, i32 %36)
br label %38
38: ; preds = %34, %30, %27, %22
br label %12
39: ; preds = %20
%40 = load i8*, i8** %1
%41 = call i32 @free(i8* %40)
br label %42
42: ; preds = %39, %10
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)
%5 = icmp eq i8* %2, null
br i1 %5, label %25, label %6
6: ; preds = %0, %21
%7 = load i32, i32* @stdin
%8 = call i32 @feof(i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %6
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
%14 = load i32, i32* %1
%15 = icmp slt i32 %14, 1
%16 = select i1 %13, i1 true, i1 %15
%17 = icmp sgt i32 %14, %4
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %21, label %19
19: ; preds = %10
%20 = call i32 @set_backlight(i8* %2, i32 %14)
br label %21
21: ; preds = %19, %10
%22 = icmp eq i32 %11, 0
br i1 %22, label %23, label %6
23: ; preds = %21, %6
%24 = call i32 @free(i8* %2)
br label %25
25: ; preds = %0, %23
ret void
}