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


x86 assembly (clang, -O0):
<readfifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1164 <readfifo+0x34>
movb   $0x0,-0x1(%rbp)
jmp    11a6 <readfifo+0x76>
mov    -0x1c(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1196 <readfifo+0x66>
movsbl -0x11(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11a0 <readfifo+0x70>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    11a0 <readfifo+0x70>
mov    -0x20(%rbp),%eax
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readfifo>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
je     1176 <readfifo+0x46>
mov    %eax,%ebp
lea    0xf(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1030 <close@plt>
cmp    $0x1,%r14d
movzbl 0xf(%rsp),%eax
cmove  %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define signext i8 @readfifo(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %1
store i8 0, i8* %2
br label %27
13: ; preds = %1
%14 = load i32, i32* %6
%15 = call i32 @read(i32 %14, i8* %4, i32 1)
store i32 %15, i32* %5
%16 = load i32, i32* %6
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i8, i8* %4
%22 = sext i8 %21 to i32
br label %24
23: ; preds = %13
br label %24
24: ; preds = %23, %20
%25 = phi i32 [ %22, %20 ], [ 0, %23 ]
%26 = trunc i32 %25 to i8
store i8 %26, i8* %2
br label %27
27: ; preds = %24, %12
%28 = load i8, i8* %2
ret i8 %28
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define signext i8 @readfifo(i8* nocapture %0) {
%2 = alloca i8
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = call i32 @read(i32 %4, i8* %2, i32 1)
%8 = tail call i32 @close(i32 %4)
%9 = icmp eq i32 %7, 1
%10 = load i8, i8* %2
%11 = select i1 %9, i8 %10, i8 0
br label %12
12: ; preds = %1, %6
%13 = phi i8 [ %11, %6 ], [ 0, %1 ]
ret i8 %13
}