#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int load_pid_file(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pipe_init(pid_t *manage) {
  int fd;
  assert(manage != NULL);
  *manage = load_pid_file("manage.pid");
  if (*manage == -1) {
    perror("Could not load pid file");
    return -1;
  }
  fd = open(".perfect_numbers", O_RDONLY);
  if (fd == -1) {
    perror("Could not open FIFO");
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<pipe_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
lea    0xe9b(%rip),%rdi
call   1040 <load_pid_file@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    1197 <pipe_init+0x57>
lea    0xe85(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <pipe_init+0x97>
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0xe7c(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11d1 <pipe_init+0x91>
lea    0xe74(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <pipe_init+0x97>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipe_init>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
lea    0xea7(%rip),%rdi
call   1040 <load_pid_file@plt>
mov    %eax,(%rbx)
cmp    $0xffffffff,%eax
je     1181 <pipe_init+0x41>
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xeae(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     118a <pipe_init+0x4a>
pop    %rbx
ret
lea    0xe83(%rip),%rdi
jmp    1191 <pipe_init+0x51>
lea    0xea3(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"manage.pid\00"
@.str.1 = [24 x i8] c"Could not load pid file\00"
@.str.2 = [17 x i8] c".perfect_numbers\00"
@O_RDONLY = global i32 0
@.str.3 = [20 x i8] c"Could not open FIFO\00"
define i32 @pipe_init(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = call i32 @load_pid_file(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = load i32*, i32** %3
store i32 %9, i32* %10
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %25
16: ; preds = %1
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %17)
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %25
23: ; preds = %16
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %21, %14
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [11 x i8] c"manage.pid\00"
@.str.1 = [24 x i8] c"Could not load pid file\00"
@.str.2 = [17 x i8] c".perfect_numbers\00"
@O_RDONLY = global i32 0
@.str.3 = [20 x i8] c"Could not open FIFO\00"
define i32 @pipe_init(i32* writeonly %0) {
%2 = icmp ne i32* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @load_pid_file(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 %5, i32* %0
%6 = icmp eq i32 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %7, %1
%12 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %1 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %7 ]
%13 = tail call i32 @perror(i8* %12)
br label %14
14: ; preds = %11, %7
%15 = phi i32 [ %9, %7 ], [ -1, %11 ]
ret i32 %15
}