#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 O_NONBLOCK;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void write_fifo() {
  char buf[100];
  memset(buf, 0, sizeof(buf));
  int fd = open("/home/lennon/share/20150214/fifo1", O_WRONLY | O_NONBLOCK);
  if (fd == -1) {
    printf("%m\n");
    exit(-1);
  }
  strcpy(buf, "hello fifo!");
  write(fd, buf, strlen(buf));
  close(fd);
}


x86 assembly (clang, -O0):
<write_fifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1070 <memset@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    0x2e3d(%rip),%rax
or     (%rax),%esi
lea    0xe4c(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0xffffffff,-0x74(%rbp)
jne    11dc <write_fifo+0x5c>
lea    0xe55(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    -0x70(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x74(%rbp),%eax
mov    %eax,-0x84(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x74(%rbp),%edi
call   1080 <close@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_fifo>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1070 <memset@plt>
mov    0x2e33(%rip),%rax
mov    0x2e44(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe51(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     11f0 <write_fifo+0x70>
mov    %eax,%ebx
lea    0xe64(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1080 <close@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe2b(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"/home/lennon/share/20150214/fifo1\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [4 x i8] c"%m\0A\00"
@.str.2 = [12 x i8] c"hello fifo!\00"
define void @write_fifo() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 100)
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 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 %14
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %2
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @write(i32 %17, i8* %18, i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @close(i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"/home/lennon/share/20150214/fifo1\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [4 x i8] c"%m\0A\00"
@.str.2 = [12 x i8] c"hello fifo!\00"
define void @write_fifo() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 100)
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_NONBLOCK
%6 = or i32 %5, %4
%7 = call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @strlen(i8* %2)
%15 = call i32 @write(i32 %7, i8* %2, i32 %14)
%16 = call i32 @close(i32 %7)
ret void
}