#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 inb(int);
scalar_t__ ioperm(int, int, int);
int /*<<< orphan*/ outb(char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  char buf, i;
  if (ioperm(0x378, 1, 1)) {
    printf("Cannot open LPT port\n");
    return 1;
  }
  buf = inb(0x378);
  if (argc == 3) {
    if (strlen(argv[2]) == 1) {
      if (!strcmp("on", argv[1])) {
        switch (argv[2][0]) {
        case '4':
          buf |= 1;
          break;
        case '3':
          buf |= 2;
          break;
        case '2':
          buf |= 4;
          break;
        case '1':
          buf |= 8;
          break;
        }
      } else if (!strcmp("off", argv[1])) {
        switch (argv[2][0]) {
        case '4':
          buf &= 254;
          break;
        case '3':
          buf &= 253;
          break;
        case '2':
          buf &= 251;
          break;
        case '1':
          buf &= 247;
          break;
        }
      }
    }
  } else if (argc == 2 && !strcmp("reset", argv[1]))
    buf = 0;
  outb(buf, 0x378);
  for (i = 1; i != 5; i++)
    printf("relay%d: %s\n", i, (buf & (16 >> i)) == (16 >> i) ? "on" : "off");
  return 0;
}


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)
mov    $0x378,%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <ioperm@plt>
cmp    $0x0,%rax
je     11ab <main+0x4b>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b0 <main+0x250>
mov    $0x378,%edi
call   1080 <inb@plt>
mov    %al,-0x11(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1303 <main+0x1a3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    12fe <main+0x19e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe4f(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1262 <main+0x102>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
add    $0xffffffcf,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     125d <main+0xfd>
mov    -0x20(%rbp),%rax
lea    0xde3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsbl -0x11(%rbp),%eax
or     $0x1,%eax
mov    %al,-0x11(%rbp)
jmp    125d <main+0xfd>
movsbl -0x11(%rbp),%eax
or     $0x2,%eax
mov    %al,-0x11(%rbp)
jmp    125d <main+0xfd>
movsbl -0x11(%rbp),%eax
or     $0x4,%eax
mov    %al,-0x11(%rbp)
jmp    125d <main+0xfd>
movsbl -0x11(%rbp),%eax
or     $0x8,%eax
mov    %al,-0x11(%rbp)
jmp    12f9 <main+0x199>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdc8(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12f4 <main+0x194>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
movsbl (%rax),%eax
add    $0xffffffcf,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     12ef <main+0x18f>
mov    -0x28(%rbp),%rax
lea    0xd69(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsbl -0x11(%rbp),%eax
and    $0xfe,%eax
mov    %al,-0x11(%rbp)
jmp    12ef <main+0x18f>
movsbl -0x11(%rbp),%eax
and    $0xfd,%eax
mov    %al,-0x11(%rbp)
jmp    12ef <main+0x18f>
movsbl -0x11(%rbp),%eax
and    $0xfb,%eax
mov    %al,-0x11(%rbp)
jmp    12ef <main+0x18f>
movsbl -0x11(%rbp),%eax
and    $0xf7,%eax
mov    %al,-0x11(%rbp)
jmp    12f4 <main+0x194>
jmp    12f9 <main+0x199>
jmp    12fe <main+0x19e>
jmp    1333 <main+0x1d3>
cmpl   $0x2,-0x8(%rbp)
jne    132e <main+0x1ce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd21(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    132e <main+0x1ce>
movb   $0x0,-0x11(%rbp)
jmp    1333 <main+0x1d3>
mov    $0x378,%esi
movsbl -0x11(%rbp),%edi
call   1050 <outb@plt>
movb   $0x1,-0x12(%rbp)
movsbl -0x12(%rbp),%eax
cmp    $0x5,%eax
je     13a9 <main+0x249>
movsbl -0x12(%rbp),%esi
movsbl -0x11(%rbp),%eax
movsbl -0x12(%rbp),%ecx
mov    $0x10,%edx
sar    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    %eax,-0x2c(%rbp)
movsbl -0x12(%rbp),%ecx
mov    $0x10,%edi
sar    %cl,%edi
mov    -0x2c(%rbp),%ecx
lea    0xcb8(%rip),%rdx
lea    0xcae(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x12(%rbp),%al
add    $0x1,%al
mov    %al,-0x12(%rbp)
jmp    1345 <main+0x1e5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1,%r15d
mov    $0x378,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1080 <ioperm@plt>
test   %rax,%rax
je     11ad <main+0x3d>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
jmp    12ca <main+0x15a>
mov    $0x378,%edi
call   1090 <inb@plt>
mov    %eax,%ebx
cmp    $0x2,%ebp
je     1223 <main+0xb3>
cmp    $0x3,%ebp
jne    123b <main+0xcb>
mov    0x10(%r14),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    123b <main+0xcb>
mov    0x8(%r14),%rbp
lea    0xe44(%rip),%rdi
mov    %rbp,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     12d6 <main+0x166>
lea    0xe30(%rip),%rdi
mov    %rbp,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    123b <main+0xcb>
mov    0x10(%r14),%rax
movsbl (%rax),%eax
add    $0xffffffcf,%eax
cmp    $0x3,%eax
ja     123b <main+0xcb>
lea    0xdeb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
and    $0xf7,%bl
jmp    123b <main+0xcb>
mov    0x8(%r14),%rsi
lea    0xdf9(%rip),%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
movzbl %bl,%ebx
cmove  %eax,%ebx
movsbl %bl,%ebp
mov    %ebp,%edi
mov    $0x378,%esi
call   1060 <outb@plt>
test   $0x8,%bpl
lea    0xdce(%rip),%r12
lea    0xdc4(%rip),%rbx
mov    %rbx,%rdx
cmove  %r12,%rdx
lea    0xdc3(%rip),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0x4,%bpl
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0x2,%bpl
mov    %rbx,%rdx
cmove  %r12,%rdx
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0x1,%bpl
cmove  %r12,%rbx
mov    %r14,%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%r14),%rax
movsbl (%rax),%eax
add    $0xffffffcf,%eax
cmp    $0x3,%eax
ja     123b <main+0xcb>
lea    0xd20(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
or     $0x8,%bl
jmp    123b <main+0xcb>
or     $0x4,%bl
jmp    123b <main+0xcb>
or     $0x2,%bl
jmp    123b <main+0xcb>
or     $0x1,%bl
jmp    123b <main+0xcb>
and    $0xfb,%bl
jmp    123b <main+0xcb>
and    $0xfd,%bl
jmp    123b <main+0xcb>
and    $0xfe,%bl
jmp    123b <main+0xcb>

LLVM IR (-O0):
@.str = [22 x i8] c"Cannot open LPT port\0A\00"
@.str.1 = [3 x i8] c"on\00"
@.str.2 = [4 x i8] c"off\00"
@.str.3 = [6 x i8] c"reset\00"
@.str.4 = [13 x i8] c"relay%d: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 @ioperm(i32 888, i32 1, i32 1)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %131
12: ; preds = %2
%13 = call signext i8 @inb(i32 888)
store i8 %13, i8* %6
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 3
br i1 %15, label %16, label %93
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %92
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %56, label %28
28: ; preds = %22
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
switch i32 %34, label %55 [
i32 52, label %35
i32 51, label %40
i32 50, label %45
i32 49, label %50
]
35: ; preds = %28
%36 = load i8, i8* %6
%37 = sext i8 %36 to i32
%38 = or i32 %37, 1
%39 = trunc i32 %38 to i8
store i8 %39, i8* %6
br label %55
40: ; preds = %28
%41 = load i8, i8* %6
%42 = sext i8 %41 to i32
%43 = or i32 %42, 2
%44 = trunc i32 %43 to i8
store i8 %44, i8* %6
br label %55
45: ; preds = %28
%46 = load i8, i8* %6
%47 = sext i8 %46 to i32
%48 = or i32 %47, 4
%49 = trunc i32 %48 to i8
store i8 %49, i8* %6
br label %55
50: ; preds = %28
%51 = load i8, i8* %6
%52 = sext i8 %51 to i32
%53 = or i32 %52, 8
%54 = trunc i32 %53 to i8
store i8 %54, i8* %6
br label %55
55: ; preds = %28, %50, %45, %40, %35
br label %91
56: ; preds = %22
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i32 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %59)
%61 = icmp ne i32 %60, 0
br i1 %61, label %90, label %62
62: ; preds = %56
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = getelementptr inbounds i8, i8* %65, i64 0
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
switch i32 %68, label %89 [
i32 52, label %69
i32 51, label %74
i32 50, label %79
i32 49, label %84
]
69: ; preds = %62
%70 = load i8, i8* %6
%71 = sext i8 %70 to i32
%72 = and i32 %71, 254
%73 = trunc i32 %72 to i8
store i8 %73, i8* %6
br label %89
74: ; preds = %62
%75 = load i8, i8* %6
%76 = sext i8 %75 to i32
%77 = and i32 %76, 253
%78 = trunc i32 %77 to i8
store i8 %78, i8* %6
br label %89
79: ; preds = %62
%80 = load i8, i8* %6
%81 = sext i8 %80 to i32
%82 = and i32 %81, 251
%83 = trunc i32 %82 to i8
store i8 %83, i8* %6
br label %89
84: ; preds = %62
%85 = load i8, i8* %6
%86 = sext i8 %85 to i32
%87 = and i32 %86, 247
%88 = trunc i32 %87 to i8
store i8 %88, i8* %6
br label %89
89: ; preds = %62, %84, %79, %74, %69
br label %90
90: ; preds = %89, %56
br label %91
91: ; preds = %90, %55
br label %92
92: ; preds = %91, %16
br label %104
93: ; preds = %12
%94 = load i32, i32* %4
%95 = icmp eq i32 %94, 2
br i1 %95, label %96, label %103
96: ; preds = %93
%97 = load i8**, i8*** %5
%98 = getelementptr inbounds i8*, i8** %97, i64 1
%99 = load i8*, i8** %98
%100 = call i32 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %99)
%101 = icmp ne i32 %100, 0
br i1 %101, label %103, label %102
102: ; preds = %96
store i8 0, i8* %6
br label %103
103: ; preds = %102, %96, %93
br label %104
104: ; preds = %103, %92
%105 = load i8, i8* %6
%106 = call i32 @outb(i8 signext %105, i32 888)
store i8 1, i8* %7
br label %107
107: ; preds = %127, %104
%108 = load i8, i8* %7
%109 = sext i8 %108 to i32
%110 = icmp ne i32 %109, 5
br i1 %110, label %111, label %130
111: ; preds = %107
%112 = load i8, i8* %7
%113 = sext i8 %112 to i32
%114 = load i8, i8* %6
%115 = sext i8 %114 to i32
%116 = load i8, i8* %7
%117 = sext i8 %116 to i32
%118 = ashr i32 16, %117
%119 = and i32 %115, %118
%120 = load i8, i8* %7
%121 = sext i8 %120 to i32
%122 = ashr i32 16, %121
%123 = icmp eq i32 %119, %122
%124 = zext i1 %123 to i64
%125 = select i1 %123, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %113, i8* %125)
br label %127
127: ; preds = %111
%128 = load i8, i8* %7
%129 = add i8 %128, 1
store i8 %129, i8* %7
br label %107
130: ; preds = %107
store i32 0, i32* %3
br label %131
131: ; preds = %130, %10
%132 = load i32, i32* %3
ret i32 %132
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"on\00"
@.str.2 = [4 x i8] c"off\00"
@.str.3 = [6 x i8] c"reset\00"
@.str.4 = [13 x i8] c"relay%d: %s\0A\00"
@str = [21 x i8] c"Cannot open LPT port\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i64 @ioperm(i32 888, i32 1, i32 1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %72
7: ; preds = %2
%8 = tail call signext i8 @inb(i32 888)
switch i32 %0, label %52 [
i32 3, label %9
i32 2, label %46
]
9: ; preds = %7
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %52
14: ; preds = %9
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @strcmp(i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %14
%20 = load i8*, i8** %10
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %52 [
i32 52, label %23
i32 51, label %25
i32 50, label %27
i32 49, label %29
]
23: ; preds = %19
%24 = or i8 %8, 1
br label %52
25: ; preds = %19
%26 = or i8 %8, 2
br label %52
27: ; preds = %19
%28 = or i8 %8, 4
br label %52
29: ; preds = %19
%30 = or i8 %8, 8
br label %52
31: ; preds = %14
%32 = tail call i32 @strcmp(i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(1) %16)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %52
34: ; preds = %31
%35 = load i8*, i8** %10
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
switch i32 %37, label %52 [
i32 52, label %38
i32 51, label %40
i32 50, label %42
i32 49, label %44
]
38: ; preds = %34
%39 = and i8 %8, -2
br label %52
40: ; preds = %34
%41 = and i8 %8, -3
br label %52
42: ; preds = %34
%43 = and i8 %8, -5
br label %52
44: ; preds = %34
%45 = and i8 %8, -9
br label %52
46: ; preds = %7
%47 = getelementptr inbounds i8*, i8** %1, i64 1
%48 = load i8*, i8** %47
%49 = tail call i32 @strcmp(i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* dereferenceable(1) %48)
%50 = icmp eq i32 %49, 0
%51 = select i1 %50, i8 0, i8 %8
br label %52
52: ; preds = %46, %7, %9, %31, %34, %44, %42, %40, %38, %23, %25, %27, %29, %19
%53 = phi i8 [ %8, %31 ], [ %8, %34 ], [ %45, %44 ], [ %43, %42 ], [ %41, %40 ], [ %39, %38 ], [ %8, %19 ], [ %30, %29 ], [ %28, %27 ], [ %26, %25 ], [ %24, %23 ], [ %8, %9 ], [ %8, %7 ], [ %51, %46 ]
%54 = tail call i32 @outb(i8 signext %53, i32 888)
%55 = zext i8 %53 to i32
%56 = and i32 %55, 8
%57 = icmp eq i32 %56, 0
%58 = select i1 %57, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 1, i8* %58)
%60 = and i32 %55, 4
%61 = icmp eq i32 %60, 0
%62 = select i1 %61, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 2, i8* %62)
%64 = and i32 %55, 2
%65 = icmp eq i32 %64, 0
%66 = select i1 %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 3, i8* %66)
%68 = and i32 %55, 1
%69 = icmp eq i32 %68, 0
%70 = select i1 %69, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%71 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 4, i8* %70)
br label %72
72: ; preds = %52, %5
%73 = phi i32 [ 1, %5 ], [ 0, %52 ]
ret i32 %73
}