#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 */
struct lt_config_audit {
  int dummy;
};
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SYS_gettid;
char *get_notify_dir(char *);
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
scalar_t__ syscall(int /*<<< orphan*/);
int lt_fifo_create(struct lt_config_audit *cfg, char *dir) {
  int fd;
  char fifo[100];
  sprintf(fifo, "%s/fifo-%d", get_notify_dir(dir), (pid_t)syscall(SYS_gettid));
  if (-1 == mkfifo(fifo, 0666)) {
    perror("mkfifo failed");
    return -1;
  }
  if (-1 == (fd = open(fifo, O_WRONLY))) {
    perror("open fifo failed");
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<lt_fifo_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <get_notify_dir@plt>
mov    %rax,-0x88(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1040 <syscall@plt>
mov    -0x90(%rbp),%rdi
mov    -0x88(%rbp),%rdx
mov    %eax,%ecx
lea    0xe4d(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x1b6,%esi
call   1050 <mkfifo@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11ed <lt_fifo_create+0x8d>
lea    0xe2f(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <lt_fifo_create+0xcf>
lea    -0x80(%rbp),%rdi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1229 <lt_fifo_create+0xc9>
lea    0xe01(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <lt_fifo_create+0xcf>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lt_fifo_create>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rdi
call   1030 <get_notify_dir@plt>
mov    %rax,%rbx
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
call   1040 <syscall@plt>
lea    0xe79(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1080 <sprintf@plt>
mov    %r14,%rdi
mov    $0x1b6,%esi
call   1050 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     11c7 <lt_fifo_create+0x67>
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11d0 <lt_fifo_create+0x70>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe3d(%rip),%rdi
jmp    11d7 <lt_fifo_create+0x77>
lea    0xe42(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
jmp    11bf <lt_fifo_create+0x5f>

LLVM IR (-O0):
%struct.lt_config_audit = type { i32 }
@.str = [11 x i8] c"%s/fifo-%d\00"
@SYS_gettid = global i32 0
@.str.1 = [14 x i8] c"mkfifo failed\00"
@O_WRONLY = global i32 0
@.str.2 = [17 x i8] c"open fifo failed\00"
define i32 @lt_fifo_create(%struct.lt_config_audit* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.lt_config_audit*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [100 x i8]
store %struct.lt_config_audit* %0, %struct.lt_config_audit** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %5
%10 = call i8* @get_notify_dir(i8* %9)
%11 = load i32, i32* @SYS_gettid
%12 = call i64 @syscall(i32 %11)
%13 = trunc i64 %12 to i32
%14 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %13)
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%16 = call i32 @mkfifo(i8* %15, i32 438)
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
20: ; preds = %2
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%22 = load i32, i32* @O_WRONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = icmp eq i32 -1, %23
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %29
27: ; preds = %20
%28 = load i32, i32* %6
store i32 %28, i32* %3
br label %29
29: ; preds = %27, %25, %18
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.lt_config_audit = type { i32 }
@.str = [11 x i8] c"%s/fifo-%d\00"
@SYS_gettid = global i32 0
@.str.1 = [14 x i8] c"mkfifo failed\00"
@O_WRONLY = global i32 0
@.str.2 = [17 x i8] c"open fifo failed\00"
define i32 @lt_fifo_create(%struct.lt_config_audit* nocapture readnone %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @get_notify_dir(i8* %1)
%6 = load i32, i32* @SYS_gettid
%7 = tail call i64 @syscall(i32 %6)
%8 = trunc i64 %7 to i32
%9 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %8)
%10 = call i32 @mkfifo(i8* %4, i32 438)
%11 = icmp eq i32 %10, -1
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* %4, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %12, %2
%17 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %12 ]
%18 = call i32 @perror(i8* %17)
br label %19
19: ; preds = %16, %12
%20 = phi i32 [ %14, %12 ], [ -1, %16 ]
ret i32 %20
}