#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);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
size_t strlen(char *);
int /*<<< orphan*/ usleep(int);
int write_to_pipe(int, char *, size_t);
int main(int argc, char **argv) {
  if (make_pipe_node() == true) {
    int fd = create_pipe(true);
    if (fd != -1) {
      int i = 0;
      while (1) {
        usleep(1000000);
        char msg[1024];
        snprintf(msg, sizeof(msg) - 1, "%7d: Here is a message.", ++i);
        size_t msg_len = strlen(msg);
        int bytes_written = write_to_pipe(fd, msg, msg_len);
        printf("write(%s) returned %d.\n", msg, bytes_written);
      }
    }
  }
  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   1050 <make_pipe_node@plt>
cmp    $0x1,%eax
jne    123a <main+0xca>
mov    $0x1,%edi
call   1080 <create_pipe@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     1235 <main+0xc5>
movl   $0x0,-0x18(%rbp)
mov    $0xf4240,%edi
call   1090 <usleep@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x430(%rbp)
mov    %ecx,-0x18(%rbp)
mov    $0x3ff,%esi
lea    0xe1d(%rip),%rdx
call   1070 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x428(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x428(%rbp),%rdx
call   1030 <write_to_pipe@plt>
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rsi
mov    -0x42c(%rbp),%edx
lea    0xded(%rip),%rdi
call   1060 <printf@plt>
jmp    11b7 <main+0x47>
jmp    123a <main+0xca>
mov    $0x1,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
xor    %eax,%eax
call   1050 <make_pipe_node@plt>
cmp    $0x1,%eax
jne    1204 <main+0x94>
mov    $0x1,%ebx
mov    $0x1,%edi
call   1080 <create_pipe@plt>
cmp    $0xffffffff,%eax
je     1204 <main+0x94>
mov    %eax,%r15d
lea    0xe57(%rip),%r14
mov    %rsp,%rbp
lea    0xe65(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xf4240,%edi
call   1090 <usleep@plt>
mov    %rbp,%rdi
mov    $0x3ff,%esi
mov    %r14,%rdx
mov    %ebx,%ecx
call   1070 <snprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1030 <write_to_pipe@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1060 <printf@plt>
add    $0x1,%ebx
jmp    11c0 <main+0x50>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"%7d: Here is a message.\00"
@.str.1 = [24 x i8] c"write(%s) returned %d.\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 i64
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @make_pipe_node()
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %34
13: ; preds = %2
%14 = call i32 @create_pipe(i32 1)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %33
17: ; preds = %13
store i32 0, i32* %7
br label %18
18: ; preds = %17, %18
%19 = call i32 @usleep(i32 1000000)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
%23 = call i32 @snprintf(i8* %20, i32 1023, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%25 = call i64 @strlen(i8* %24)
store i64 %25, i64* %9
%26 = load i32, i32* %6
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%28 = load i64, i64* %9
%29 = call i32 @write_to_pipe(i32 %26, i8* %27, i64 %28)
store i32 %29, i32* %10
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%31 = load i32, i32* %10
%32 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %30, i32 %31)
br label %18
33: ; preds = %13
br label %34
34: ; preds = %33, %2
ret i32 1
}

LLVM IR (-O2):
@.str = [24 x i8] c"%7d: Here is a message.\00"
@.str.1 = [24 x i8] c"write(%s) returned %d.\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 %19
6: ; preds = %2
%7 = tail call i32 @create_pipe(i32 1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %19, 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, %11
%12 = phi i32 [ %14, %11 ], [ 0, %9 ]
%13 = call i32 @usleep(i32 1000000)
%14 = add nuw nsw i32 %12, 1
%15 = call i32 @snprintf(i8* %10, i32 1023, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i64 @strlen(i8* %10)
%17 = call i32 @write_to_pipe(i32 %7, i8* %10, i64 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 %17)
br label %11
19: ; preds = %6, %2
ret i32 1
}