#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*/ close(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, unsigned char *, int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ write(int, char *, scalar_t__);
int main(int argc, char *argv[]) {
  int fd;
  if (2 > argc) {
    printf("\033[1;31m"
           "[USER-PART-ERROR] input parameters are not enough\n"
           "\033[m");
    goto _HINT;
  }
  fd = open("/dev/tacobuf", O_RDWR);
  if (fd < 0) {
    printf("\033[1;31m"
           "[USER-PART-ERROR] open device tacobuf failed\n"
           "\033[m");
    printf("\033[1;32m"
           "[USER-PART] 1) maybe you should insert kernel module first\n"
           "\033[m");
    printf("\033[1;32m"
           "[USER-PART] 2) maybe you should use sudo to execute this program\n"
           "\033[m");
    return -1;
  }
  if (0 == strcmp(argv[1], "read")) {
    unsigned char _ubuf[128];
    memset(_ubuf, 0, 128);
    if (0 > read(fd, _ubuf, 128)) {
      printf("\033[1;31m"
             "[USER-PART-ERROR] read data from tacobuf failed\n"
             "\033[m");
      close(fd);
      return -1;
    }
    printf("\033[1;33m"
           "[USER-PART] read data : %s\n"
           "\033[m",
           _ubuf);
  } else if (0 == strcmp(argv[1], "unlock")) {
    if (0 > write(fd, "ok", strlen("ok") + 1)) {
      printf("\033[1;31m"
             "[USER-PART-ERROR] write data to tacobuf failed\n"
             "\033[m");
      close(fd);
      return -1;
    }
    printf("\033[1;33m"
           "[USER-PART] unlock kernel\n"
           "\033[m");
  } else {
    goto _HINT;
  }
  close(fd);
  return 0;
_HINT:
  printf("\033[1;32m"
         "[USER-PART] action should be 'read' or 'unlock'\n"
         "\033[m");
  printf("\033[1;32m"
         "[USER-PART] sudo ./main read\n"
         "\033[m");
  printf("\033[1;32m"
         "[USER-PART] sudo ./main unlock\n"
         "\033[m");
  close(fd);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jle    11ba <main+0x3a>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1356 <main+0x1d6>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    0xe73(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1212 <main+0x92>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138f <main+0x20f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xef3(%rip),%rsi
call   1090 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12a5 <main+0x125>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1080 <read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    128b <main+0x10b>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138f <main+0x20f>
lea    -0xa0(%rbp),%rsi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1342 <main+0x1c2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xec6(%rip),%rsi
call   1090 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1338 <main+0x1b8>
mov    -0x14(%rbp),%eax
mov    %eax,-0xa4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <strlen@plt>
mov    -0xa4(%rbp),%edi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xe91(%rip),%rsi
call   1030 <write@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    1325 <main+0x1a5>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138f <main+0x20f>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    133d <main+0x1bd>
jmp    1356 <main+0x1d6>
jmp    1342 <main+0x1c2>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    138f <main+0x20f>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x88,%rsp
cmp    $0x1,%edi
jg     11c7 <main+0x57>
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1050(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x107d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1097(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    $0xffffffff,%eax
jmp    12b0 <main+0x140>
mov    %rsi,%rbx
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0xe63(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     123f <main+0xcf>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
lea    0xf24(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1270 <main+0x100>
mov    0x8(%rbx),%rdi
lea    0xf75(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    118c <main+0x1c>
lea    0xf67(%rip),%rsi
mov    $0x3,%edx
mov    %ebp,%edi
call   1030 <write@plt>
test   %rax,%rax
js     12c6 <main+0x156>
lea    0xf88(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12a7 <main+0x137>
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe2e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe66(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    12b0 <main+0x140>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1070 <read@plt>
test   %rax,%rax
js     12ba <main+0x14a>
lea    0xeb7(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe58(%rip),%rdi
jmp    11af <main+0x3f>
lea    0xeb7(%rip),%rdi
jmp    11af <main+0x3f>

LLVM IR (-O0):
@.str = [61 x i8] c"\1B[1;31m[USER-PART-ERROR] input parameters are not enough\0A\1B[m\00"
@.str.1 = [13 x i8] c"/dev/tacobuf\00"
@O_RDWR = global i32 0
@.str.2 = [56 x i8] c"\1B[1;31m[USER-PART-ERROR] open device tacobuf failed\0A\1B[m\00"
@.str.3 = [70 x i8] c"\1B[1;32m[USER-PART] 1) maybe you should insert kernel module first\0A\1B[m\00"
@.str.4 = [76 x i8] c"\1B[1;32m[USER-PART] 2) maybe you should use sudo to execute this program\0A\1B[m\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [59 x i8] c"\1B[1;31m[USER-PART-ERROR] read data from tacobuf failed\0A\1B[m\00"
@.str.7 = [38 x i8] c"\1B[1;33m[USER-PART] read data : %s\0A\1B[m\00"
@.str.8 = [7 x i8] c"unlock\00"
@.str.9 = [3 x i8] c"ok\00"
@.str.10 = [58 x i8] c"\1B[1;31m[USER-PART-ERROR] write data to tacobuf failed\0A\1B[m\00"
@.str.11 = [37 x i8] c"\1B[1;33m[USER-PART] unlock kernel\0A\1B[m\00"
@.str.12 = [59 x i8] c"\1B[1;32m[USER-PART] action should be 'read' or 'unlock'\0A\1B[m\00"
@.str.13 = [40 x i8] c"\1B[1;32m[USER-PART] sudo ./main read\0A\1B[m\00"
@.str.14 = [42 x i8] c"\1B[1;32m[USER-PART] sudo ./main unlock\0A\1B[m\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 2, %8
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
br label %64
12: ; preds = %2
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %70
21: ; preds = %12
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i64 0, %25
br i1 %26, label %27, label %41
27: ; preds = %21
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%29 = call i32 @memset(i8* %28, i32 0, i32 128)
%30 = load i32, i32* %6
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%32 = call i64 @read(i32 %30, i8* %31, i32 128)
%33 = icmp sgt i64 0, %32
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0))
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
store i32 -1, i32* %3
br label %70
38: ; preds = %27
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %39)
br label %61
41: ; preds = %21
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%46 = icmp eq i64 0, %45
br i1 %46, label %47, label %59
47: ; preds = %41
%48 = load i32, i32* %6
%49 = call i64 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%50 = add nsw i64 %49, 1
%51 = call i64 @write(i32 %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i64 %50)
%52 = icmp sgt i64 0, %51
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.10, i64 0, i64 0))
%55 = load i32, i32* %6
%56 = call i32 @close(i32 %55)
store i32 -1, i32* %3
br label %70
57: ; preds = %47
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
br label %60
59: ; preds = %41
br label %64
60: ; preds = %57
br label %61
61: ; preds = %60, %38
%62 = load i32, i32* %6
%63 = call i32 @close(i32 %62)
store i32 0, i32* %3
br label %70
64: ; preds = %59, %10
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.12, i64 0, i64 0))
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0))
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.14, i64 0, i64 0))
%68 = load i32, i32* %6
%69 = call i32 @close(i32 %68)
store i32 -1, i32* %3
br label %70
70: ; preds = %64, %61, %53, %34, %17
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [61 x i8] c"\1B[1;31m[USER-PART-ERROR] input parameters are not enough\0A\1B[m\00"
@.str.1 = [13 x i8] c"/dev/tacobuf\00"
@O_RDWR = global i32 0
@.str.2 = [56 x i8] c"\1B[1;31m[USER-PART-ERROR] open device tacobuf failed\0A\1B[m\00"
@.str.3 = [70 x i8] c"\1B[1;32m[USER-PART] 1) maybe you should insert kernel module first\0A\1B[m\00"
@.str.4 = [76 x i8] c"\1B[1;32m[USER-PART] 2) maybe you should use sudo to execute this program\0A\1B[m\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [59 x i8] c"\1B[1;31m[USER-PART-ERROR] read data from tacobuf failed\0A\1B[m\00"
@.str.7 = [38 x i8] c"\1B[1;33m[USER-PART] read data : %s\0A\1B[m\00"
@.str.8 = [7 x i8] c"unlock\00"
@.str.9 = [3 x i8] c"ok\00"
@.str.10 = [58 x i8] c"\1B[1;31m[USER-PART-ERROR] write data to tacobuf failed\0A\1B[m\00"
@.str.11 = [37 x i8] c"\1B[1;33m[USER-PART] unlock kernel\0A\1B[m\00"
@.str.12 = [59 x i8] c"\1B[1;32m[USER-PART] action should be 'read' or 'unlock'\0A\1B[m\00"
@.str.13 = [40 x i8] c"\1B[1;32m[USER-PART] sudo ./main read\0A\1B[m\00"
@.str.14 = [42 x i8] c"\1B[1;32m[USER-PART] sudo ./main unlock\0A\1B[m\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0))
br label %44
7: ; preds = %2
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @.str.4, i64 0, i64 0))
br label %50
15: ; preds = %7
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %15
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i32 0, i32 128)
%23 = call i64 @read(i32 %9, i8* %21, i32 128)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 @close(i32 %9)
br label %50
28: ; preds = %20
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %21)
br label %42
30: ; preds = %15
%31 = load i8*, i8** %16
%32 = tail call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %30
%35 = tail call i64 @write(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i64 3)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.10, i64 0, i64 0))
%39 = tail call i32 @close(i32 %9)
br label %50
40: ; preds = %34
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
br label %42
42: ; preds = %28, %40
%43 = call i32 @close(i32 %9)
br label %50
44: ; preds = %30, %5
%45 = phi i32 [ undef, %5 ], [ %9, %30 ]
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.12, i64 0, i64 0))
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0))
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.14, i64 0, i64 0))
%49 = tail call i32 @close(i32 %45)
br label %50
50: ; preds = %25, %44, %42, %37, %11
%51 = phi i32 [ -1, %44 ], [ -1, %11 ], [ 0, %42 ], [ -1, %37 ], [ -1, %25 ]
ret i32 %51
}