#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*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
char getchar();
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int sculltest;
  int code;
  char input;
  if ((sculltest = open("/dev/scull_kfifo", O_RDWR)) < 0) {
    printf("cannot open scull_kfifo!\n");
    exit(1);
  }
  if (lseek(sculltest, 0, SEEK_SET) == -1)
    printf("scull_kfifo: the module can not lseek!\n");
  for (; input != 'q'; getchar()) {
    printf("please input the command :");
    input = getchar();
    switch (input) {
    case '1':
      if ((code = ioctl(sculltest, _IO('k', 0), NULL)) < 0)
        printf("scull_kfifo: ioctl SCULL_KFIFO_SIZE error! code=%d \n", code);
      else
        printf("scull_kfifo: ioctl SCULL_KFIFO_SIZE ok! len=%d  \n", code);
      break;
    case '2':
      if ((code = ioctl(sculltest, _IO('k', 1), NULL)) < 0)
        printf("scull_kfifo: SCULL_KFIFO_RESET error! code=%d \n", code);
      else
        printf("scull_kfifo: SCULL_KFIFO_RESET ok! code=%d \n", code);
      break;
    case 'q':
      break;
    default:
      printf("scull_kfifo:  Invalid input ! only 1、2、q !\n");
    }
  }
  close(sculltest);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11c8 <main+0x48>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11f2 <main+0x72>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f7 <main+0x77>
movsbl -0xd(%rbp),%eax
cmp    $0x71,%eax
je     132e <main+0x1ae>
lea    0xe48(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x15(%rbp)
call   1030 <printf@plt>
mov    -0x15(%rbp),%al
call   1080 <getchar@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x31,%eax
je     1257 <main+0xd7>
jmp    1235 <main+0xb5>
mov    -0x14(%rbp),%eax
sub    $0x32,%eax
je     12af <main+0x12f>
jmp    1246 <main+0xc6>
mov    -0x14(%rbp),%eax
sub    $0x71,%eax
je     130a <main+0x18a>
jmp    130f <main+0x18f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x6b,%edi
xor    %esi,%esi
call   1040 <_IO@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1299 <main+0x119>
mov    -0xc(%rbp),%esi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12aa <main+0x12a>
mov    -0xc(%rbp),%esi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131d <main+0x19d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x6b,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    12f4 <main+0x174>
mov    -0xc(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1305 <main+0x185>
mov    -0xc(%rbp),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    131d <main+0x19d>
jmp    131d <main+0x19d>
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1322 <main+0x1a2>
mov    $0x0,%al
call   1080 <getchar@plt>
jmp    11f7 <main+0x77>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xe55(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
jns    11ca <main+0x3a>
lea    0xf8b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%ebp
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11ef <main+0x5f>
lea    0xf35(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1b(%rip),%rbx
lea    0xec6(%rip),%r15
lea    0xe5d(%rip),%r13
lea    0xee5(%rip),%r14
jmp    1247 <main+0xb7>
nopl   (%rax)
mov    $0x6b,%edi
mov    $0x1,%esi
call   1050 <_IO@plt>
mov    %ebp,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1070 <ioctl@plt>
test   %eax,%eax
js     129a <main+0x10a>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
cmp    $0x71,%r12b
je     12ac <main+0x11c>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    %eax,%r12d
movsbl %al,%eax
cmp    $0x71,%eax
je     123a <main+0xaa>
cmp    $0x32,%eax
je     1210 <main+0x80>
cmp    $0x31,%eax
jne    1290 <main+0x100>
mov    $0x6b,%edi
xor    %esi,%esi
call   1050 <_IO@plt>
mov    %ebp,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1070 <ioctl@plt>
test   %eax,%eax
js     12a3 <main+0x113>
mov    %r13,%rdi
jmp    1231 <main+0xa1>
nopl   (%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    123a <main+0xaa>
lea    0xdf2(%rip),%rdi
jmp    1231 <main+0xa1>
lea    0xd82(%rip),%rdi
jmp    1231 <main+0xa1>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"/dev/scull_kfifo\00"
@O_RDWR = global i32 0
@.str.1 = [26 x i8] c"cannot open scull_kfifo!\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [40 x i8] c"scull_kfifo: the module can not lseek!\0A\00"
@.str.3 = [27 x i8] c"please input the command :\00"
@.str.4 = [53 x i8] c"scull_kfifo: ioctl SCULL_KFIFO_SIZE error! code=%d \0A\00"
@.str.5 = [50 x i8] c"scull_kfifo: ioctl SCULL_KFIFO_SIZE ok! len=%d \0A\00"
@.str.6 = [48 x i8] c"scull_kfifo: SCULL_KFIFO_RESET error! code=%d \0A\00"
@.str.7 = [45 x i8] c"scull_kfifo: SCULL_KFIFO_RESET ok! code=%d \0A\00"
@.str.8 = [48 x i8] c"scull_kfifo: Invalid input ! only 1\E3\80\812\E3\80\81q !\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* %2
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @lseek(i32 %12, i32 0, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
br label %19
19: ; preds = %56, %18
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 113
br i1 %22, label %23, label %58
23: ; preds = %19
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%25 = call signext i8 (...) @getchar()
store i8 %25, i8* %4
%26 = load i8, i8* %4
%27 = sext i8 %26 to i32
switch i32 %27, label %53 [
i32 49, label %28
i32 50, label %40
i32 113, label %52
]
28: ; preds = %23
%29 = load i32, i32* %2
%30 = call i32 @_IO(i8 signext 107, i32 0)
%31 = call i32 @ioctl(i32 %29, i32 %30, i32* null)
store i32 %31, i32* %3
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* %3
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %34)
br label %39
36: ; preds = %28
%37 = load i32, i32* %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %33
br label %55
40: ; preds = %23
%41 = load i32, i32* %2
%42 = call i32 @_IO(i8 signext 107, i32 1)
%43 = call i32 @ioctl(i32 %41, i32 %42, i32* null)
store i32 %43, i32* %3
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* %3
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i32 %46)
br label %51
48: ; preds = %40
%49 = load i32, i32* %3
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %48, %45
br label %55
52: ; preds = %23
br label %55
53: ; preds = %23
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.8, i64 0, i64 0))
br label %55
55: ; preds = %53, %52, %51, %39
br label %56
56: ; preds = %55
%57 = call signext i8 (...) @getchar()
br label %19
58: ; preds = %19
%59 = load i32, i32* %2
%60 = call i32 @close(i32 %59)
%61 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [17 x i8] c"/dev/scull_kfifo\00"
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [27 x i8] c"please input the command :\00"
@.str.4 = [53 x i8] c"scull_kfifo: ioctl SCULL_KFIFO_SIZE error! code=%d \0A\00"
@.str.5 = [50 x i8] c"scull_kfifo: ioctl SCULL_KFIFO_SIZE ok! len=%d \0A\00"
@.str.6 = [48 x i8] c"scull_kfifo: SCULL_KFIFO_RESET error! code=%d \0A\00"
@.str.7 = [45 x i8] c"scull_kfifo: SCULL_KFIFO_RESET ok! code=%d \0A\00"
@str = [47 x i8] c"scull_kfifo: Invalid input ! only 1\E3\80\812\E3\80\81q !\00"
@str.9 = [39 x i8] c"scull_kfifo: the module can not lseek!\00"
@str.10 = [25 x i8] c"cannot open scull_kfifo!\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.10, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @lseek(i32 %2, i32 0, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.9, i64 0, i64 0))
br label %13
13: ; preds = %7, %11
br label %14
14: ; preds = %13, %36
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call signext i8 (...) @getchar()
%17 = sext i8 %16 to i32
switch i32 %17, label %34 [
i32 49, label %18
i32 50, label %26
i32 113, label %36
]
18: ; preds = %14
%19 = tail call i32 @_IO(i8 signext 107, i32 0)
%20 = tail call i32 @ioctl(i32 %2, i32 %19, i32* null)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %36
24: ; preds = %18
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0), i32 %20)
br label %36
26: ; preds = %14
%27 = tail call i32 @_IO(i8 signext 107, i32 1)
%28 = tail call i32 @ioctl(i32 %2, i32 %27, i32* null)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0), i32 %28)
br label %36
32: ; preds = %26
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i32 %28)
br label %36
34: ; preds = %14
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %14, %34, %24, %22, %32, %30
%37 = tail call signext i8 (...) @getchar()
%38 = icmp eq i8 %16, 113
br i1 %38, label %39, label %14
39: ; preds = %36
%40 = tail call i32 @close(i32 %2)
%41 = tail call i32 @exit(i32 0)
unreachable
}