#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*/ msg;

/* Variables and functions */
int create_pipe(int);
int make_pipe_node();
int /*<<< orphan*/ printf(char *, char *);
int read_from_pipe(int, char *, int);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  if (make_pipe_node() == true) {
    int fd = create_pipe(false);
    if (fd != -1) {
      int i = 0;
      while (1) {
        usleep(100000);
        char msg[1024];
        int bytes_read = read_from_pipe(fd, msg, sizeof(msg));
        if (bytes_read > 0) {
          msg[bytes_read] = 0;
          printf("%s\n", msg);
        }
      }
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <make_pipe_node@plt>
cmp    $0x1,%eax
jne    11f1 <main+0xa1>
xor    %edi,%edi
call   1060 <create_pipe@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11ec <main+0x9c>
movl   $0x0,-0x18(%rbp)
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read_from_pipe@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jle    11e7 <main+0x97>
movslq -0x424(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
jmp    1194 <main+0x44>
jmp    11f1 <main+0xa1>
mov    $0x1,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
xor    %eax,%eax
call   1030 <make_pipe_node@plt>
cmp    $0x1,%eax
jne    11b0 <main+0x60>
xor    %edi,%edi
call   1060 <create_pipe@plt>
cmp    $0xffffffff,%eax
je     11b0 <main+0x60>
mov    %eax,%ebx
mov    %rsp,%r14
lea    0xe80(%rip),%r15
mov    $0x186a0,%edi
call   1070 <usleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1050 <read_from_pipe@plt>
test   %eax,%eax
jle    1180 <main+0x30>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
jmp    1180 <main+0x30>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%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 [1024 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (...) @make_pipe_node()
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %32
12: ; preds = %2
%13 = call i32 @create_pipe(i32 0)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %31
16: ; preds = %12
store i32 0, i32* %7
br label %17
17: ; preds = %16, %30
%18 = call i32 @usleep(i32 100000)
%19 = load i32, i32* %6
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%21 = call i32 @read_from_pipe(i32 %19, i8* %20, i32 1024)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %26
store i8 0, i8* %27
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %24, %17
br label %17
31: ; preds = %12
br label %32
32: ; preds = %31, %2
ret i32 1
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32 (...) @make_pipe_node()
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %20
6: ; preds = %2
%7 = tail call i32 @create_pipe(i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %20, label %9
9: ; preds = %6
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %11
11: ; preds = %9, %19
%12 = call i32 @usleep(i32 100000)
%13 = call i32 @read_from_pipe(i32 %7, i8* %10, i32 1024)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = zext i32 %13 to i64
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %19
19: ; preds = %15, %11
br label %11
20: ; preds = %6, %2
ret i32 1
}