#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*/ PPRELEASE;
int /*<<< orphan*/ PPWDATA;
unsigned char atoi(char *);
scalar_t__ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
scalar_t__ ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  unsigned char trig = 0xFF;
  int pport = open("/dev/parport0", O_RDWR);
  if (argc > 1) {
    trig = atoi(argv[1]);
  }
  if (pport >= 0) {
    if (ioctl(pport, PPCLAIM) < 0) {
      fprintf(stderr, "PPCLAIM ioctl Error : %s (%d)\n", strerror(errno),
              errno);
      exit(errno);
    }
    if (ioctl(pport, PPWDATA, &trig) < 0) {
      fprintf(stderr, "PPWDATA ioctl Error : %s (%d)\n", strerror(errno),
              errno);
      exit(errno);
    }
    usleep(3000);
    trig = 0;
    ioctl(pport, PPWDATA, &trig);
    if (ioctl(pport, PPRELEASE) < 0) {
      fprintf(stderr, "PPRELEASE ioctl Error : %s (%d)\n", strerror(errno),
              errno);
      exit(errno);
    }
    if (close(pport) < 0) {
      fprintf(stderr, "Close Error : %s (%d)\n", strerror(errno), errno);
      exit(errno);
    }
  } else
    perror("trigger");
}


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)
movb   $0xff,-0x11(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    0xe46(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11dc <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %al,-0x11(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1389 <main+0x1f9>
mov    -0x18(%rbp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1246 <main+0xb6>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
mov    0x2d8e(%rip),%rax
mov    (%rax),%ecx
lea    0xddb(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
lea    -0x11(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    12aa <main+0x11a>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
mov    0x2d2a(%rip),%rax
mov    (%rax),%ecx
lea    0xd96(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    $0xbb8,%edi
call   10b0 <usleep@plt>
movb   $0x0,-0x11(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d0e(%rip),%rax
mov    (%rax),%esi
lea    -0x11(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    -0x18(%rbp),%edi
mov    0x2d0f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    132f <main+0x19f>
mov    0x2ccd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
mov    0x2ca5(%rip),%rax
mov    (%rax),%ecx
lea    0xd30(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c90(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    1384 <main+0x1f4>
mov    0x2c78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
mov    0x2c50(%rip),%rax
mov    (%rax),%ecx
lea    0xcfc(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1395 <main+0x205>
lea    0xcf4(%rip),%rdi
call   1070 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movb   $0xff,0xf(%rsp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    0xe4e(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
cmp    $0x2,%ebp
jl     11cb <main+0x3b>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
mov    %al,0xf(%rsp)
test   %ebx,%ebx
js     1261 <main+0xd1>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %rax,%rax
js     126f <main+0xdf>
mov    0x2ddb(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xf(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %rax,%rax
js     1293 <main+0x103>
mov    $0xbb8,%edi
call   10b0 <usleep@plt>
movb   $0x0,0xf(%rsp)
mov    0x0(%rbp),%esi
lea    0xf(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %rax,%rax
js     12b7 <main+0x127>
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
js     12db <main+0x14b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe1c(%rip),%rdi
call   1070 <perror@plt>
jmp    1256 <main+0xc6>
mov    0x2d4a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d39(%rip),%rbp
mov    0x0(%rbp),%edi
call   10a0 <strerror@plt>
mov    0x0(%rbp),%ecx
lea    0xd7d(%rip),%rsi
jmp    12fd <main+0x16d>
mov    0x2d26(%rip),%rax
mov    (%rax),%ebx
mov    0x2d15(%rip),%rbp
mov    0x0(%rbp),%edi
call   10a0 <strerror@plt>
mov    0x0(%rbp),%ecx
lea    0xd78(%rip),%rsi
jmp    12fd <main+0x16d>
mov    0x2d02(%rip),%rax
mov    (%rax),%ebx
mov    0x2cf1(%rip),%rbp
mov    0x0(%rbp),%edi
call   10a0 <strerror@plt>
mov    0x0(%rbp),%ecx
lea    0xd73(%rip),%rsi
jmp    12fd <main+0x16d>
mov    0x2cde(%rip),%rax
mov    (%rax),%ebx
mov    0x2ccd(%rip),%rbp
mov    0x0(%rbp),%edi
call   10a0 <strerror@plt>
mov    0x0(%rbp),%ecx
lea    0xd70(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/parport0\00"
@O_RDWR = global i32 0
@PPCLAIM = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"PPCLAIM ioctl Error : %s (%d)\0A\00"
@errno = global i32 0
@PPWDATA = global i32 0
@.str.2 = [31 x i8] c"PPWDATA ioctl Error : %s (%d)\0A\00"
@PPRELEASE = global i32 0
@.str.3 = [33 x i8] c"PPRELEASE ioctl Error : %s (%d)\0A\00"
@.str.4 = [23 x i8] c"Close Error : %s (%d)\0A\00"
@.str.5 = [8 x i8] c"trigger\00"
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
store i8 -1, i8* %6
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %7
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call zeroext i8 @atoi(i8* %15)
store i8 %16, i8* %6
br label %17
17: ; preds = %12, %2
%18 = load i32, i32* %7
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %76
20: ; preds = %17
%21 = load i32, i32* %7
%22 = load i32, i32* @PPCLAIM
%23 = call i64 (i32, i32, ...) @ioctl(i32 %21, i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = load i32, i32* @errno
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32 %29)
%31 = load i32, i32* @errno
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %20
%34 = load i32, i32* %7
%35 = load i32, i32* @PPWDATA
%36 = call i64 (i32, i32, ...) @ioctl(i32 %34, i32 %35, i8* %6)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = load i32, i32* @errno
%43 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %41, i32 %42)
%44 = load i32, i32* @errno
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %33
%47 = call i32 @usleep(i32 3000)
store i8 0, i8* %6
%48 = load i32, i32* %7
%49 = load i32, i32* @PPWDATA
%50 = call i64 (i32, i32, ...) @ioctl(i32 %48, i32 %49, i8* %6)
%51 = load i32, i32* %7
%52 = load i32, i32* @PPRELEASE
%53 = call i64 (i32, i32, ...) @ioctl(i32 %51, i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %46
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = load i32, i32* @errno
%60 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %58, i32 %59)
%61 = load i32, i32* @errno
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %46
%64 = load i32, i32* %7
%65 = call i64 @close(i32 %64)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %75
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = load i32, i32* @errno
%72 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %70, i32 %71)
%73 = load i32, i32* @errno
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %63
br label %78
76: ; preds = %17
%77 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %78
78: ; preds = %76, %75
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/parport0\00"
@O_RDWR = global i32 0
@PPCLAIM = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"PPCLAIM ioctl Error : %s (%d)\0A\00"
@errno = global i32 0
@PPWDATA = global i32 0
@.str.2 = [31 x i8] c"PPWDATA ioctl Error : %s (%d)\0A\00"
@PPRELEASE = global i32 0
@.str.3 = [33 x i8] c"PPRELEASE ioctl Error : %s (%d)\0A\00"
@.str.4 = [23 x i8] c"Close Error : %s (%d)\0A\00"
@.str.5 = [8 x i8] c"trigger\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
store i8 -1, i8* %3
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call zeroext i8 @atoi(i8* %9)
store i8 %10, i8* %3
br label %11
11: ; preds = %7, %2
%12 = icmp sgt i32 %5, -1
br i1 %12, label %13, label %63
13: ; preds = %11
%14 = load i32, i32* @PPCLAIM
%15 = tail call i64 (i32, i32, ...) @ioctl(i32 %5, i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = load i32, i32* @errno
%22 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
%23 = load i32, i32* @errno
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %13
%26 = load i32, i32* @PPWDATA
%27 = call i64 (i32, i32, ...) @ioctl(i32 %5, i32 %26, i8* %3)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = load i32, i32* @errno
%34 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %32, i32 %33)
%35 = load i32, i32* @errno
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %25
%38 = call i32 @usleep(i32 3000)
store i8 0, i8* %3
%39 = load i32, i32* @PPWDATA
%40 = call i64 (i32, i32, ...) @ioctl(i32 %5, i32 %39, i8* %3)
%41 = load i32, i32* @PPRELEASE
%42 = call i64 (i32, i32, ...) @ioctl(i32 %5, i32 %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %37
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = load i32, i32* @errno
%49 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %47, i32 %48)
%50 = load i32, i32* @errno
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %37
%53 = call i64 @close(i32 %5)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = load i32, i32* @errno
%60 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %58, i32 %59)
%61 = load i32, i32* @errno
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %11
%64 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %65
65: ; preds = %52, %63
ret i32 0
}