#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int S_IRUSR;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISFIFO(int /*<<< orphan*/);
int S_IWUSR;
int /*<<< orphan*/ ltr_int_log_message(char *);
int /*<<< orphan*/ ltr_int_my_perror(char *);
scalar_t__ mkfifo(char const *, int);
scalar_t__ rmdir(char const *);
scalar_t__ stat(char const *, struct stat *);
scalar_t__ unlink(char const *);
bool ltr_int_make_fifo(const char *name) {
  if (name == NULL) {
    ltr_int_log_message("Name must be set! (NULL passed)\n");
  }
  struct stat info;
  if (stat(name, &info) == 0) {
    if (S_ISFIFO(info.st_mode)) {
      ltr_int_log_message("Fifo exists already!\n");
      return true;
    } else if (S_ISDIR(info.st_mode)) {
      ltr_int_log_message("Directory exists! Will try to remove it.\n");
      if (rmdir(name) != 0) {
        ltr_int_my_perror("rmdir");
        return false;
      }
    } else {
      ltr_int_log_message(
          "File exists, but it is not a fifo! Will try to remove it.\n");
      if (unlink(name) != 0) {
        ltr_int_my_perror("unlink");
        return false;
      }
    }
  }
  if (mkfifo(name, S_IRUSR | S_IWUSR) != 0) {
    ltr_int_my_perror("mkfifo");
    return false;
  }
  ltr_int_log_message("Fifo created!\n");
  return true;
}


x86 assembly (clang, -O0):
<ltr_int_make_fifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a3 <ltr_int_make_fifo+0x23>
lea    0xe62(%rip),%rdi
call   1040 <ltr_int_log_message@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
jne    1278 <ltr_int_make_fifo+0xf8>
mov    -0x18(%rbp),%edi
call   1060 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     11e4 <ltr_int_make_fifo+0x64>
lea    0xe4e(%rip),%rdi
call   1040 <ltr_int_log_message@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c8 <ltr_int_make_fifo+0x148>
mov    -0x18(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1232 <ltr_int_make_fifo+0xb2>
lea    0xe3a(%rip),%rdi
call   1040 <ltr_int_log_message@plt>
mov    -0x10(%rbp),%rdi
call   1050 <rmdir@plt>
cmp    $0x0,%rax
je     122d <ltr_int_make_fifo+0xad>
lea    0xe45(%rip),%rdi
call   10a0 <ltr_int_my_perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c8 <ltr_int_make_fifo+0x148>
jmp    126e <ltr_int_make_fifo+0xee>
lea    0xe2e(%rip),%rdi
call   1040 <ltr_int_log_message@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     1269 <ltr_int_make_fifo+0xe9>
lea    0xe4a(%rip),%rdi
call   10a0 <ltr_int_my_perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c8 <ltr_int_make_fifo+0x148>
jmp    126e <ltr_int_make_fifo+0xee>
jmp    1273 <ltr_int_make_fifo+0xf3>
jmp    1278 <ltr_int_make_fifo+0xf8>
mov    -0x10(%rbp),%rdi
mov    0x2d55(%rip),%rax
mov    (%rax),%esi
mov    0x2d5c(%rip),%rax
or     (%rax),%esi
call   1080 <mkfifo@plt>
cmp    $0x0,%rax
je     12b5 <ltr_int_make_fifo+0x135>
lea    0xe05(%rip),%rdi
call   10a0 <ltr_int_my_perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c8 <ltr_int_make_fifo+0x148>
lea    0xdf4(%rip),%rdi
call   1040 <ltr_int_log_message@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltr_int_make_fifo>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1199 <ltr_int_make_fifo+0x19>
lea    0xe6c(%rip),%rdi
call   1040 <ltr_int_log_message@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <stat@plt>
test   %rax,%rax
je     11da <ltr_int_make_fifo+0x5a>
mov    0x2e26(%rip),%rax
mov    0x2e2f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1080 <mkfifo@plt>
test   %rax,%rax
je     11f1 <ltr_int_make_fifo+0x71>
lea    0xed8(%rip),%rdi
call   10a0 <ltr_int_my_perror@plt>
xor    %eax,%eax
jmp    1202 <ltr_int_make_fifo+0x82>
mov    0x8(%rsp),%edi
call   1060 <S_ISFIFO@plt>
test   %rax,%rax
je     1208 <ltr_int_make_fifo+0x88>
lea    0xe32(%rip),%rdi
jmp    11f8 <ltr_int_make_fifo+0x78>
lea    0xeb8(%rip),%rdi
call   1040 <ltr_int_log_message@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     123c <ltr_int_make_fifo+0xbc>
lea    0xe1a(%rip),%rdi
call   1040 <ltr_int_log_message@plt>
mov    %rbx,%rdi
call   1050 <rmdir@plt>
test   %rax,%rax
je     11ab <ltr_int_make_fifo+0x2b>
lea    0xe27(%rip),%rdi
jmp    11d1 <ltr_int_make_fifo+0x51>
lea    0xe24(%rip),%rdi
call   1040 <ltr_int_log_message@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     11ab <ltr_int_make_fifo+0x2b>
lea    0xe42(%rip),%rdi
jmp    11d1 <ltr_int_make_fifo+0x51>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [33 x i8] c"Name must be set! (NULL passed)\0A\00"
@.str.1 = [22 x i8] c"Fifo exists already!\0A\00"
@.str.2 = [42 x i8] c"Directory exists! Will try to remove it.\0A\00"
@.str.3 = [6 x i8] c"rmdir\00"
@.str.4 = [59 x i8] c"File exists, but it is not a fifo! Will try to remove it.\0A\00"
@.str.5 = [7 x i8] c"unlink\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.6 = [7 x i8] c"mkfifo\00"
@.str.7 = [15 x i8] c"Fifo created!\0A\00"
define i32 @ltr_int_make_fifo(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @ltr_int_log_message(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = load i8*, i8** %3
%11 = call i64 @stat(i8* %10, %struct.stat* %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %43
13: ; preds = %9
%14 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i64 @S_ISFIFO(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @ltr_int_log_message(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %54
20: ; preds = %13
%21 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @S_ISDIR(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = call i32 @ltr_int_log_message(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %3
%28 = call i64 @rmdir(i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @ltr_int_my_perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %54
32: ; preds = %25
br label %41
33: ; preds = %20
%34 = call i32 @ltr_int_log_message(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
%35 = load i8*, i8** %3
%36 = call i64 @unlink(i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @ltr_int_my_perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %2
br label %54
40: ; preds = %33
br label %41
41: ; preds = %40, %32
br label %42
42: ; preds = %41
br label %43
43: ; preds = %42, %9
%44 = load i8*, i8** %3
%45 = load i32, i32* @S_IRUSR
%46 = load i32, i32* @S_IWUSR
%47 = or i32 %45, %46
%48 = call i64 @mkfifo(i8* %44, i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = call i32 @ltr_int_my_perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %2
br label %54
52: ; preds = %43
%53 = call i32 @ltr_int_log_message(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %2
br label %54
54: ; preds = %52, %50, %38, %30, %18
%55 = load i32, i32* %2
ret i32 %55
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [33 x i8] c"Name must be set! (NULL passed)\0A\00"
@.str.1 = [22 x i8] c"Fifo exists already!\0A\00"
@.str.2 = [42 x i8] c"Directory exists! Will try to remove it.\0A\00"
@.str.3 = [6 x i8] c"rmdir\00"
@.str.4 = [59 x i8] c"File exists, but it is not a fifo! Will try to remove it.\0A\00"
@.str.5 = [7 x i8] c"unlink\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.6 = [7 x i8] c"mkfifo\00"
@.str.7 = [15 x i8] c"Fifo created!\0A\00"
define i32 @ltr_int_make_fifo(i8* %0) {
%2 = alloca %struct.stat
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @ltr_int_log_message(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = bitcast %struct.stat* %2 to i8*
%8 = call i64 @stat(i8* %0, %struct.stat* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %33
10: ; preds = %6
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @S_ISFIFO(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = call i32 @ltr_int_log_message(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %43
17: ; preds = %10
%18 = load i32, i32* %11
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %17
%22 = call i32 @ltr_int_log_message(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%23 = call i64 @rmdir(i8* %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = call i32 @ltr_int_my_perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %43
27: ; preds = %17
%28 = call i32 @ltr_int_log_message(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0))
%29 = call i64 @unlink(i8* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = call i32 @ltr_int_my_perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %43
33: ; preds = %27, %21, %6
%34 = load i32, i32* @S_IRUSR
%35 = load i32, i32* @S_IWUSR
%36 = or i32 %35, %34
%37 = call i64 @mkfifo(i8* %0, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %33
%40 = call i32 @ltr_int_my_perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %43
41: ; preds = %33
%42 = call i32 @ltr_int_log_message(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0))
br label %43
43: ; preds = %41, %39, %31, %25, %15
%44 = phi i32 [ 1, %15 ], [ 0, %25 ], [ 0, %39 ], [ 1, %41 ], [ 0, %31 ]
ret i32 %44
}