#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*/ EXIT_FAILURE;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ _IOC(int /*<<< orphan*/, char, int, int);
int /*<<< orphan*/ _IOC_NONE;
int /*<<< orphan*/ _IOC_READ;
int /*<<< orphan*/ _IOC_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int fd;
  char buffer[256];
  if (argc < 2)
    usage(argv[0]);
  if (strlen(argv[1]) != 1)
    usage(argv[0]);
  fd = open("/dev/so2_cdev", O_RDONLY);
  if (fd < 0) {
    perror("open");
    exit(EXIT_FAILURE);
  }
  switch (argv[1][0]) {
  case 'p':
    if (ioctl(fd, _IOC(_IOC_NONE, 'k', 1, 0), 0) < 0) {
      perror("ioctl");
      exit(EXIT_FAILURE);
    }
    break;
  case 's':
    if (argc < 3)
      usage(argv[0]);
    memset(buffer, 0, 256);
    strncpy(buffer, argv[2], 256);
    if (ioctl(fd, _IOC(_IOC_WRITE, 'k', 2, 256), buffer) < 0) {
      perror("ioctl");
      exit(EXIT_FAILURE);
    }
    break;
  case 'g':
    if (ioctl(fd, _IOC(_IOC_READ, 'k', 3, 256), buffer) < 0) {
      perror("ioctl");
      exit(EXIT_FAILURE);
    }
    buffer[256 - 1] = 0;
    printf("IOCTL buffer contains %s\n", buffer);
    break;
  case 'd':
    if (ioctl(fd, _IOC(_IOC_NONE, 'k', 4, 0), 0) < 0) {
      perror("ioctl");
      exit(EXIT_FAILURE);
    }
    break;
  case 'u':
    if (ioctl(fd, _IOC(_IOC_NONE, 'k', 5, 0), 0) < 0) {
      perror("ioctl");
      exit(EXIT_FAILURE);
    }
    break;
  case 'n':
    if (fcntl(fd, F_SETFL, O_RDONLY | O_NONBLOCK) < 0) {
      perror("fcntl");
      exit(EXIT_FAILURE);
    }
    if (read(fd, buffer, 256) < 0) {
      perror("read");
      exit(EXIT_FAILURE);
    }
    buffer[256 - 1] = 0;
    printf("Device buffer contains %s\n", buffer);
    break;
  default:
    error("Wrong parameter");
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    120f <main+0x2f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
je     1231 <main+0x51>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
lea    0xe07(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    126d <main+0x8d>
lea    0xdfc(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x128(%rbp)
sub    $0x11,%eax
ja     156e <main+0x38e>
mov    -0x128(%rbp),%rax
lea    0xd65(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%eax
mov    %eax,-0x12c(%rbp)
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
mov    $0x6b,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <_IOC@plt>
mov    -0x12c(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <ioctl@plt>
cmp    $0x0,%eax
jge    12fb <main+0x11b>
lea    0xd73(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    157a <main+0x39a>
cmpl   $0x3,-0x8(%rbp)
jge    1316 <main+0x136>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <usage@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x130(%rbp)
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
mov    $0x6b,%esi
mov    $0x2,%edx
mov    $0x100,%ecx
call   1060 <_IOC@plt>
mov    -0x130(%rbp),%edi
mov    %eax,%esi
lea    -0x120(%rbp),%rdx
call   1090 <ioctl@plt>
cmp    $0x0,%eax
jge    139f <main+0x1bf>
lea    0xccf(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    157a <main+0x39a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x134(%rbp)
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
mov    $0x6b,%esi
mov    $0x3,%edx
mov    $0x100,%ecx
call   1060 <_IOC@plt>
mov    -0x134(%rbp),%edi
mov    %eax,%esi
lea    -0x120(%rbp),%rdx
call   1090 <ioctl@plt>
cmp    $0x0,%eax
jge    1401 <main+0x221>
lea    0xc6d(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2bc6(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x120(%rbp),%rsi
lea    0xc4e(%rip),%rdi
call   1070 <printf@plt>
jmp    157a <main+0x39a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x138(%rbp)
mov    0x2bab(%rip),%rax
mov    (%rax),%edi
mov    $0x6b,%esi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <_IOC@plt>
mov    -0x138(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <ioctl@plt>
cmp    $0x0,%eax
jge    1474 <main+0x294>
lea    0xbfa(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2b53(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    157a <main+0x39a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x13c(%rbp)
mov    0x2b4f(%rip),%rax
mov    (%rax),%edi
mov    $0x6b,%esi
mov    $0x5,%edx
xor    %ecx,%ecx
call   1060 <_IOC@plt>
mov    -0x13c(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <ioctl@plt>
cmp    $0x0,%eax
jge    14d0 <main+0x2f0>
lea    0xb9e(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2af7(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    157a <main+0x39a>
mov    -0x14(%rbp),%edi
mov    0x2ae9(%rip),%rax
mov    (%rax),%esi
mov    0x2af8(%rip),%rax
mov    (%rax),%edx
mov    0x2af7(%rip),%rax
or     (%rax),%edx
call   1040 <fcntl@plt>
cmp    $0x0,%eax
jge    151b <main+0x33b>
lea    0xb73(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2aac(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   10b0 <read@plt>
cmp    $0x0,%eax
jge    1552 <main+0x372>
lea    0xb42(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2a75(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x120(%rbp),%rsi
lea    0xb22(%rip),%rdi
call   1070 <printf@plt>
jmp    157a <main+0x39a>
lea    0xb2c(%rip),%rdi
call   10d0 <error@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x1,%edi
jg     11ff <main+0x1f>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    0x8(%rbx),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
je     1215 <main+0x35>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    0x2dc4(%rip),%r15
mov    (%r15),%esi
lea    0xe22(%rip),%rdi
call   10e0 <open@plt>
test   %eax,%eax
js     13c8 <main+0x1e8>
mov    %eax,%r14d
mov    0x8(%rbx),%rax
movsbl (%rax),%eax
add    $0xffffff9c,%eax
cmp    $0x11,%eax
ja     12bb <main+0xdb>
lea    0xdb4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    $0x6b,%esi
mov    $0x4,%edx
jmp    1399 <main+0x1b9>
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
or     (%r15),%edx
mov    %r14d,%edi
call   1040 <fcntl@plt>
test   %eax,%eax
js     13eb <main+0x20b>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x100,%edx
call   10b0 <read@plt>
test   %eax,%eax
js     13f4 <main+0x214>
movb   $0x0,0xff(%rsp)
lea    0xdcd(%rip),%rdi
jmp    130d <main+0x12d>
lea    0xddf(%rip),%rdi
call   10d0 <error@plt>
jmp    13b0 <main+0x1d0>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
mov    $0x6b,%esi
mov    $0x3,%edx
mov    $0x100,%ecx
call   1060 <_IOC@plt>
mov    %rsp,%rdx
mov    %r14d,%edi
mov    %eax,%esi
call   1090 <ioctl@plt>
test   %eax,%eax
js     13d1 <main+0x1f1>
movb   $0x0,0xff(%rsp)
lea    0xd54(%rip),%rdi
mov    %rsp,%rsi
call   1070 <printf@plt>
jmp    13b0 <main+0x1d0>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
mov    $0x6b,%esi
mov    $0x1,%edx
jmp    1399 <main+0x1b9>
cmp    $0x2,%ebp
jg     133c <main+0x15c>
mov    (%rbx),%rdi
call   10c0 <usage@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    0x10(%rbx),%rsi
mov    %rbp,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    0x2c42(%rip),%rax
mov    (%rax),%edi
mov    $0x6b,%esi
mov    $0x2,%edx
mov    $0x100,%ecx
call   1060 <_IOC@plt>
mov    %r14d,%edi
mov    %eax,%esi
mov    %rbp,%rdx
jmp    13a7 <main+0x1c7>
mov    0x2c4b(%rip),%rax
mov    (%rax),%edi
mov    $0x6b,%esi
mov    $0x5,%edx
xor    %ecx,%ecx
call   1060 <_IOC@plt>
mov    %r14d,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1090 <ioctl@plt>
test   %eax,%eax
js     13d1 <main+0x1f1>
mov    %r14d,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc87(%rip),%rdi
jmp    13d8 <main+0x1f8>
lea    0xc83(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2bdc(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    0xc89(%rip),%rdi
jmp    13d8 <main+0x1f8>
lea    0xc86(%rip),%rdi
jmp    13d8 <main+0x1f8>

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/so2_cdev\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@_IOC_NONE = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@_IOC_WRITE = global i32 0
@_IOC_READ = global i32 0
@.str.3 = [26 x i8] c"IOCTL buffer contains %s\0A\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.4 = [6 x i8] c"fcntl\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [27 x i8] c"Device buffer contains %s\0A\00"
@.str.7 = [16 x i8] c"Wrong parameter\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @usage(i8* %13)
br label %15
15: ; preds = %10, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
%20 = icmp ne i32 %19, 1
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @usage(i8* %24)
br label %26
26: ; preds = %21, %15
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %26
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = getelementptr inbounds i8, i8* %38, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
switch i32 %41, label %142 [
i32 112, label %42
i32 115, label %53
i32 103, label %80
i32 100, label %95
i32 117, label %106
i32 110, label %117
]
42: ; preds = %35
%43 = load i32, i32* %6
%44 = load i32, i32* @_IOC_NONE
%45 = call i32 @_IOC(i32 %44, i8 signext 107, i32 1, i32 0)
%46 = call i32 @ioctl(i32 %43, i32 %45, i8* null)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %42
%49 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %42
br label %144
53: ; preds = %35
%54 = load i32, i32* %4
%55 = icmp slt i32 %54, 3
br i1 %55, label %56, label %61
56: ; preds = %53
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 0
%59 = load i8*, i8** %58
%60 = call i32 @usage(i8* %59)
br label %61
61: ; preds = %56, %53
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%63 = call i32 @memset(i8* %62, i32 0, i32 256)
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 2
%67 = load i8*, i8** %66
%68 = call i32 @strncpy(i8* %64, i8* %67, i32 256)
%69 = load i32, i32* %6
%70 = load i32, i32* @_IOC_WRITE
%71 = call i32 @_IOC(i32 %70, i8 signext 107, i32 2, i32 256)
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%73 = call i32 @ioctl(i32 %69, i32 %71, i8* %72)
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %61
%76 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%77 = load i32, i32* @EXIT_FAILURE
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %61
br label %144
80: ; preds = %35
%81 = load i32, i32* %6
%82 = load i32, i32* @_IOC_READ
%83 = call i32 @_IOC(i32 %82, i8 signext 107, i32 3, i32 256)
%84 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%85 = call i32 @ioctl(i32 %81, i32 %83, i8* %84)
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %91
87: ; preds = %80
%88 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%89 = load i32, i32* @EXIT_FAILURE
%90 = call i32 @exit(i32 %89)
unreachable
91: ; preds = %80
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 255
store i8 0, i8* %92
%93 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%94 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %93)
br label %144
95: ; preds = %35
%96 = load i32, i32* %6
%97 = load i32, i32* @_IOC_NONE
%98 = call i32 @_IOC(i32 %97, i8 signext 107, i32 4, i32 0)
%99 = call i32 @ioctl(i32 %96, i32 %98, i8* null)
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %105
101: ; preds = %95
%102 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%103 = load i32, i32* @EXIT_FAILURE
%104 = call i32 @exit(i32 %103)
unreachable
105: ; preds = %95
br label %144
106: ; preds = %35
%107 = load i32, i32* %6
%108 = load i32, i32* @_IOC_NONE
%109 = call i32 @_IOC(i32 %108, i8 signext 107, i32 5, i32 0)
%110 = call i32 @ioctl(i32 %107, i32 %109, i8* null)
%111 = icmp slt i32 %110, 0
br i1 %111, label %112, label %116
112: ; preds = %106
%113 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%114 = load i32, i32* @EXIT_FAILURE
%115 = call i32 @exit(i32 %114)
unreachable
116: ; preds = %106
br label %144
117: ; preds = %35
%118 = load i32, i32* %6
%119 = load i32, i32* @F_SETFL
%120 = load i32, i32* @O_RDONLY
%121 = load i32, i32* @O_NONBLOCK
%122 = or i32 %120, %121
%123 = call i32 @fcntl(i32 %118, i32 %119, i32 %122)
%124 = icmp slt i32 %123, 0
br i1 %124, label %125, label %129
125: ; preds = %117
%126 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%127 = load i32, i32* @EXIT_FAILURE
%128 = call i32 @exit(i32 %127)
unreachable
129: ; preds = %117
%130 = load i32, i32* %6
%131 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%132 = call i32 @read(i32 %130, i8* %131, i32 256)
%133 = icmp slt i32 %132, 0
br i1 %133, label %134, label %138
134: ; preds = %129
%135 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%136 = load i32, i32* @EXIT_FAILURE
%137 = call i32 @exit(i32 %136)
unreachable
138: ; preds = %129
%139 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 255
store i8 0, i8* %139
%140 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%141 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %140)
br label %144
142: ; preds = %35
%143 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %144
144: ; preds = %142, %138, %116, %105, %91, %79, %52
%145 = load i32, i32* %6
%146 = call i32 @close(i32 %145)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/so2_cdev\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@_IOC_NONE = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@_IOC_WRITE = global i32 0
@_IOC_READ = global i32 0
@.str.3 = [26 x i8] c"IOCTL buffer contains %s\0A\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.4 = [6 x i8] c"fcntl\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [27 x i8] c"Device buffer contains %s\0A\00"
@.str.7 = [16 x i8] c"Wrong parameter\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %9
9: ; preds = %6, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = icmp eq i32 %12, 1
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = load i8*, i8** %1
%16 = tail call i32 @usage(i8* %15)
br label %17
17: ; preds = %14, %9
%18 = load i32, i32* @O_RDONLY
%19 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %17
%26 = load i8*, i8** %10
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
switch i32 %28, label %107 [
i32 112, label %29
i32 115, label %38
i32 103, label %56
i32 100, label %68
i32 117, label %77
i32 110, label %86
]
29: ; preds = %25
%30 = load i32, i32* @_IOC_NONE
%31 = tail call i32 @_IOC(i32 %30, i8 signext 107, i32 1, i32 0)
%32 = tail call i32 @ioctl(i32 %19, i32 %31, i8* null)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %109
34: ; preds = %29
%35 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = tail call i32 @exit(i32 %36)
unreachable
38: ; preds = %25
%39 = icmp slt i32 %0, 3
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = load i8*, i8** %1
%42 = tail call i32 @usage(i8* %41)
br label %43
43: ; preds = %40, %38
%44 = call i32 @memset(i8* %4, i32 0, i32 256)
%45 = getelementptr inbounds i8*, i8** %1, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @strncpy(i8* %4, i8* %46, i32 256)
%48 = load i32, i32* @_IOC_WRITE
%49 = call i32 @_IOC(i32 %48, i8 signext 107, i32 2, i32 256)
%50 = call i32 @ioctl(i32 %19, i32 %49, i8* %4)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %109
52: ; preds = %43
%53 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %25
%57 = load i32, i32* @_IOC_READ
%58 = tail call i32 @_IOC(i32 %57, i8 signext 107, i32 3, i32 256)
%59 = call i32 @ioctl(i32 %19, i32 %58, i8* %4)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %56
%62 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %56
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
store i8 0, i8* %66
%67 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %109
68: ; preds = %25
%69 = load i32, i32* @_IOC_NONE
%70 = tail call i32 @_IOC(i32 %69, i8 signext 107, i32 4, i32 0)
%71 = tail call i32 @ioctl(i32 %19, i32 %70, i8* null)
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %109
73: ; preds = %68
%74 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
%76 = tail call i32 @exit(i32 %75)
unreachable
77: ; preds = %25
%78 = load i32, i32* @_IOC_NONE
%79 = tail call i32 @_IOC(i32 %78, i8 signext 107, i32 5, i32 0)
%80 = tail call i32 @ioctl(i32 %19, i32 %79, i8* null)
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %109
82: ; preds = %77
%83 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%84 = load i32, i32* @EXIT_FAILURE
%85 = tail call i32 @exit(i32 %84)
unreachable
86: ; preds = %25
%87 = load i32, i32* @F_SETFL
%88 = load i32, i32* @O_RDONLY
%89 = load i32, i32* @O_NONBLOCK
%90 = or i32 %89, %88
%91 = tail call i32 @fcntl(i32 %19, i32 %87, i32 %90)
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %86
%94 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%95 = load i32, i32* @EXIT_FAILURE
%96 = tail call i32 @exit(i32 %95)
unreachable
97: ; preds = %86
%98 = call i32 @read(i32 %19, i8* %4, i32 256)
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %104
100: ; preds = %97
%101 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%102 = load i32, i32* @EXIT_FAILURE
%103 = tail call i32 @exit(i32 %102)
unreachable
104: ; preds = %97
%105 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 255
store i8 0, i8* %105
%106 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %4)
br label %109
107: ; preds = %25
%108 = tail call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %109
109: ; preds = %77, %68, %43, %29, %107, %104, %65
%110 = call i32 @close(i32 %19)
ret i32 0
}