#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*/ _IO(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
char *get_talpa_pedevice();
int ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int pe_init(void) {
  int rc;
  int fd;
  char *devname;
  devname = get_talpa_pedevice();
  if (!devname) {
    return -1;
  }
  fd = open(devname, O_RDWR);
  free(devname);
  if (fd < 0) {
    return -1;
  }
  rc = ioctl(fd, _IO(0xfe, 0));
  if (rc < 0) {
    close(fd);
    return -1;
  }
  rc = ioctl(fd, _IO(0xfe, 1));
  if (rc < 0) {
    close(fd);
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<pe_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <get_talpa_pedevice@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118a <pe_init+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <pe_init+0xe1>
mov    -0x18(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0xc(%rbp)
jge    11be <pe_init+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <pe_init+0xe1>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xfe,%edi
xor    %esi,%esi
call   1050 <_IO@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1060 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11fb <pe_init+0x9b>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <pe_init+0xe1>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0xfe,%edi
mov    $0x1,%esi
call   1050 <_IO@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
call   1060 <ioctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    123b <pe_init+0xdb>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <pe_init+0xe1>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pe_init>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <get_talpa_pedevice@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11d9 <pe_init+0x79>
mov    %rax,%rbx
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
js     11d9 <pe_init+0x79>
mov    $0xfe,%edi
xor    %esi,%esi
call   1050 <_IO@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <ioctl@plt>
test   %eax,%eax
js     11d2 <pe_init+0x72>
mov    $0xfe,%edi
mov    $0x1,%esi
call   1050 <_IO@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <ioctl@plt>
test   %eax,%eax
js     11d2 <pe_init+0x72>
mov    %ebp,%r14d
jmp    11d9 <pe_init+0x79>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
define i32 @pe_init() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = call i8* (...) @get_talpa_pedevice()
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
store i32 -1, i32* %1
br label %38
9: ; preds = %0
%10 = load i8*, i8** %4
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %3
%13 = load i8*, i8** %4
%14 = call i32 @free(i8* %13)
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %9
store i32 -1, i32* %1
br label %38
18: ; preds = %9
%19 = load i32, i32* %3
%20 = call i32 @_IO(i32 254, i32 0)
%21 = call i32 @ioctl(i32 %19, i32 %20)
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
store i32 -1, i32* %1
br label %38
27: ; preds = %18
%28 = load i32, i32* %3
%29 = call i32 @_IO(i32 254, i32 1)
%30 = call i32 @ioctl(i32 %28, i32 %29)
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = load i32, i32* %3
%35 = call i32 @close(i32 %34)
store i32 -1, i32* %1
br label %38
36: ; preds = %27
%37 = load i32, i32* %3
store i32 %37, i32* %1
br label %38
38: ; preds = %36, %33, %24, %17, %8
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@O_RDWR = global i32 0
define i32 @pe_init() {
%1 = tail call i8* (...) @get_talpa_pedevice()
%2 = icmp eq i8* %1, null
br i1 %2, label %18, label %3
3: ; preds = %0
%4 = load i32, i32* @O_RDWR
%5 = tail call i32 @open(i8* %1, i32 %4)
%6 = tail call i32 @free(i8* %1)
%7 = icmp slt i32 %5, 0
br i1 %7, label %18, label %8
8: ; preds = %3
%9 = tail call i32 @_IO(i32 254, i32 0)
%10 = tail call i32 @ioctl(i32 %5, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = tail call i32 @_IO(i32 254, i32 1)
%14 = tail call i32 @ioctl(i32 %5, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12, %8
%17 = tail call i32 @close(i32 %5)
br label %18
18: ; preds = %16, %12, %3, %0
%19 = phi i32 [ -1, %0 ], [ -1, %3 ], [ %5, %12 ], [ -1, %16 ]
ret i32 %19
}