#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 */
int /*<<< orphan*/ O_WRONLY;
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ unlink(char *);
int cpipe(char *name) {
  int fd = -1;
  printf("%s make pipe\n", name);
  unlink(name);
  if (mkfifo(name, 0666) == -1) {
    perror("mkfifo");
  }
  printf("%s open pipe\n", name);
  if ((fd = open(name, O_WRONLY)) == -1) {
    perror("open");
  }
  printf("%s opend pipe\n", name);
  return fd;
}


x86 assembly (clang, -O0):
<cpipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1b6,%esi
call   1050 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    119f <cpipe+0x4f>
lea    0xe74(%rip),%rdi
call   1070 <perror@plt>
mov    -0x8(%rbp),%rsi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11d9 <cpipe+0x89>
lea    0xe4f(%rip),%rdi
call   1070 <perror@plt>
mov    -0x8(%rbp),%rsi
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpipe>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xea3(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %rbx,%rdi
mov    $0x1b6,%esi
call   1050 <mkfifo@plt>
cmp    $0xffffffff,%eax
je     11be <cpipe+0x6e>
lea    0xe8f(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11cc <cpipe+0x7c>
lea    0xe7b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe49(%rip),%rdi
call   1070 <perror@plt>
jmp    117f <cpipe+0x2f>
lea    0xe50(%rip),%rdi
call   1070 <perror@plt>
jmp    11a6 <cpipe+0x56>

LLVM IR (-O0):
@.str = [14 x i8] c"%s make pipe\0A\00"
@.str.1 = [7 x i8] c"mkfifo\00"
@.str.2 = [14 x i8] c"%s open pipe\0A\00"
@O_WRONLY = global i32 0
@.str.3 = [5 x i8] c"open\00"
@.str.4 = [15 x i8] c"%s opend pipe\0A\00"
define i32 @cpipe(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
%4 = load i8*, i8** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = load i8*, i8** %2
%7 = call i32 @unlink(i8* %6)
%8 = load i8*, i8** %2
%9 = call i32 @mkfifo(i8* %8, i32 438)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = load i8*, i8** %2
%15 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %2
%17 = load i32, i32* @O_WRONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %3
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %13
%23 = load i8*, i8** %2
%24 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [14 x i8] c"%s make pipe\0A\00"
@.str.1 = [7 x i8] c"mkfifo\00"
@.str.2 = [14 x i8] c"%s open pipe\0A\00"
@O_WRONLY = global i32 0
@.str.3 = [5 x i8] c"open\00"
@.str.4 = [15 x i8] c"%s opend pipe\0A\00"
define i32 @cpipe(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32 @unlink(i8* %0)
%4 = tail call i32 @mkfifo(i8* %0, i32 438)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%10 = load i32, i32* @O_WRONLY
%11 = tail call i32 @open(i8* %0, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %0)
ret i32 %11
}