#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 */
scalar_t__ EEXIST;
int O_NONBLOCK;
int O_RDONLY;
scalar_t__ errno;
int mkfifo(char *, int);
int open(char *, int);
int fifo_prepare(const char *prompt) {
  int ret;
  ret = mkfifo("/lib/cryptsetup/passfifo", 0600);
  if (ret && errno != EEXIST)
    return -1;
  return open("/lib/cryptsetup/passfifo", O_RDONLY | O_NONBLOCK);
}


x86 assembly (clang, -O0):
<fifo_prepare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xecd(%rip),%rdi
mov    $0x180,%esi
call   1030 <mkfifo@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1170 <fifo_prepare+0x50>
mov    0x2e77(%rip),%rax
mov    (%rax),%rax
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
je     1170 <fifo_prepare+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <fifo_prepare+0x71>
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
or     (%rax),%esi
lea    0xe77(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fifo_prepare>:
push   %rax
lea    0xed8(%rip),%rdi
mov    $0x180,%esi
call   1030 <mkfifo@plt>
test   %eax,%eax
je     114c <fifo_prepare+0x2c>
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%rax
jne    116b <fifo_prepare+0x4b>
mov    0x2e8d(%rip),%rax
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe9b(%rip),%rdi
pop    %rax
jmp    1040 <open@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/lib/cryptsetup/passfifo\00"
@errno = global i64 0
@EEXIST = global i64 0
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @fifo_prepare(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 @mkfifo(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 384)
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i64, i64* @errno
%10 = load i64, i64* @EEXIST
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 -1, i32* %2
br label %18
13: ; preds = %8, %1
%14 = load i32, i32* @O_RDONLY
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %14, %15
%17 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %2
br label %18
18: ; preds = %13, %12
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@.str = [25 x i8] c"/lib/cryptsetup/passfifo\00"
@errno = global i64 0
@EEXIST = global i64 0
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @fifo_prepare(i8* nocapture readnone %0) {
%2 = tail call i32 @mkfifo(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 384)
%3 = icmp eq i32 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = load i64, i64* @errno
%6 = load i64, i64* @EEXIST
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %13
8: ; preds = %4, %1
%9 = load i32, i32* @O_RDONLY
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %4, %8
%14 = phi i32 [ %12, %8 ], [ -1, %4 ]
ret i32 %14
}