#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_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, char, int);
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ remove(char *);
int main(int argc, char *argv[]) {
  int fd, len;
  char buffer[50];
  if (mkfifo("/tmp/my_pype", 0777)) {
    perror("mkfifo");
    return 1;
  }
  printf("%s is created\n", "/tmp/my_pype");
  if ((fd = open("/tmp/my_pype", O_RDONLY)) <= 0) {
    perror("open");
    return 1;
  }
  printf("%s is opened\n", "/tmp/my_pype");
  do {
    memset(buffer, '\0', 50);
    if ((len = read(fd, buffer, 50 - 1)) <= 0) {
      perror("read");
      close(fd);
      remove("/tmp/my_pype");
      return 0;
    }
    printf("Incoming message (%d): %s\n", len, buffer);
  } while (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
mov    $0x1ff,%esi
call   1080 <mkfifo@plt>
cmp    $0x0,%rax
je     11c9 <main+0x49>
lea    0xe55(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a9 <main+0x129>
lea    0xe44(%rip),%rdi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
lea    0xe12(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jg     1217 <main+0x97>
lea    0xe1d(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a9 <main+0x129>
lea    0xe0a(%rip),%rdi
lea    0xddb(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1050 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x31,%edx
call   1070 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jg     1285 <main+0x105>
lea    0xdd6(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    0xd8c(%rip),%rdi
call   1030 <remove@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a9 <main+0x129>
mov    -0x18(%rbp),%esi
lea    -0x50(%rbp),%rdx
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    122c <main+0xac>
jmp    12a9 <main+0x129>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xe6f(%rip),%rdi
mov    $0x1ff,%esi
call   1080 <mkfifo@plt>
test   %rax,%rax
jne    11d6 <main+0x56>
lea    0xe6d(%rip),%rdi
lea    0xe52(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
test   %eax,%eax
jg     11ed <main+0x6d>
lea    0xe4f(%rip),%rdi
jmp    11dd <main+0x5d>
lea    0xe30(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%r14d
jmp    1290 <main+0x110>
mov    %eax,%ebp
lea    0xe32(%rip),%rdi
lea    0xe03(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x31,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1271 <main+0xf1>
lea    0xe08(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x31,%edx
call   1070 <read@plt>
test   %eax,%eax
jg     1240 <main+0xc0>
lea    0xdbe(%rip),%rdi
call   10a0 <perror@plt>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xd75(%rip),%rdi
call   1030 <remove@plt>
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/my_pype\00"
@.str.1 = [7 x i8] c"mkfifo\00"
@.str.2 = [15 x i8] c"%s is created\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [5 x i8] c"open\00"
@.str.4 = [14 x i8] c"%s is opened\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [27 x i8] c"Incoming message (%d): %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [50 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i64 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 511)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %39
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %6
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %39
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %38, %20
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%24 = call i32 @memset(i8* %23, i8 signext 0, i32 50)
%25 = load i32, i32* %6
%26 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%27 = call i32 @read(i32 %25, i8* %26, i32 49)
store i32 %27, i32* %7
%28 = icmp sle i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
%33 = call i32 @remove(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %39
34: ; preds = %22
%35 = load i32, i32* %7
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %35, i8* %36)
br label %38
38: ; preds = %34
br i1 true, label %22, label %39
39: ; preds = %11, %18, %29, %38
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/my_pype\00"
@.str.1 = [7 x i8] c"mkfifo\00"
@.str.2 = [15 x i8] c"%s is created\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [5 x i8] c"open\00"
@.str.4 = [14 x i8] c"%s is opened\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [27 x i8] c"Incoming message (%d): %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 511)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %31
9: ; preds = %2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %31
16: ; preds = %9
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @memset(i8* %4, i8 signext 0, i32 50)
%19 = call i32 @read(i32 %12, i8* %4, i32 49)
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %25
21: ; preds = %25, %16
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 @close(i32 %12)
%24 = call i32 @remove(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %31
25: ; preds = %16, %25
%26 = phi i32 [ %29, %25 ], [ %19, %16 ]
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i32 %26, i8* %4)
%28 = call i32 @memset(i8* %4, i8 signext 0, i32 50)
%29 = call i32 @read(i32 %12, i8* %4, i32 49)
%30 = icmp slt i32 %29, 1
br i1 %30, label %21, label %25
31: ; preds = %21, %14, %7
%32 = phi i32 [ 1, %7 ], [ 1, %14 ], [ 0, %21 ]
ret i32 %32
}