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

/* Variables and functions */
scalar_t__ EEXIST;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ S_ISFIFO(int /*<<< orphan*/);
scalar_t__ errno;
int mkfifo(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int unlink(char *);
int main(int argc, char **argv) {
  pid_t pid;
  int ret;
  int fd;
  char buf[1];
  struct stat statbuf;
  ret = mkfifo("/tmp/ffo", S_IRWXU);
  if (ret == -1) {
    if (errno == EEXIST && !S_ISFIFO(statbuf.st_mode)) {
      ret = unlink("/tmp/ffo");
      if (ret == -1) {
        perror("unlink");
        return -1;
      }
      ret = mkfifo("/tmp/ffo", S_IRWXU);
      if (ret == -1) {
        perror("mkfifo");
        return -1;
      }
    } else {
      perror("mkfifo");
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1050 <mkfifo@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1230 <main+0xf0>
mov    0x2e51(%rip),%rax
mov    (%rax),%rax
mov    0x2e4f(%rip),%rcx
cmp    (%rcx),%rax
jne    1213 <main+0xd3>
mov    -0x28(%rbp),%edi
call   1040 <S_ISFIFO@plt>
cmp    $0x0,%eax
jne    1213 <main+0xd3>
lea    0xe56(%rip),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11d4 <main+0x94>
lea    0xe46(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <main+0xf7>
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    0xe1c(%rip),%rdi
call   1050 <mkfifo@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    120e <main+0xce>
lea    0xe13(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <main+0xf7>
jmp    122b <main+0xeb>
lea    0xdf6(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1237 <main+0xf7>
jmp    1230 <main+0xf0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e9c(%rip),%r15
mov    (%r15),%esi
lea    0xeaa(%rip),%rdi
call   1050 <mkfifo@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
jne    11c3 <main+0x83>
mov    0x2e67(%rip),%rax
mov    (%rax),%rax
mov    0x2e65(%rip),%rcx
lea    0xe96(%rip),%r14
cmp    (%rcx),%rax
jne    11b6 <main+0x76>
call   1040 <S_ISFIFO@plt>
test   %eax,%eax
jne    11b6 <main+0x76>
lea    0xe71(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
je     11af <main+0x6f>
mov    (%r15),%esi
lea    0xe5d(%rip),%rdi
call   1050 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    11c3 <main+0x83>
jmp    11b6 <main+0x76>
lea    0xe53(%rip),%r14
mov    %r14,%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"/tmp/ffo\00"
@S_IRWXU = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [7 x i8] c"unlink\00"
@.str.2 = [7 x i8] c"mkfifo\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1 x i8]
%10 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @S_IRWXU
%12 = call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %41
15: ; preds = %2
%16 = load i64, i64* @errno
%17 = load i64, i64* @EEXIST
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @S_ISFIFO(i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %38, label %24
24: ; preds = %19
%25 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
30: ; preds = %24
%31 = load i32, i32* @S_IRWXU
%32 = call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
37: ; preds = %30
br label %40
38: ; preds = %19, %15
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
40: ; preds = %37
br label %41
41: ; preds = %40, %2
store i32 0, i32* %3
br label %42
42: ; preds = %41, %38, %35, %28
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [9 x i8] c"/tmp/ffo\00"
@S_IRWXU = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [7 x i8] c"unlink\00"
@.str.2 = [7 x i8] c"mkfifo\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @S_IRWXU
%4 = tail call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %23
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = load i64, i64* @EEXIST
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = tail call i32 @S_ISFIFO(i32 undef)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = tail call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32 %14, -1
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @S_IRWXU
%18 = tail call i32 @mkfifo(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %6, %10, %16, %13
%21 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %13 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %16 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %10 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %6 ]
%22 = tail call i32 @perror(i8* %21)
br label %23
23: ; preds = %20, %2, %16
%24 = phi i32 [ 0, %16 ], [ 0, %2 ], [ -1, %20 ]
ret i32 %24
}