#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_RDONLY;
int S_IFIFO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char s[300];
  int num, fd;
  mknod("american_maid", S_IFIFO | 0666, 0);
  printf("waiting for writers ... \n");
  fd = open("american_maid", O_RDONLY);
  printf("got a writer!\n");
  do {
    if ((num = read(fd, s, 300)) == -1)
      perror("read");
    else {
      s[num] = '\0';
      printf("\tlistener: read %d bytes: '%s'\n", num, s);
    }
  } while (num > 0);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
or     $0x1b6,%esi
lea    0xe71(%rip),%rdi
xor    %edx,%edx
call   1050 <mknod@plt>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x148(%rbp)
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x148(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x12c,%edx
call   1040 <read@plt>
mov    %eax,-0x144(%rbp)
cmp    $0xffffffff,%eax
jne    1204 <main+0xa4>
lea    0xe3d(%rip),%rdi
call   1070 <perror@plt>
jmp    122e <main+0xce>
movslq -0x144(%rbp),%rax
movb   $0x0,-0x140(%rbp,%rax,1)
mov    -0x144(%rbp),%esi
lea    -0x140(%rbp),%rdx
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1233 <main+0xd3>
cmpl   $0x0,-0x144(%rbp)
jg     11cd <main+0x6d>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x138,%rsp
mov    0x2e4c(%rip),%rax
mov    $0x1b6,%esi
or     (%rax),%esi
lea    0xe6e(%rip),%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1060 <mknod@plt>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <open@plt>
mov    %eax,%r15d
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
lea    0xe41(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x12c,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     1212 <main+0xa2>
mov    %eax,%ebp
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jg     11e0 <main+0x70>
jmp    121e <main+0xae>
lea    0xdf5(%rip),%rdi
call   1080 <perror@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"american_maid\00"
@S_IFIFO = global i32 0
@.str.1 = [26 x i8] c"waiting for writers ... \0A\00"
@O_RDONLY = global i32 0
@.str.2 = [15 x i8] c"got a writer!\0A\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [32 x i8] c"\09listener: read %d bytes: '%s'\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 ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @O_RDONLY
%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 ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %31, %2
%17 = load i32, i32* %8
%18 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 300)
store i32 %19, i32* %7
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %30
23: ; preds = %16
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 %25
store i8 0, i8* %26
%27 = load i32, i32* %7
%28 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %27, i8* %28)
br label %30
30: ; preds = %23, %21
br label %31
31: ; preds = %30
%32 = load i32, i32* %7
%33 = icmp sgt i32 %32, 0
br i1 %33, label %16, label %34
34: ; preds = %31
%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_RDONLY = global i32 0
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [32 x i8] c"\09listener: read %d bytes: '%s'\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [25 x i8] c"waiting for writers ... \00"
@str.5 = [14 x i8] c"got a writer!\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 ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* @O_RDONLY
%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 ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
br label %12
12: ; preds = %17, %2
%13 = call i32 @read(i32 %10, i8* %4, i32 300)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %22
17: ; preds = %12
%18 = sext i32 %13 to i64
%19 = getelementptr inbounds [300 x i8], [300 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %13, i8* %4)
%21 = icmp sgt i32 %13, 0
br i1 %21, label %12, label %22
22: ; preds = %17, %15
%23 = load i32, i32* @EXIT_SUCCESS
%24 = call i32 @exit(i32 %23)
unreachable
}