#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__ ENOENT;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
scalar_t__ errno;
int /*<<< orphan*/ fatal(char *);
char *malloc(scalar_t__);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
scalar_t__ unlink(char *);
void init_fs(char *dir, char **in_path, int *out_fd) {
  char *path = malloc(strlen(dir) + 5);
  sprintf(path, "%s/out", dir);
  *out_fd = open(path, O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU);
  if (*out_fd == -1) {
    fatal("open() for out file failed");
  }
  sprintf(path, "%s/in", dir);
  if (unlink(path) && errno != ENOENT) {
    fatal("unlink()'ing in fifo failed");
  }
  *in_path = path;
}


x86 assembly (clang, -O0):
<init_fs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x5,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe64(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    0x2dfb(%rip),%rax
or     (%rax),%esi
mov    0x2e32(%rip),%rax
or     (%rax),%esi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
call   1060 <open@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    11ef <init_fs+0x8f>
lea    0xe1d(%rip),%rdi
call   1080 <fatal@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe24(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     123c <init_fs+0xdc>
mov    0x2dab(%rip),%rax
mov    (%rax),%rax
mov    0x2d91(%rip),%rcx
cmp    (%rcx),%rax
je     123c <init_fs+0xdc>
lea    0xdf1(%rip),%rdi
call   1080 <fatal@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_fs>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
lea    0x5(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe77(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1070 <sprintf@plt>
mov    0x2e5d(%rip),%rax
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e43(%rip),%rax
or     (%rax),%esi
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %eax,(%r12)
cmp    $0xffffffff,%eax
jne    11d5 <init_fs+0x75>
lea    0xe37(%rip),%rdi
call   1080 <fatal@plt>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     1216 <init_fs+0xb6>
mov    0x2dcd(%rip),%rax
mov    (%rax),%rax
mov    0x2db3(%rip),%rcx
cmp    (%rcx),%rax
je     1216 <init_fs+0xb6>
lea    0xe17(%rip),%rdi
call   1080 <fatal@plt>
mov    %rbx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s/out\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [27 x i8] c"open() for out file failed\00"
@.str.2 = [6 x i8] c"%s/in\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.3 = [28 x i8] c"unlink()'ing in fifo failed\00"
define void @init_fs(i8* %0, i8** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 5
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = load i8*, i8** %4
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %7
%16 = load i32, i32* @O_CREAT
%17 = load i32, i32* @O_WRONLY
%18 = or i32 %16, %17
%19 = load i32, i32* @O_TRUNC
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IRWXU
%22 = call i32 @open(i8* %15, i32 %20, i32 %21)
%23 = load i32*, i32** %6
store i32 %22, i32* %23
%24 = load i32*, i32** %6
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %3
%28 = call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %3
%30 = load i8*, i8** %7
%31 = load i8*, i8** %4
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %7
%34 = call i64 @unlink(i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %29
%37 = load i64, i64* @errno
%38 = load i64, i64* @ENOENT
%39 = icmp ne i64 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @fatal(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %36, %29
%43 = load i8*, i8** %7
%44 = load i8**, i8*** %5
store i8* %43, i8** %44
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s/out\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [27 x i8] c"open() for out file failed\00"
@.str.2 = [6 x i8] c"%s/in\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.3 = [28 x i8] c"unlink()'ing in fifo failed\00"
define void @init_fs(i8* %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 5
%6 = tail call i8* @malloc(i64 %5)
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @O_CREAT
%9 = load i32, i32* @O_WRONLY
%10 = or i32 %9, %8
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRWXU
%14 = tail call i32 @open(i8* %6, i32 %12, i32 %13)
store i32 %14, i32* %2
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = tail call i32 @fatal(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %3
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%20 = tail call i64 @unlink(i8* %6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %18
%23 = load i64, i64* @errno
%24 = load i64, i64* @ENOENT
%25 = icmp eq i64 %23, %24
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = tail call i32 @fatal(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %22, %18
store i8* %6, i8** %1
ret void
}