#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 */
scalar_t__ EEXIST;
int /*<<< orphan*/ O_RDWR;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ unlink(char *);
int main(void) {
  if (mkfifo("/tmp/ser1", S_IRUSR | S_IWUSR | S_IWGRP) == -1 && errno != EEXIST)
    exit(-1);
  int sfd = open("/tmp/ser1", O_RDWR);
  if (sfd < 0)
    exit(-2);
  printf("done\n");
  close(sfd);
  unlink("/tmp/ser1");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e59(%rip),%rax
or     (%rax),%esi
mov    0x2e58(%rip),%rax
or     (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1060 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    11c3 <main+0x63>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%rax
je     11c3 <main+0x63>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
lea    0xe2d(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11ef <main+0x8f>
mov    $0xfffffffe,%edi
call   1080 <exit@plt>
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
lea    0xdf6(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e50(%rip),%rax
mov    0x2e69(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e66(%rip),%rax
or     (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1060 <mkfifo@plt>
cmp    $0xffffffff,%eax
jne    11a3 <main+0x43>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%rax
jne    11eb <main+0x8b>
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
lea    0xe4d(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11e1 <main+0x81>
mov    %eax,%ebx
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xe28(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    $0xfffffffe,%edi
call   1080 <exit@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/tmp/ser1\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IWGRP = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"done\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @S_IRUSR
%4 = load i32, i32* @S_IWUSR
%5 = or i32 %3, %4
%6 = load i32, i32* @S_IWGRP
%7 = or i32 %5, %6
%8 = call i32 @mkfifo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = load i64, i64* @errno
%12 = load i64, i64* @EEXIST
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %10, %0
%17 = load i32, i32* @O_RDWR
%18 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @exit(i32 -2)
unreachable
23: ; preds = %16
%24 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* %2
%26 = call i32 @close(i32 %25)
%27 = call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"/tmp/ser1\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IWGRP = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@O_RDWR = global i32 0
@str = [5 x i8] c"done\00"
define i32 @main() {
%1 = load i32, i32* @S_IRUSR
%2 = load i32, i32* @S_IWUSR
%3 = or i32 %2, %1
%4 = load i32, i32* @S_IWGRP
%5 = or i32 %3, %4
%6 = tail call i32 @mkfifo(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = load i64, i64* @errno
%10 = load i64, i64* @EEXIST
%11 = icmp eq i64 %9, %10
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %8, %0
%15 = load i32, i32* @O_RDWR
%16 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @exit(i32 -2)
unreachable
20: ; preds = %14
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 @close(i32 %16)
%23 = tail call i32 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
ret i32 0
}