char *two_way_pipe_create_fifo(char *directory) {
  char sys_string[1024];
  int results;
  char fifo_filename[1024];
  if (directory && *directory) {
    sprintf(fifo_filename, "%s/fifo_%d", directory, getpid());
  } else {
    sprintf(fifo_filename, "fifo_%d", getpid());
  }
  sprintf(sys_string, "mkfifo %s", fifo_filename);
  results = system(sys_string);
  return strdup(fifo_filename);
}


x86 assembly (clang, -O0):
<two_way_pipe_create_fifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ad <two_way_pipe_create_fifo+0x6d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ad <two_way_pipe_create_fifo+0x6d>
lea    -0x820(%rbp),%rax
mov    %rax,-0x830(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x828(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x830(%rbp),%rdi
mov    -0x828(%rbp),%rdx
mov    %eax,%ecx
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    11d9 <two_way_pipe_create_fifo+0x99>
lea    -0x820(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x838(%rbp),%rdi
mov    %eax,%edx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x410(%rbp),%rdi
mov    $0x0,%al
call   1040 <system@plt>
mov    %eax,-0x414(%rbp)
lea    -0x820(%rbp),%rdi
call   1060 <strdup@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<two_way_pipe_create_fifo>:
push   %r14
push   %rbx
sub    $0x808,%rsp
test   %rdi,%rdi
je     1176 <two_way_pipe_create_fifo+0x36>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1176 <two_way_pipe_create_fifo+0x36>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe9b(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    1190 <two_way_pipe_create_fifo+0x50>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe7f(%rip),%rsi
mov    %rsp,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xe74(%rip),%rsi
lea    0x400(%rsp),%rbx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <system@plt>
mov    %r14,%rdi
call   1060 <strdup@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s/fifo_%d\00"
@.str.1 = [8 x i8] c"fifo_%d\00"
@.str.2 = [10 x i8] c"mkfifo %s\00"
define i8* @two_way_pipe_create_fifo(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca [1024 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %2
%16 = call i32 (...) @getpid()
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16)
br label %22
18: ; preds = %8, %1
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = call i32 (...) @getpid()
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %13
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%27 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %26)
store i32 %27, i32* %4
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%29 = call i8* @strdup(i8* %28)
ret i8* %29
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s/fifo_%d\00"
@.str.1 = [8 x i8] c"fifo_%d\00"
@.str.2 = [10 x i8] c"mkfifo %s\00"
define i8* @two_way_pipe_create_fifo(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 (...) @getpid()
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %11)
br label %16
13: ; preds = %7, %1
%14 = tail call i32 (...) @getpid()
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %13, %10
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%18 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* %4)
%19 = call i8* @strdup(i8* %5)
ret i8* %19
}