#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 IEEE1284_MODE_ECP;
int IEEE1284_MODE_ECPRLE;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ PPCLAIM;
int /*<<< orphan*/ PPGETMODE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int Parport_Open(char *DeviceName) {
  int Device = -1;
  int bCurrentPortMode = 0;
  int bPortMode = IEEE1284_MODE_ECP;
  bPortMode = IEEE1284_MODE_ECPRLE;
  Device = open(DeviceName, O_RDWR);
  if (Device == -1) {
    fprintf(stderr, "ERROR: Parport_Open Can not open %s\n", DeviceName);
    return Device;
  }
  if (ioctl(Device, PPCLAIM)) {
    perror("ERROR: Parport_Open Can not claim");
    close(Device);
    return -1;
  }
  ioctl(Device, PPGETMODE, &bCurrentPortMode);
  fprintf(stderr, "ERROR: Parport_Open PPGETMODE %04Xh\n",
          (int)bCurrentPortMode);
  return Device;
}


x86 assembly (clang, -O0):
<Parport_Open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c7 <Parport_Open+0x77>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123a <Parport_Open+0xea>
mov    -0x14(%rbp),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <ioctl@plt>
cmp    $0x0,%eax
je     1203 <Parport_Open+0xb3>
lea    0xe3b(%rip),%rdi
call   1070 <perror@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123a <Parport_Open+0xea>
mov    -0x14(%rbp),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1030 <ioctl@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Parport_Open>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movl   $0x0,0x4(%rsp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11be <Parport_Open+0x6e>
mov    %eax,%ebx
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
test   %eax,%eax
jne    11e7 <Parport_Open+0x97>
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <ioctl@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x4(%rsp),%edx
lea    0xe92(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11dd <Parport_Open+0x8d>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe37(%rip),%rdi
call   1070 <perror@plt>
mov    %ebx,%edi
call   1040 <close@plt>
jmp    11d8 <Parport_Open+0x88>

LLVM IR (-O0):
@IEEE1284_MODE_ECP = global i32 0
@IEEE1284_MODE_ECPRLE = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"ERROR: Parport_Open Can not open %s\0A\00"
@PPCLAIM = global i32 0
@.str.1 = [34 x i8] c"ERROR: Parport_Open Can not claim\00"
@PPGETMODE = global i32 0
@.str.2 = [37 x i8] c"ERROR: Parport_Open PPGETMODE %04Xh\0A\00"
define i32 @Parport_Open(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* @IEEE1284_MODE_ECP
store i32 %7, i32* %6
%8 = load i32, i32* @IEEE1284_MODE_ECPRLE
store i32 %8, i32* %6
%9 = load i8*, i8** %3
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %3
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %4
store i32 %18, i32* %2
br label %36
19: ; preds = %1
%20 = load i32, i32* %4
%21 = load i32, i32* @PPCLAIM
%22 = call i32 (i32, i32, ...) @ioctl(i32 %20, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* %4
%27 = call i32 @close(i32 %26)
store i32 -1, i32* %2
br label %36
28: ; preds = %19
%29 = load i32, i32* %4
%30 = load i32, i32* @PPGETMODE
%31 = call i32 (i32, i32, ...) @ioctl(i32 %29, i32 %30, i32* %5)
%32 = load i32, i32* @stderr
%33 = load i32, i32* %5
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %4
store i32 %35, i32* %2
br label %36
36: ; preds = %28, %24, %14
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@IEEE1284_MODE_ECP = global i32 0
@IEEE1284_MODE_ECPRLE = global i32 0
@O_RDWR = global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"ERROR: Parport_Open Can not open %s\0A\00"
@PPCLAIM = global i32 0
@.str.1 = [34 x i8] c"ERROR: Parport_Open Can not claim\00"
@PPGETMODE = global i32 0
@.str.2 = [37 x i8] c"ERROR: Parport_Open PPGETMODE %04Xh\0A\00"
define i32 @Parport_Open(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %23
10: ; preds = %1
%11 = load i32, i32* @PPCLAIM
%12 = tail call i32 (i32, i32, ...) @ioctl(i32 %5, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @close(i32 %5)
br label %23
17: ; preds = %10
%18 = load i32, i32* @PPGETMODE
%19 = call i32 (i32, i32, ...) @ioctl(i32 %5, i32 %18, i32* %2)
%20 = load i32, i32* @stderr
%21 = load i32, i32* %2
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %17, %14, %7
%24 = phi i32 [ -1, %7 ], [ -1, %14 ], [ %5, %17 ]
ret i32 %24
}