#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 O_RDWR;
int O_SYNC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ioctl_OFF_LED(int);
int /*<<< orphan*/ ioctl_ON_LED(int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int Choice;
  int exitflag = 1;
  int file_desc;
  printf("################################ \n\r");
  printf("      Blink LED Application  \n\r");
  printf("################################ \n\r");
  file_desc = open("/dev/blink_Dev", O_RDWR | O_SYNC);
  if (file_desc < 0) {
    printf("Can't open device file: %s\n", "/dev/blink_Dev");
    exit(-1);
  }
  while (exitflag) {
    printf("************************************************ \n\r");
    printf("Press '1' to Start Blink LED TEST \n\r");
    printf("Press '0' to Stop Blink LED TEST \n\r");
    printf("************************************************ \n\r");
    scanf("%d", &Choice);
    printf("Choice  :: %d \n\r", Choice);
    if (Choice == 1) {
      ioctl_ON_LED(file_desc);
      exitflag = 1;
    } else if (0 == Choice) {
      ioctl_OFF_LED(file_desc);
      exitflag = 1;
    } else {
      exitflag = 0;
    }
  }
  close(file_desc);
  printf("################################ \n\r");
  printf("      Bye Blink LED Application  \n\r");
  printf("################################ \n\r");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11fa <main+0x8a>
lea    0xe71(%rip),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    11ff <main+0x8f>
cmpl   $0x0,-0xc(%rbp)
je     12b0 <main+0x140>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1280 <main+0x110>
mov    -0x10(%rbp),%edi
call   1030 <ioctl_ON_LED@plt>
movl   $0x1,-0xc(%rbp)
jmp    12ab <main+0x13b>
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jne    129f <main+0x12f>
mov    -0x10(%rbp),%edi
call   1090 <ioctl_OFF_LED@plt>
movl   $0x1,-0xc(%rbp)
jmp    12a6 <main+0x136>
movl   $0x0,-0xc(%rbp)
jmp    12ab <main+0x13b>
jmp    11ff <main+0x8f>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe7e(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e3d(%rip),%rax
mov    0x2e2e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe87(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     1293 <main+0x123>
mov    %eax,%ebp
lea    0xe9c(%rip),%rbx
lea    0xeee(%rip),%r15
lea    0xf0b(%rip),%r12
lea    0x4(%rsp),%r13
lea    0xf02(%rip),%r14
jmp    11f7 <main+0x87>
nop
mov    %ebp,%edi
call   1090 <ioctl_OFF_LED@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
je     11f0 <main+0x80>
cmp    $0x1,%eax
jne    1252 <main+0xe2>
mov    %ebp,%edi
call   1030 <ioctl_ON_LED@plt>
jmp    11f7 <main+0x87>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xda0(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb9(%rip),%rdi
lea    0xda3(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"################################ \0A\0D\00"
@.str.1 = [32 x i8] c" Blink LED Application \0A\0D\00"
@.str.2 = [15 x i8] c"/dev/blink_Dev\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.3 = [28 x i8] c"Can't open device file: %s\0A\00"
@.str.4 = [52 x i8] c"************************************************ \0A\0D\00"
@.str.5 = [37 x i8] c"Press '1' to Start Blink LED TEST \0A\0D\00"
@.str.6 = [36 x i8] c"Press '0' to Stop Blink LED TEST \0A\0D\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [17 x i8] c"Choice :: %d \0A\0D\00"
@.str.9 = [36 x i8] c" Bye Blink LED Application \0A\0D\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_SYNC
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %0
br label %18
18: ; preds = %42, %17
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %43
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %2)
%27 = load i32, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %21
%32 = load i32, i32* %4
%33 = call i32 @ioctl_ON_LED(i32 %32)
store i32 1, i32* %3
br label %42
34: ; preds = %21
%35 = load i32, i32* %2
%36 = icmp eq i32 0, %35
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %4
%39 = call i32 @ioctl_OFF_LED(i32 %38)
store i32 1, i32* %3
br label %41
40: ; preds = %34
store i32 0, i32* %3
br label %41
41: ; preds = %40, %37
br label %42
42: ; preds = %41, %31
br label %18
43: ; preds = %18
%44 = load i32, i32* %4
%45 = call i32 @close(i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0))
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"################################ \0A\0D\00"
@.str.1 = [32 x i8] c" Blink LED Application \0A\0D\00"
@.str.2 = [15 x i8] c"/dev/blink_Dev\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.3 = [28 x i8] c"Can't open device file: %s\0A\00"
@.str.4 = [52 x i8] c"************************************************ \0A\0D\00"
@.str.5 = [37 x i8] c"Press '1' to Start Blink LED TEST \0A\0D\00"
@.str.6 = [36 x i8] c"Press '0' to Stop Blink LED TEST \0A\0D\00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [17 x i8] c"Choice :: %d \0A\0D\00"
@.str.9 = [36 x i8] c" Bye Blink LED Application \0A\0D\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_SYNC
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %0, %27
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%20 = load i32, i32* %1
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %1
switch i32 %22, label %28 [
i32 1, label %23
i32 0, label %25
]
23: ; preds = %14
%24 = call i32 @ioctl_ON_LED(i32 %9)
br label %27
25: ; preds = %14
%26 = call i32 @ioctl_OFF_LED(i32 %9)
br label %27
27: ; preds = %25, %23
br label %14
28: ; preds = %14
%29 = call i32 @close(i32 %9)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
ret i32 0
}