#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 */
char EOF;
int /*<<< orphan*/ O_RDWR;
unsigned long _IO(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char getopt(int, char **, char *);
int ioctl(int, unsigned long, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int fd = 0;
  int ret = 0;
  unsigned long cmd = 0;
  char c = 0;
  if (argc < 2) {
    usage(argv[0]);
    return -1;
  }
  fd = open("/dev/"
            "fault",
            O_RDWR);
  if (fd < 0) {
    fprintf(stderr, "open char dev failed\n");
    return fd;
  }
  while ((c = getopt(argc, argv, "hnpslamg")) != EOF)
    switch (c) {
    case 'h':
      usage(argv[0]);
      break;
    case 'n':
      cmd = _IO(0xf5, 0);
      break;
    case 'p':
      cmd = _IO(0xf5, 1);
      break;
    case 's':
      cmd = _IO(0xf5, 2);
      break;
    case 'l':
      cmd = _IO(0xf5, 3);
      break;
    case 'a':
      cmd = _IO(0xf5, 4);
      break;
    case 'm':
      cmd = _IO(0xf5, 5);
      break;
    case 'g':
      cmd = _IO(0xf5, 6);
      break;
    case '?':
      fprintf(stderr, "unsupported param\n");
      break;
    }
  ret = ioctl(fd, cmd, 0);
  if (ret) {
    fprintf(stderr, "ioctl failed %d\n", ret);
    goto out;
  }
out:
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c2 <main+0x52>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    137f <main+0x20f>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
lea    0xf02(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1206 <main+0x96>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xeeb(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    137f <main+0x20f>
jmp    120b <main+0x9b>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xedc(%rip),%rdx
call   1090 <getopt@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2db5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1332 <main+0x1c2>
movsbl -0x21(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x34,%eax
ja     132d <main+0x1bd>
mov    -0x30(%rbp),%rax
lea    0xda9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
jmp    132d <main+0x1bd>
mov    $0xf5,%edi
xor    %esi,%esi
call   1030 <_IO@plt>
mov    %rax,-0x20(%rbp)
jmp    132d <main+0x1bd>
mov    $0xf5,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
mov    %rax,-0x20(%rbp)
jmp    132d <main+0x1bd>
mov    $0xf5,%edi
mov    $0x2,%esi
call   1030 <_IO@plt>
mov    %rax,-0x20(%rbp)
jmp    132d <main+0x1bd>
mov    $0xf5,%edi
mov    $0x3,%esi
call   1030 <_IO@plt>
mov    %rax,-0x20(%rbp)
jmp    132d <main+0x1bd>
mov    $0xf5,%edi
mov    $0x4,%esi
call   1030 <_IO@plt>
mov    %rax,-0x20(%rbp)
jmp    132d <main+0x1bd>
mov    $0xf5,%edi
mov    $0x5,%esi
call   1030 <_IO@plt>
mov    %rax,-0x20(%rbp)
jmp    132d <main+0x1bd>
mov    $0xf5,%edi
mov    $0x6,%esi
call   1030 <_IO@plt>
mov    %rax,-0x20(%rbp)
jmp    132d <main+0x1bd>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    120b <main+0x9b>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     136c <main+0x1fc>
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1371 <main+0x201>
jmp    1371 <main+0x201>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1196 <main+0x26>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    $0xffffffff,%r14d
jmp    122b <main+0xbb>
mov    %edi,%ebp
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xf2c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1214 <main+0xa4>
mov    %r14d,0x4(%rsp)
lea    0xf35(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <getopt@plt>
mov    0x2e0f(%rip),%r12
cmp    (%r12),%al
jne    123d <main+0xcd>
xor    %r13d,%r13d
mov    0x4(%rsp),%ebp
mov    %ebp,%edi
mov    %r13,%rsi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,%r14d
test   %eax,%eax
je     120b <main+0x9b>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xf10(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    122b <main+0xbb>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xebb(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xeb1(%rip),%r15
lea    0xdb5(%rip),%r14
xor    %r13d,%r13d
jmp    127f <main+0x10f>
mov    $0xf5,%edi
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
call   1030 <_IO@plt>
mov    %rax,%r13
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
cmp    (%r12),%al
je     11da <main+0x6a>
movsbl %al,%eax
add    $0xffffffc1,%eax
cmp    $0x34,%eax
ja     1268 <main+0xf8>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1268 <main+0xf8>
mov    $0xf5,%edi
mov    $0x4,%esi
jmp    1260 <main+0xf0>
mov    $0xf5,%edi
mov    $0x6,%esi
jmp    1260 <main+0xf0>
mov    (%rbx),%rdi
call   1070 <usage@plt>
jmp    1268 <main+0xf8>
mov    $0xf5,%edi
mov    $0x3,%esi
jmp    1260 <main+0xf0>
mov    $0xf5,%edi
mov    $0x5,%esi
jmp    1260 <main+0xf0>
mov    $0xf5,%edi
mov    $0x1,%esi
jmp    1260 <main+0xf0>
mov    $0xf5,%edi
mov    $0x2,%esi
jmp    1260 <main+0xf0>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/fault\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [22 x i8] c"open char dev failed\0A\00"
@.str.2 = [9 x i8] c"hnpslamg\00"
@EOF = global i8 0
@.str.3 = [19 x i8] c"unsupported param\0A\00"
@.str.4 = [17 x i8] c"ioctl failed %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i64 0, i64* %8
store i8 0, i8* %9
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i8* %15)
store i32 -1, i32* %3
br label %76
17: ; preds = %2
%18 = load i32, i32* @O_RDWR
%19 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %76
26: ; preds = %17
br label %27
27: ; preds = %60, %26
%28 = load i32, i32* %4
%29 = load i8**, i8*** %5
%30 = call signext i8 @getopt(i32 %28, i8** %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i8 %30, i8* %9
%31 = sext i8 %30 to i32
%32 = load i8, i8* @EOF
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %31, %33
br i1 %34, label %35, label %61
35: ; preds = %27
%36 = load i8, i8* %9
%37 = sext i8 %36 to i32
switch i32 %37, label %60 [
i32 104, label %38
i32 110, label %43
i32 112, label %45
i32 115, label %47
i32 108, label %49
i32 97, label %51
i32 109, label %53
i32 103, label %55
i32 63, label %57
]
38: ; preds = %35
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = call i32 @usage(i8* %41)
br label %60
43: ; preds = %35
%44 = call i64 @_IO(i32 245, i32 0)
store i64 %44, i64* %8
br label %60
45: ; preds = %35
%46 = call i64 @_IO(i32 245, i32 1)
store i64 %46, i64* %8
br label %60
47: ; preds = %35
%48 = call i64 @_IO(i32 245, i32 2)
store i64 %48, i64* %8
br label %60
49: ; preds = %35
%50 = call i64 @_IO(i32 245, i32 3)
store i64 %50, i64* %8
br label %60
51: ; preds = %35
%52 = call i64 @_IO(i32 245, i32 4)
store i64 %52, i64* %8
br label %60
53: ; preds = %35
%54 = call i64 @_IO(i32 245, i32 5)
store i64 %54, i64* %8
br label %60
55: ; preds = %35
%56 = call i64 @_IO(i32 245, i32 6)
store i64 %56, i64* %8
br label %60
57: ; preds = %35
%58 = load i32, i32* @stderr
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %35, %57, %55, %53, %51, %49, %47, %45, %43, %38
br label %27
61: ; preds = %27
%62 = load i32, i32* %6
%63 = load i64, i64* %8
%64 = call i32 @ioctl(i32 %62, i64 %63, i32 0)
store i32 %64, i32* %7
%65 = load i32, i32* %7
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %61
%68 = load i32, i32* @stderr
%69 = load i32, i32* %7
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %69)
br label %72
71: ; preds = %61
br label %72
72: ; preds = %71, %67
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
%75 = load i32, i32* %7
store i32 %75, i32* %3
br label %76
76: ; preds = %72, %22, %12
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/fault\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.1 = [22 x i8] c"open char dev failed\0A\00"
@.str.2 = [9 x i8] c"hnpslamg\00"
@EOF = global i8 0
@.str.3 = [19 x i8] c"unsupported param\0A\00"
@.str.4 = [17 x i8] c"ioctl failed %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
br label %56
7: ; preds = %2
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
br i1 %14, label %47, label %18
15: ; preds = %7
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %56
18: ; preds = %11, %42
%19 = phi i8 [ %44, %42 ], [ %12, %11 ]
%20 = phi i64 [ %43, %42 ], [ 0, %11 ]
%21 = sext i8 %19 to i32
switch i32 %21, label %42 [
i32 104, label %22
i32 110, label %25
i32 112, label %27
i32 115, label %29
i32 108, label %31
i32 97, label %33
i32 109, label %35
i32 103, label %37
i32 63, label %39
]
22: ; preds = %18
%23 = load i8*, i8** %1
%24 = tail call i32 @usage(i8* %23)
br label %42
25: ; preds = %18
%26 = tail call i64 @_IO(i32 245, i32 0)
br label %42
27: ; preds = %18
%28 = tail call i64 @_IO(i32 245, i32 1)
br label %42
29: ; preds = %18
%30 = tail call i64 @_IO(i32 245, i32 2)
br label %42
31: ; preds = %18
%32 = tail call i64 @_IO(i32 245, i32 3)
br label %42
33: ; preds = %18
%34 = tail call i64 @_IO(i32 245, i32 4)
br label %42
35: ; preds = %18
%36 = tail call i64 @_IO(i32 245, i32 5)
br label %42
37: ; preds = %18
%38 = tail call i64 @_IO(i32 245, i32 6)
br label %42
39: ; preds = %18
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %18, %39, %37, %35, %33, %31, %29, %27, %25, %22
%43 = phi i64 [ %20, %18 ], [ %20, %39 ], [ %38, %37 ], [ %36, %35 ], [ %34, %33 ], [ %32, %31 ], [ %30, %29 ], [ %28, %27 ], [ %26, %25 ], [ %20, %22 ]
%44 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%45 = load i8, i8* @EOF
%46 = icmp eq i8 %44, %45
br i1 %46, label %47, label %18
47: ; preds = %42, %11
%48 = phi i64 [ 0, %11 ], [ %43, %42 ]
%49 = tail call i32 @ioctl(i32 %9, i64 %48, i32 0)
%50 = icmp eq i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %47
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %54
54: ; preds = %47, %51
%55 = tail call i32 @close(i32 %9)
br label %56
56: ; preds = %54, %15, %4
%57 = phi i32 [ -1, %4 ], [ %9, %15 ], [ %49, %54 ]
ret i32 %57
}