#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int IEEE1284_MODE_COMPAT;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ PPCLAIM;
int /*<<< orphan*/ PPNEGOT;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ usage();
int /*<<< orphan*/ write(int, char *, size_t);
int main(int argc, char *argv[]) {
  int portFD, fd, i, readFromSTDIN = 2;
  FILE *file;
  int mode = IEEE1284_MODE_COMPAT;
  char *ppdev = "/dev/parport0";
  char buf[512];
  size_t nread;
  for (i = 0; i < argc; i++) {
    if (argv[i][0] != '-')
      continue;
    if (argv[i][1] == 'd' && argc > i + 1) {
      ppdev = argv[i + 1];
      readFromSTDIN += 2;
      continue;
    }
    usage();
    exit(EXIT_FAILURE);
  }
  portFD = open(ppdev, O_RDWR);
  if (ioctl(portFD, PPCLAIM)) {
    perror("ERROR PPCLAIM");
    exit(1);
  }
  if (ioctl(portFD, PPNEGOT, &mode)) {
    perror("ERROR PPSETMODE");
    exit(1);
  }
  if (argc < readFromSTDIN) {
    file = stdin;
  } else {
    file = fopen(argv[argc - 1], "r");
    if (file == NULL) {
      perror("ERROR opening FILE");
      exit(1);
    }
  }
  while ((nread = fread(buf, 1, 512, file)) > 0) {
    write(portFD, buf, nread);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2,-0x20(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    0xe4d(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1257 <main+0xd7>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11e7 <main+0x67>
jmp    1249 <main+0xc9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    1234 <main+0xb4>
mov    -0x8(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    1234 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    1249 <main+0xc9>
mov    $0x0,%al
call   1060 <usage@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11be <main+0x3e>
mov    -0x38(%rbp),%rdi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     129f <main+0x11f>
lea    0xd7e(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     12d6 <main+0x156>
lea    0xd55(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12f5 <main+0x175>
mov    0x2cef(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    133c <main+0x1bc>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd1f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1337 <main+0x1b7>
lea    0xd06(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    133c <main+0x1bc>
jmp    1341 <main+0x1c1>
lea    -0x240(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    %rax,-0x248(%rbp)
cmp    $0x0,%rax
jbe    1387 <main+0x207>
mov    -0x14(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    -0x248(%rbp),%rdx
call   1040 <write@plt>
jmp    1341 <main+0x1c1>
xor    %eax,%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
test   %edi,%edi
jle    11fe <main+0x7e>
mov    %r14d,%eax
mov    $0x2,%ebp
lea    0xe4d(%rip),%rdi
xor    %ecx,%ecx
jmp    11cc <main+0x4c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rcx
mov    %rcx,%rdx
cmp    %rax,%rdx
je     120a <main+0x8a>
mov    (%rbx,%rcx,8),%rdx
cmpb   $0x2d,(%rdx)
jne    11c0 <main+0x40>
cmpb   $0x64,0x1(%rdx)
jne    12e8 <main+0x168>
lea    0x1(%rcx),%rdx
cmp    %rax,%rdx
jge    12e8 <main+0x168>
mov    0x8(%rbx,%rcx,8),%rdi
add    $0x2,%ebp
mov    %rdx,%rcx
cmp    %rax,%rdx
jne    11cc <main+0x4c>
jmp    120a <main+0x8a>
lea    0xdfb(%rip),%rdi
mov    $0x2,%ebp
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%r15d
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %eax,%eax
call   1050 <ioctl@plt>
test   %rax,%rax
jne    12fd <main+0x17d>
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %r15d,%edi
xor    %eax,%eax
call   1050 <ioctl@plt>
test   %rax,%rax
jne    1306 <main+0x186>
cmp    %r14d,%ebp
jle    1269 <main+0xe9>
mov    0x2d74(%rip),%rax
mov    (%rax),%rbx
jmp    1289 <main+0x109>
movslq %r14d,%rax
mov    -0x8(%rbx,%rax,8),%rdi
lea    0xdb4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     130f <main+0x18f>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     12d8 <main+0x158>
lea    0x10(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    12b0 <main+0x130>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1060 <usage@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xd0a(%rip),%rdi
jmp    1316 <main+0x196>
lea    0xd0f(%rip),%rdi
jmp    1316 <main+0x196>
lea    0xd18(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@IEEE1284_MODE_COMPAT = global i32 0
@.str = [14 x i8] c"/dev/parport0\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@PPCLAIM = global i32 0
@.str.1 = [14 x i8] c"ERROR PPCLAIM\00"
@PPNEGOT = global i32 0
@.str.2 = [16 x i8] c"ERROR PPSETMODE\00"
@stdin = global i32* null
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [19 x i8] c"ERROR opening FILE\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
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca [512 x i8]
%14 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 2, i32* %9
%15 = load i32, i32* @IEEE1284_MODE_COMPAT
store i32 %15, i32* %11
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %12
store i32 0, i32* %8
br label %16
16: ; preds = %59, %2
%17 = load i32, i32* %8
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %62
20: ; preds = %16
%21 = load i8**, i8*** %5
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 45
br i1 %29, label %30, label %31
30: ; preds = %20
br label %59
31: ; preds = %20
%32 = load i8**, i8*** %5
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 100
br i1 %40, label %41, label %55
41: ; preds = %31
%42 = load i32, i32* %4
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
%45 = icmp sgt i32 %42, %44
br i1 %45, label %46, label %55
46: ; preds = %41
%47 = load i8**, i8*** %5
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %47, i64 %50
%52 = load i8*, i8** %51
store i8* %52, i8** %12
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 2
store i32 %54, i32* %9
br label %59
55: ; preds = %41, %31
%56 = call i32 (...) @usage()
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %46, %30
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %16
62: ; preds = %16
%63 = load i8*, i8** %12
%64 = load i32, i32* @O_RDWR
%65 = call i32 @open(i8* %63, i32 %64)
store i32 %65, i32* %6
%66 = load i32, i32* %6
%67 = load i32, i32* @PPCLAIM
%68 = call i64 (i32, i32, ...) @ioctl(i32 %66, i32 %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %62
%71 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %62
%74 = load i32, i32* %6
%75 = load i32, i32* @PPNEGOT
%76 = call i64 (i32, i32, ...) @ioctl(i32 %74, i32 %75, i32* %11)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %73
%82 = load i32, i32* %4
%83 = load i32, i32* %9
%84 = icmp slt i32 %82, %83
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = load i32*, i32** @stdin
store i32* %86, i32** %10
br label %101
87: ; preds = %81
%88 = load i8**, i8*** %5
%89 = load i32, i32* %4
%90 = sub nsw i32 %89, 1
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8*, i8** %88, i64 %91
%93 = load i8*, i8** %92
%94 = call i32* @fopen(i8* %93, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %94, i32** %10
%95 = load i32*, i32** %10
%96 = icmp eq i32* %95, null
br i1 %96, label %97, label %100
97: ; preds = %87
%98 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %87
br label %101
101: ; preds = %100, %85
br label %102
102: ; preds = %107, %101
%103 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%104 = load i32*, i32** %10
%105 = call i64 @fread(i8* %103, i32 1, i32 512, i32* %104)
store i64 %105, i64* %14
%106 = icmp ugt i64 %105, 0
br i1 %106, label %107, label %112
107: ; preds = %102
%108 = load i32, i32* %6
%109 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%110 = load i64, i64* %14
%111 = call i32 @write(i32 %108, i8* %109, i64 %110)
br label %102
112: ; preds = %102
ret i32 0
}

LLVM IR (-O2):
@IEEE1284_MODE_COMPAT = global i32 0
@.str = [14 x i8] c"/dev/parport0\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@PPCLAIM = global i32 0
@.str.1 = [14 x i8] c"ERROR PPCLAIM\00"
@PPNEGOT = global i32 0
@.str.2 = [16 x i8] c"ERROR PPSETMODE\00"
@stdin = global i32* null
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [19 x i8] c"ERROR opening FILE\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [512 x i8]
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @IEEE1284_MODE_COMPAT
store i32 %6, i32* %3
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %42
9: ; preds = %2
%10 = zext i32 %0 to i64
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %9, %37
%13 = phi i64 [ 0, %9 ], [ %38, %37 ]
%14 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %9 ], [ %40, %37 ]
%15 = phi i32 [ 2, %9 ], [ %39, %37 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %13
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 45
br i1 %19, label %22, label %20
20: ; preds = %12
%21 = add nuw nsw i64 %13, 1
br label %37
22: ; preds = %12
%23 = getelementptr inbounds i8, i8* %17, i64 1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 100
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = add nuw nsw i64 %13, 1
%28 = icmp slt i64 %27, %10
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = getelementptr inbounds i8*, i8** %1, i64 %27
%31 = load i8*, i8** %30
%32 = add nsw i32 %15, 2
br label %37
33: ; preds = %26, %22
%34 = tail call i32 (...) @usage()
%35 = load i32, i32* @EXIT_FAILURE
%36 = tail call i32 @exit(i32 %35)
unreachable
37: ; preds = %20, %29
%38 = phi i64 [ %21, %20 ], [ %27, %29 ]
%39 = phi i32 [ %15, %20 ], [ %32, %29 ]
%40 = phi i8* [ %14, %20 ], [ %31, %29 ]
%41 = icmp eq i64 %38, %11
br i1 %41, label %42, label %12
42: ; preds = %37, %2
%43 = phi i32 [ 2, %2 ], [ %39, %37 ]
%44 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %2 ], [ %40, %37 ]
%45 = load i32, i32* @O_RDWR
%46 = tail call i32 @open(i8* %44, i32 %45)
%47 = load i32, i32* @PPCLAIM
%48 = tail call i64 (i32, i32, ...) @ioctl(i32 %46, i32 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %42
%51 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%52 = tail call i32 @exit(i32 1)
unreachable
53: ; preds = %42
%54 = load i32, i32* @PPNEGOT
%55 = call i64 (i32, i32, ...) @ioctl(i32 %46, i32 %54, i32* %3)
%56 = icmp eq i64 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %53
%61 = icmp sgt i32 %43, %0
br i1 %61, label %62, label %64
62: ; preds = %60
%63 = load i32*, i32** @stdin
br label %74
64: ; preds = %60
%65 = add nsw i32 %0, -1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %1, i64 %66
%68 = load i8*, i8** %67
%69 = call i32* @fopen(i8* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%70 = icmp eq i32* %69, null
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %64, %62
%75 = phi i32* [ %63, %62 ], [ %69, %64 ]
%76 = call i64 @fread(i8* %7, i32 1, i32 512, i32* %75)
%77 = icmp eq i64 %76, 0
br i1 %77, label %83, label %78
78: ; preds = %74, %78
%79 = phi i64 [ %81, %78 ], [ %76, %74 ]
%80 = call i32 @write(i32 %46, i8* %7, i64 %79)
%81 = call i64 @fread(i8* %7, i32 1, i32 512, i32* %75)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %78
83: ; preds = %78, %74
ret i32 0
}