#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 S_IFIFO;
int /*<<< orphan*/ feof(int /*<<< orphan*/);
scalar_t__ gets(char *);
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(void) {
  char s[300];
  int num, fd;
  mknod("american_maid", S_IFIFO | 0666, 0);
  printf("waiting for readers...\n");
  fd = open("american_maid", O_WRONLY);
  printf("got a reader--type some stuff\n");
  while (gets(s), !feof(stdin)) {
    if ((num = write(fd, s, strlen(s))) == -1)
      perror("write");
    else
      printf("speak: wrote %d bytes\n", num);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe58(%rip),%rdi
xor    %edx,%edx
call   1070 <mknod@plt>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
lea    0xe33(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x138(%rbp)
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x130(%rbp),%rdi
call   1080 <gets@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1215 <main+0x95>
jmp    1288 <main+0x108>
mov    -0x138(%rbp),%eax
mov    %eax,-0x144(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x144(%rbp),%edi
mov    -0x140(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x134(%rbp)
cmp    $0xffffffff,%eax
jne    126f <main+0xef>
lea    0xde0(%rip),%rdi
call   10a0 <perror@plt>
jmp    1283 <main+0x103>
mov    -0x134(%rbp),%esi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e6 <main+0x66>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x130,%rsp
mov    0x2e32(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
lea    0xe4c(%rip),%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1080 <mknod@plt>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
mov    %eax,%ebp
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1090 <gets@plt>
mov    0x2df0(%rip),%r12
mov    (%r12),%edi
call   1070 <feof@plt>
test   %eax,%eax
je     1217 <main+0x87>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbx
lea    0xded(%rip),%r14
lea    0xdec(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     126c <main+0xdc>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1090 <gets@plt>
mov    (%r12),%edi
call   1070 <feof@plt>
test   %eax,%eax
je     1230 <main+0xa0>
jmp    1205 <main+0x75>
mov    %r14,%rdi
call   10b0 <perror@plt>
jmp    1255 <main+0xc5>

LLVM IR (-O0):
@.str = [14 x i8] c"american_maid\00"
@S_IFIFO = global i32 0
@.str.1 = [24 x i8] c"waiting for readers...\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [31 x i8] c"got a reader--type some stuff\0A\00"
@stdin = global i32 0
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [23 x i8] c"speak: wrote %d bytes\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [300 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @S_IFIFO
%6 = or i32 %5, 438
%7 = call i32 @mknod(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @O_WRONLY
%10 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %4
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %31, %0
%13 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%14 = call i64 @gets(i8* %13)
%15 = load i32, i32* @stdin
%16 = call i32 @feof(i32 %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %32
19: ; preds = %12
%20 = load i32, i32* %4
%21 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%22 = getelementptr inbounds [300 x i8], [300 x i8]* %2, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @write(i32 %20, i8* %21, i32 %23)
store i32 %24, i32* %3
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %31
28: ; preds = %19
%29 = load i32, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28, %26
br label %12
32: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"american_maid\00"
@S_IFIFO = global i32 0
@O_WRONLY = global i32 0
@stdin = global i32 0
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [23 x i8] c"speak: wrote %d bytes\0A\00"
@str = [23 x i8] c"waiting for readers...\00"
@str.5 = [30 x i8] c"got a reader--type some stuff\00"
define i32 @main() {
%1 = alloca [300 x i8]
%2 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @S_IFIFO
%4 = or i32 %3, 438
%5 = tail call i32 @mknod(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4, i32 0)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
%10 = call i64 @gets(i8* %2)
%11 = load i32, i32* @stdin
%12 = call i32 @feof(i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %0, %22
%15 = call i32 @strlen(i8* %2)
%16 = call i32 @write(i32 %8, i8* %2, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %22
20: ; preds = %14
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %16)
br label %22
22: ; preds = %20, %18
%23 = call i64 @gets(i8* %2)
%24 = load i32, i32* @stdin
%25 = call i32 @feof(i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %14, label %27
27: ; preds = %22, %0
ret i32 0
}