#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_WRONLY;
int /*<<< orphan*/ close(int);
int getpid();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int fd, messagelen, i;
  char message[100];
  do {
    fd = open("/tmp/myfifo", O_WRONLY);
    if (fd == -1)
      sleep(1);
  } while (fd == -1);
  for (i = 1; i <= 3; i++) {
    sprintf(message, "Hello no. %d from process %d\n", i, getpid());
    messagelen = strlen(message) + 1;
    write(fd, message, messagelen);
    sleep(3);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0xe6e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11ae <main+0x3e>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    11b3 <main+0x43>
cmpl   $0xffffffff,-0x8(%rbp)
je     1182 <main+0x12>
movl   $0x1,-0x10(%rbp)
cmpl   $0x3,-0x10(%rbp)
jg     123a <main+0xca>
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x90(%rbp),%rdi
mov    -0x84(%rbp),%edx
mov    %eax,%ecx
lea    0xe0d(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
mov    $0x3,%edi
call   1090 <sleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c4 <main+0x54>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    0x2e58(%rip),%r15
mov    (%r15),%esi
lea    0xe76(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11bc <main+0x4c>
lea    0xe63(%rip),%r14
nopl   (%rax)
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11a0 <main+0x30>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe42(%rip),%r15
mov    %rsp,%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %eax,%ecx
call   1080 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <write@plt>
mov    $0x3,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
mov    %eax,%ecx
call   1080 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <write@plt>
mov    $0x3,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
mov    %eax,%ecx
call   1080 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <write@plt>
mov    $0x3,%edi
call   1090 <sleep@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/tmp/myfifo\00"
@O_WRONLY = global i32 0
@.str.1 = [30 x i8] c"Hello no. %d from process %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
store i32 0, i32* %1
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* @O_WRONLY
%8 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @sleep(i32 1)
br label %13
13: ; preds = %11, %6
br label %14
14: ; preds = %13
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, -1
br i1 %16, label %6, label %17
17: ; preds = %14
store i32 1, i32* %4
br label %18
18: ; preds = %34, %17
%19 = load i32, i32* %4
%20 = icmp sle i32 %19, 3
br i1 %20, label %21, label %37
21: ; preds = %18
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%23 = load i32, i32* %4
%24 = call i32 (...) @getpid()
%25 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %24)
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
%29 = load i32, i32* %2
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%31 = load i32, i32* %3
%32 = call i32 @write(i32 %29, i8* %30, i32 %31)
%33 = call i32 @sleep(i32 3)
br label %34
34: ; preds = %21
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %18
37: ; preds = %18
%38 = load i32, i32* %2
%39 = call i32 @close(i32 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"/tmp/myfifo\00"
@O_WRONLY = global i32 0
@.str.1 = [30 x i8] c"Hello no. %d from process %d\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %27, label %6
6: ; preds = %27, %0
%7 = phi i32 [ %4, %0 ], [ %30, %27 ]
%8 = call i32 (...) @getpid()
%9 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %8)
%10 = call i32 @strlen(i8* %2)
%11 = add nsw i32 %10, 1
%12 = call i32 @write(i32 %7, i8* %2, i32 %11)
%13 = call i32 @sleep(i32 3)
%14 = call i32 (...) @getpid()
%15 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %14)
%16 = call i32 @strlen(i8* %2)
%17 = add nsw i32 %16, 1
%18 = call i32 @write(i32 %7, i8* %2, i32 %17)
%19 = call i32 @sleep(i32 3)
%20 = call i32 (...) @getpid()
%21 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %20)
%22 = call i32 @strlen(i8* %2)
%23 = add nsw i32 %22, 1
%24 = call i32 @write(i32 %7, i8* %2, i32 %23)
%25 = call i32 @sleep(i32 3)
%26 = call i32 @close(i32 %7)
ret i32 0
27: ; preds = %0, %27
%28 = tail call i32 @sleep(i32 1)
%29 = load i32, i32* @O_WRONLY
%30 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %27, label %6
}