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

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
scalar_t__ mkfifo(char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(int *, int, char *);
int write(int, int *, int);
int main() {
  int ret, fd;
  int buf[11] = {0};
  if (mkfifo("/tmp/my_fifo", 0666) < 0)
    printf("failed to create fifo\n");
  fd = open("/tmp/my_fifo", O_WRONLY);
  if (ret < 0)
    printf("Failed to open fifo\n");
  printf("open fifo is ok\n");
  while (1) {
    snprintf(buf, sizeof(buf), "Hello world!...\n");
    ret = write(fd, buf, sizeof(buf));
    printf("ret of write = %d\n", ret);
    sleep(1);
  }
  printf("open fifo close\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x2c,%edx
call   1060 <memset@plt>
lea    0xe6a(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
cmp    $0x0,%rax
jge    11b8 <main+0x48>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
lea    0xe38(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11e8 <main+0x78>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x2c,%esi
lea    0xe44(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x2c,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    11f6 <main+0x86>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0x1c(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe6e(%rip),%rdi
mov    $0x1b6,%esi
call   1070 <mkfifo@plt>
test   %rax,%rax
jns    11ad <main+0x3d>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
lea    0xe43(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
lea    0xe36(%rip),%r14
mov    %rsp,%rbx
lea    0xe3d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x2c,%esi
mov    %r14,%rdx
call   1060 <snprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x2c,%edx
call   1040 <write@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    11f0 <main+0x80>

LLVM IR (-O0):
@.str = [13 x i8] c"/tmp/my_fifo\00"
@.str.1 = [23 x i8] c"failed to create fifo\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [21 x i8] c"Failed to open fifo\0A\00"
@.str.3 = [17 x i8] c"open fifo is ok\0A\00"
@.str.4 = [17 x i8] c"Hello world!...\0A\00"
@.str.5 = [19 x i8] c"ret of write = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [11 x i32]
store i32 0, i32* %1
%5 = bitcast [11 x i32]* %4 to i8*
%6 = call i64 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 438)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %10
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %19
%20 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 0
%21 = call i32 @snprintf(i32* %20, i32 44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32, i32* %3
%23 = getelementptr inbounds [11 x i32], [11 x i32]* %4, i64 0, i64 0
%24 = call i32 @write(i32 %22, i32* %23, i32 44)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%27 = call i32 @sleep(i32 1)
br label %19
}

LLVM IR (-O2):
@.str = [13 x i8] c"/tmp/my_fifo\00"
@O_WRONLY = global i32 0
@.str.4 = [17 x i8] c"Hello world!...\0A\00"
@.str.5 = [19 x i8] c"ret of write = %d\0A\00"
@str = [16 x i8] c"open fifo is ok\00"
@str.6 = [22 x i8] c"failed to create fifo\00"
define i32 @main() {
%1 = alloca [11 x i32]
%2 = bitcast [11 x i32]* %1 to i8*
%3 = tail call i64 @mkfifo(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 438)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = load i32, i32* @O_WRONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%11 = getelementptr inbounds [11 x i32], [11 x i32]* %1, i64 0, i64 0
br label %12
12: ; preds = %12, %7
%13 = call i32 @snprintf(i32* %11, i32 44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @write(i32 %9, i32* %11, i32 44)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%16 = call i32 @sleep(i32 1)
br label %12
}