#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*/ PPCLAIM;
int /*<<< orphan*/ PPEXCL;
int /*<<< orphan*/ PPWDATA;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  unsigned char data;
  int pfd;
  pfd = open("/dev/parportsnif0", O_RDWR);
  if (pfd < 0) {
    perror("Failed to open port");
    exit(0);
  }
  if ((ioctl(pfd, PPEXCL) < 0) || (ioctl(pfd, PPCLAIM) < 0)) {
    perror("Failed to lock port");
    close(pfd);
    exit(0);
  }
  data = 0x00;
  ioctl(pfd, PPWDATA, &data);
  usleep(100000);
  data = 0x55;
  ioctl(pfd, PPWDATA, &data);
  usleep(100000);
  data = 0xAA;
  ioctl(pfd, PPWDATA, &data);
  usleep(100000);
  data = 0x55;
  ioctl(pfd, PPWDATA, &data);
  usleep(100000);
  data = 0xAA;
  ioctl(pfd, PPWDATA, &data);
  usleep(100000);
  data = 0x00;
  ioctl(pfd, PPWDATA, &data);
  usleep(100000);
  close(pfd);
  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    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ab <main+0x4b>
lea    0xe73(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%eax
jl     11e3 <main+0x83>
mov    -0x18(%rbp),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%eax
jge    11fe <main+0x9e>
lea    0xe3c(%rip),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>
movb   $0x0,-0x11(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
lea    -0x11(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movb   $0x55,-0x11(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
lea    -0x11(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movb   $0xaa,-0x11(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
lea    -0x11(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movb   $0x55,-0x11(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
lea    -0x11(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movb   $0xaa,-0x11(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
lea    -0x11(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movb   $0x0,-0x11(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d13(%rip),%rax
mov    (%rax),%esi
lea    -0x11(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     12a9 <main+0x149>
mov    %eax,%ebx
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %eax,%eax
js     128f <main+0x12f>
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %eax,%eax
js     128f <main+0x12f>
movb   $0x0,0xf(%rsp)
mov    0x2e10(%rip),%r15
mov    (%r15),%esi
lea    0xf(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movb   $0x55,0xf(%rsp)
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movb   $0xaa,0xf(%rsp)
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movb   $0x55,0xf(%rsp)
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movb   $0xaa,0xf(%rsp)
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
movb   $0x0,0xf(%rsp)
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    $0x186a0,%edi
call   1080 <usleep@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd90(%rip),%rdi
call   1060 <perror@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xd62(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"/dev/parportsnif0\00"
@O_RDWR = global i32 0
@.str.1 = [20 x i8] c"Failed to open port\00"
@PPEXCL = global i32 0
@PPCLAIM = global i32 0
@.str.2 = [20 x i8] c"Failed to lock port\00"
@PPWDATA = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = load i32, i32* %7
%17 = load i32, i32* @PPEXCL
%18 = call i32 (i32, i32, ...) @ioctl(i32 %16, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = load i32, i32* %7
%22 = load i32, i32* @PPCLAIM
%23 = call i32 (i32, i32, ...) @ioctl(i32 %21, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20, %15
%26 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* %7
%28 = call i32 @close(i32 %27)
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %20
store i8 0, i8* %6
%31 = load i32, i32* %7
%32 = load i32, i32* @PPWDATA
%33 = call i32 (i32, i32, ...) @ioctl(i32 %31, i32 %32, i8* %6)
%34 = call i32 @usleep(i32 100000)
store i8 85, i8* %6
%35 = load i32, i32* %7
%36 = load i32, i32* @PPWDATA
%37 = call i32 (i32, i32, ...) @ioctl(i32 %35, i32 %36, i8* %6)
%38 = call i32 @usleep(i32 100000)
store i8 -86, i8* %6
%39 = load i32, i32* %7
%40 = load i32, i32* @PPWDATA
%41 = call i32 (i32, i32, ...) @ioctl(i32 %39, i32 %40, i8* %6)
%42 = call i32 @usleep(i32 100000)
store i8 85, i8* %6
%43 = load i32, i32* %7
%44 = load i32, i32* @PPWDATA
%45 = call i32 (i32, i32, ...) @ioctl(i32 %43, i32 %44, i8* %6)
%46 = call i32 @usleep(i32 100000)
store i8 -86, i8* %6
%47 = load i32, i32* %7
%48 = load i32, i32* @PPWDATA
%49 = call i32 (i32, i32, ...) @ioctl(i32 %47, i32 %48, i8* %6)
%50 = call i32 @usleep(i32 100000)
store i8 0, i8* %6
%51 = load i32, i32* %7
%52 = load i32, i32* @PPWDATA
%53 = call i32 (i32, i32, ...) @ioctl(i32 %51, i32 %52, i8* %6)
%54 = call i32 @usleep(i32 100000)
%55 = load i32, i32* %7
%56 = call i32 @close(i32 %55)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"/dev/parportsnif0\00"
@O_RDWR = global i32 0
@.str.1 = [20 x i8] c"Failed to open port\00"
@PPEXCL = global i32 0
@PPCLAIM = global i32 0
@.str.2 = [20 x i8] c"Failed to lock port\00"
@PPWDATA = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = load i32, i32* @PPEXCL
%12 = tail call i32 (i32, i32, ...) @ioctl(i32 %5, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i32, i32* @PPCLAIM
%16 = tail call i32 (i32, i32, ...) @ioctl(i32 %5, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14, %10
%19 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @close(i32 %5)
%21 = tail call i32 @exit(i32 0)
unreachable
22: ; preds = %14
store i8 0, i8* %3
%23 = load i32, i32* @PPWDATA
%24 = call i32 (i32, i32, ...) @ioctl(i32 %5, i32 %23, i8* %3)
%25 = call i32 @usleep(i32 100000)
store i8 85, i8* %3
%26 = load i32, i32* @PPWDATA
%27 = call i32 (i32, i32, ...) @ioctl(i32 %5, i32 %26, i8* %3)
%28 = call i32 @usleep(i32 100000)
store i8 -86, i8* %3
%29 = load i32, i32* @PPWDATA
%30 = call i32 (i32, i32, ...) @ioctl(i32 %5, i32 %29, i8* %3)
%31 = call i32 @usleep(i32 100000)
store i8 85, i8* %3
%32 = load i32, i32* @PPWDATA
%33 = call i32 (i32, i32, ...) @ioctl(i32 %5, i32 %32, i8* %3)
%34 = call i32 @usleep(i32 100000)
store i8 -86, i8* %3
%35 = load i32, i32* @PPWDATA
%36 = call i32 (i32, i32, ...) @ioctl(i32 %5, i32 %35, i8* %3)
%37 = call i32 @usleep(i32 100000)
store i8 0, i8* %3
%38 = load i32, i32* @PPWDATA
%39 = call i32 (i32, i32, ...) @ioctl(i32 %5, i32 %38, i8* %3)
%40 = call i32 @usleep(i32 100000)
%41 = call i32 @close(i32 %5)
ret i32 0
}