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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe51(%rip),%rdi
xor    %edx,%edx
call   1070 <mknod@plt>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
lea    0xe2c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x148(%rbp)
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x140(%rbp),%rdi
mov    0x2ded(%rip),%rax
mov    (%rax),%edx
mov    $0x12c,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1284 <main+0x104>
mov    -0x148(%rbp),%eax
mov    %eax,-0x154(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    -0x140(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x154(%rbp),%edi
mov    -0x150(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x144(%rbp)
cmp    $0xffffffff,%eax
jne    126b <main+0xeb>
lea    0xde7(%rip),%rdi
call   1090 <perror@plt>
jmp    127f <main+0xff>
mov    -0x144(%rbp),%esi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ed <main+0x6d>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x130,%rsp
mov    0x2e2a(%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    0x2def(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
mov    %eax,%ebp
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df8(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%rdi
mov    $0x12c,%esi
call   1070 <fgets@plt>
test   %rax,%rax
jne    1214 <main+0x84>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    %rsp,%rbx
lea    0xdf0(%rip),%r14
lea    0xdef(%rip),%r15
jmp    1252 <main+0xc2>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x12c,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     1206 <main+0x76>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1230 <main+0xa0>
mov    %r14,%rdi
call   10a0 <perror@plt>
jmp    123c <main+0xac>

LLVM IR (-O0):
@.str = [14 x i8] c"american_maid\00"
@S_IFIFO = global i32 0
@.str.1 = [25 x i8] c"waiting for reader ... \0A\00"
@O_WRONLY = global i32 0
@.str.2 = [33 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"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [300 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @S_IFIFO
%10 = or i32 %9, 438
%11 = call i32 @mknod(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %10, i32 0)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %33, %2
%17 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i64 @fgets(i8* %17, i32 300, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %34
21: ; preds = %16
%22 = load i32, i32* %8
%23 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%24 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @write(i32 %22, i8* %23, i32 %25)
store i32 %26, i32* %7
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %33
30: ; preds = %21
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %28
br label %16
34: ; preds = %16
%35 = load i32, i32* @EXIT_SUCCESS
%36 = call i32 @exit(i32 %35)
unreachable
}

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"
@EXIT_SUCCESS = global i32 0
@str = [24 x i8] c"waiting for reader ... \00"
@str.5 = [32 x i8] c"got a reader -- type some stuff\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [300 x i8]
%4 = getelementptr inbounds [300 x i8], [300 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @S_IFIFO
%6 = or i32 %5, 438
%7 = tail call i32 @mknod(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* @O_WRONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
%12 = load i32, i32* @stdin
%13 = call i64 @fgets(i8* %4, i32 300, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %2, %23
%16 = call i32 @strlen(i8* %4)
%17 = call i32 @write(i32 %10, i8* %4, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %23
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %17)
br label %23
23: ; preds = %21, %19
%24 = load i32, i32* @stdin
%25 = call i64 @fgets(i8* %4, i32 300, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %15
27: ; preds = %23, %2
%28 = load i32, i32* @EXIT_SUCCESS
%29 = call i32 @exit(i32 %28)
unreachable
}