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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int produce_item();
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ write(int, int *, int);
int main() {
  int fifo, item = 0;
  remove("myfifo");
  if (mkfifo("myfifo", 0600)) {
    printf("mkfifo: error creating named pipe");
    exit(-1);
  }
  if ((fifo = open("myfifo", O_WRONLY)) < 0) {
    printf("open: pipe doesn't exist");
    exit(-1);
  }
  while (1) {
    item = produce_item();
    write(fifo, &item, sizeof(item));
    printf("producer: %d\n", item);
  }
  close(fifo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe73(%rip),%rdi
call   1030 <remove@plt>
lea    0xe67(%rip),%rdi
mov    $0x180,%esi
call   1060 <mkfifo@plt>
cmp    $0x0,%rax
je     11c5 <main+0x55>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
lea    0xe2b(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11fe <main+0x8e>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    1203 <main+0x93>
mov    $0x0,%al
call   1070 <produce_item@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1203 <main+0x93>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe82(%rip),%rbx
mov    %rbx,%rdi
call   1030 <remove@plt>
mov    %rbx,%rdi
mov    $0x180,%esi
call   1060 <mkfifo@plt>
test   %rax,%rax
jne    11ea <main+0x7a>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
lea    0xe58(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11f3 <main+0x83>
mov    %eax,%ebx
lea    0x4(%rsp),%r14
lea    0xe83(%rip),%r15
nop
xor    %eax,%eax
call   1070 <produce_item@plt>
mov    %eax,%ebp
mov    %eax,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c0 <main+0x50>
lea    0xe16(%rip),%rdi
jmp    11fa <main+0x8a>
lea    0xe2f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"myfifo\00"
@.str.1 = [34 x i8] c"mkfifo: error creating named pipe\00"
@O_WRONLY = global i32 0
@.str.2 = [25 x i8] c"open: pipe doesn't exist\00"
@.str.3 = [14 x i8] c"producer: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = call i32 @remove(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 384)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %10
br label %18
18: ; preds = %17, %18
%19 = call i32 (...) @produce_item()
store i32 %19, i32* %3
%20 = load i32, i32* %2
%21 = call i32 @write(i32 %20, i32* %3, i32 4)
%22 = load i32, i32* %3
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %18
}

LLVM IR (-O2):
@.str = [7 x i8] c"myfifo\00"
@.str.1 = [34 x i8] c"mkfifo: error creating named pipe\00"
@O_WRONLY = global i32 0
@.str.2 = [25 x i8] c"open: pipe doesn't exist\00"
@.str.3 = [14 x i8] c"producer: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @remove(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @mkfifo(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 384)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = load i32, i32* @O_WRONLY
%11 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %9, %16
%17 = tail call i32 (...) @produce_item()
store i32 %17, i32* %1
%18 = call i32 @write(i32 %11, i32* %1, i32 4)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %16
}