#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ lcdSetBrightness(int);
scalar_t__ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ uartClose();
int /*<<< orphan*/ uartInit();
int main(int argc, char *argv[]) {
  int d;
  if ((argc == 2) && (sscanf(argv[1], "%d", &d) > 0)) {
    if ((d < 0) || (d > 255)) {
      fprintf(stderr, "invalid brightness value\n");
      return 2;
    }
  } else {
    fprintf(stderr, "usage: %s <0..255>\n", argv[0]);
    return 1;
  }
  (void)uartInit();
  lcdSetBrightness(d);
  fprintf(stdout, "brightness set to %d / 255\n", d);
  uartClose();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11d1 <main+0x81>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe81(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jle    11d1 <main+0x81>
cmpl   $0x0,-0x14(%rbp)
jl     11a9 <main+0x59>
cmpl   $0xff,-0x14(%rbp)
jle    11cc <main+0x7c>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1232 <main+0xe2>
jmp    11fb <main+0xab>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1232 <main+0xe2>
mov    $0x0,%al
call   1040 <uartInit@plt>
mov    -0x14(%rbp),%edi
call   1030 <lcdSetBrightness@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1050 <uartClose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    119f <main+0x4f>
mov    0x8(%rbx),%rdi
lea    0xe98(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1070 <sscanf@plt>
test   %rax,%rax
jle    119f <main+0x4f>
cmpl   $0x100,0xc(%rsp)
jb     11c6 <main+0x76>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%ebx
jmp    11be <main+0x6e>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe6b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <uartInit@plt>
mov    0xc(%rsp),%edi
call   1030 <lcdSetBrightness@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    0xc(%rsp),%edx
lea    0xe45(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1050 <uartClose@plt>
jmp    11be <main+0x6e>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"invalid brightness value\0A\00"
@.str.2 = [20 x i8] c"usage: %s <0..255>\0A\00"
@stdout = global i32 0
@.str.3 = [28 x i8] c"brightness set to %d / 255\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %25
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %9
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 255
br i1 %20, label %21, label %24
21: ; preds = %18, %15
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %39
24: ; preds = %18
br label %31
25: ; preds = %9, %2
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 1, i32* %3
br label %39
31: ; preds = %24
%32 = call i32 (...) @uartInit()
%33 = load i32, i32* %6
%34 = call i32 @lcdSetBrightness(i32 %33)
%35 = load i32, i32* @stdout
%36 = load i32, i32* %6
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = call i32 (...) @uartClose()
store i32 0, i32* %3
br label %39
39: ; preds = %31, %25, %21
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"invalid brightness value\0A\00"
@.str.2 = [20 x i8] c"usage: %s <0..255>\0A\00"
@stdout = global i32 0
@.str.3 = [28 x i8] c"brightness set to %d / 255\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %17
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i64 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %6
%12 = load i32, i32* %3
%13 = icmp ugt i32 %12, 255
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %29
17: ; preds = %6, %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %29
21: ; preds = %11
%22 = call i32 (...) @uartInit()
%23 = load i32, i32* %3
%24 = call i32 @lcdSetBrightness(i32 %23)
%25 = load i32, i32* @stdout
%26 = load i32, i32* %3
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = call i32 (...) @uartClose()
br label %29
29: ; preds = %21, %17, %14
%30 = phi i32 [ 2, %14 ], [ 0, %21 ], [ 1, %17 ]
ret i32 %30
}