#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 O_NONBLOCK;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int);
int write(int, char const *, int);
int writefifo(const char *path, const char c) {
  int n, fd = open(path, O_WRONLY | O_NONBLOCK);
  if (fd == -1)
    return -1;
  n = write(fd, &c, 1);
  close(fd);
  return (n == 1) ? 0 : -1;
}


x86 assembly (clang, -O0):
<writefifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    0x2e92(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1176 <writefifo+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a5 <writefifo+0x75>
mov    -0x1c(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writefifo>:
push   %rbp
push   %rbx
push   %rax
mov    %sil,0x7(%rsp)
mov    0x2e91(%rip),%rax
mov    0x2ea2(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     117c <writefifo+0x4c>
mov    %eax,%ebx
lea    0x7(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
cmp    $0x1,%ebp
setne  %al
neg    %eax
jmp    1181 <writefifo+0x51>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @writefifo(i8* %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %8, i32 %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %25
16: ; preds = %2
%17 = load i32, i32* %7
%18 = call i32 @write(i32 %17, i8* %5, i32 1)
store i32 %18, i32* %6
%19 = load i32, i32* %7
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 1
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 0, i32 -1
store i32 %24, i32* %3
br label %25
25: ; preds = %16, %15
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @writefifo(i8* nocapture %0, i8 signext %1) {
%3 = alloca i8
store i8 %1, i8* %3
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_NONBLOCK
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = call i32 @write(i32 %7, i8* %3, i32 1)
%11 = tail call i32 @close(i32 %7)
%12 = icmp ne i32 %10, 1
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %2, %9
%15 = phi i32 [ %13, %9 ], [ -1, %2 ]
ret i32 %15
}