#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*/ exit(int);
int ioctl(int, int, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char **argv) {
  int fd;
  int vendor, product;
  int status;
  if ((fd = open("/dev/urbtc0", O_RDWR)) == -1) {
    perror("device open error\n");
    exit(1);
  }
  if (ioctl(fd, 1, &vendor) == -1) {
    perror("ioctl error\n");
    exit(1);
  }
  printf("Vendor %x\n", vendor);
  if (ioctl(fd, 2, &product) == -1) {
    perror("ioctl error\n");
    exit(1);
  }
  printf("Product %x\n", product);
  if (ioctl(fd, 3) == -1) {
    perror("ioctl error\n");
    exit(1);
  }
  if (ioctl(fd, 7, &status) == -1) {
    perror("ioctl error\n");
    exit(1);
  }
  printf("read status %d\n", status);
  if (ioctl(fd, 4) == -1) {
    perror("ioctl error\n");
    exit(1);
  }
  if (ioctl(fd, 7, &status) == -1) {
    perror("ioctl error\n");
    exit(1);
  }
  printf("read status %d\n", status);
  if (ioctl(fd, 5) == -1) {
    perror("ioctl error\n");
    exit(1);
  }
  if (ioctl(fd, 8, &status) == -1) {
    perror("ioctl error\n");
    exit(1);
  }
  printf("write status %d\n", status);
  if (ioctl(fd, 6) == -1) {
    perror("ioctl error\n");
    exit(1);
  }
  if (ioctl(fd, 8, &status) == -1) {
    perror("ioctl error\n");
    exit(1);
  }
  printf("write status %d\n", status);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11ad <main+0x4d>
lea    0xe6e(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11df <main+0x7f>
lea    0xe4f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%esi
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1220 <main+0xc0>
lea    0xe0e(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%esi
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x3,%esi
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    125d <main+0xfd>
lea    0xdd1(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x7,%esi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    128f <main+0x12f>
lea    0xd9f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%esi
lea    0xdaa(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    12cc <main+0x16c>
lea    0xd62(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x7,%esi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    12fe <main+0x19e>
lea    0xd30(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%esi
lea    0xd3b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    133b <main+0x1db>
lea    0xcf3(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    136d <main+0x20d>
lea    0xcc1(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%esi
lea    0xcdc(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x6,%esi
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    13aa <main+0x24a>
lea    0xc84(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    13dc <main+0x27c>
lea    0xc52(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%esi
lea    0xc6d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     12fe <main+0x19e>
mov    %eax,%ebx
lea    0xc(%rsp),%rdx
mov    %eax,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x188>
mov    0xc(%rsp),%esi
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x188>
mov    0x8(%rsp),%esi
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x188>
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x188>
mov    0x4(%rsp),%esi
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x188>
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x188>
mov    0x4(%rsp),%esi
lea    0xde5(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x188>
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x188>
mov    0x4(%rsp),%esi
lea    0xdba(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x188>
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x188>
mov    0x4(%rsp),%esi
lea    0xd7f(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xd30(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xd07(%rip),%rdi
jmp    12ef <main+0x18f>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/urbtc0\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"device open error\0A\00"
@.str.2 = [13 x i8] c"ioctl error\0A\00"
@.str.3 = [11 x i8] c"Vendor %x\0A\00"
@.str.4 = [12 x i8] c"Product %x\0A\00"
@.str.5 = [16 x i8] c"read status %d\0A\00"
@.str.6 = [17 x i8] c"write status %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 i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* %6
%18 = call i32 (i32, i32, ...) @ioctl(i32 %17, i32 1, i32* %7)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16
%24 = load i32, i32* %7
%25 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %6
%27 = call i32 (i32, i32, ...) @ioctl(i32 %26, i32 2, i32* %8)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23
%33 = load i32, i32* %8
%34 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %6
%36 = call i32 (i32, i32, ...) @ioctl(i32 %35, i32 3)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %32
%42 = load i32, i32* %6
%43 = call i32 (i32, i32, ...) @ioctl(i32 %42, i32 7, i32* %9)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %41
%49 = load i32, i32* %9
%50 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %6
%52 = call i32 (i32, i32, ...) @ioctl(i32 %51, i32 4)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %48
%55 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %48
%58 = load i32, i32* %6
%59 = call i32 (i32, i32, ...) @ioctl(i32 %58, i32 7, i32* %9)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %57
%65 = load i32, i32* %9
%66 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %6
%68 = call i32 (i32, i32, ...) @ioctl(i32 %67, i32 5)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %64
%71 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %64
%74 = load i32, i32* %6
%75 = call i32 (i32, i32, ...) @ioctl(i32 %74, i32 8, i32* %9)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %80
77: ; preds = %73
%78 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %73
%81 = load i32, i32* %9
%82 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %6
%84 = call i32 (i32, i32, ...) @ioctl(i32 %83, i32 6)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %89
86: ; preds = %80
%87 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %80
%90 = load i32, i32* %6
%91 = call i32 (i32, i32, ...) @ioctl(i32 %90, i32 8, i32* %9)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %96
93: ; preds = %89
%94 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %89
%97 = load i32, i32* %9
%98 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %97)
%99 = load i32, i32* %6
%100 = call i32 @close(i32 %99)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/urbtc0\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"device open error\0A\00"
@.str.2 = [13 x i8] c"ioctl error\0A\00"
@.str.3 = [11 x i8] c"Vendor %x\0A\00"
@.str.4 = [12 x i8] c"Product %x\0A\00"
@.str.5 = [16 x i8] c"read status %d\0A\00"
@.str.6 = [17 x i8] c"write status %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i32, i32* @O_RDWR
%10 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = call i32 (i32, i32, ...) @ioctl(i32 %10, i32 1, i32* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = load i32, i32* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = call i32 (i32, i32, ...) @ioctl(i32 %10, i32 2, i32* %4)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i32, i32* %4
%31 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = call i32 (i32, i32, ...) @ioctl(i32 %10, i32 3)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %29
%38 = call i32 (i32, i32, ...) @ioctl(i32 %10, i32 7, i32* %5)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %37
%44 = load i32, i32* %5
%45 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %44)
%46 = call i32 (i32, i32, ...) @ioctl(i32 %10, i32 4)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %43
%52 = call i32 (i32, i32, ...) @ioctl(i32 %10, i32 7, i32* %5)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %51
%58 = load i32, i32* %5
%59 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %58)
%60 = call i32 (i32, i32, ...) @ioctl(i32 %10, i32 5)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %57
%66 = call i32 (i32, i32, ...) @ioctl(i32 %10, i32 8, i32* %5)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %65
%72 = load i32, i32* %5
%73 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %72)
%74 = call i32 (i32, i32, ...) @ioctl(i32 %10, i32 6)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %71
%80 = call i32 (i32, i32, ...) @ioctl(i32 %10, i32 8, i32* %5)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %79
%86 = load i32, i32* %5
%87 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %86)
%88 = call i32 @close(i32 %10)
ret i32 0
}