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

/* Variables and functions */
char EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
void test1() {
  FILE *fp0, *fp1;
  char ch;
  printf("\nCase: \tReading empty fifos\n\n");
  printf("Opening read ends of fifo 0 and fifo 1\n");
  fp0 = fopen("/dev/fifo1", "r");
  fp1 = fopen("/dev/fifo3", "r");
  if (fp0 == NULL || fp1 == NULL) {
    perror("Error while opening fifo.\n");
    exit(EXIT_FAILURE);
  }
  printf("Reading date. Read: \n");
  while ((ch = fgetc(fp0)) != EOF)
    printf("%c", ch);
  while ((ch = fgetc(fp1)) != EOF)
    printf("%c", ch);
  printf("Closing read ends of fifo 0 and fifo 1\n");
  fclose(fp0);
  fclose(fp1);
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebb(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    0xeb1(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c8 <test1+0x68>
cmpq   $0x0,-0x10(%rbp)
jne    11e2 <test1+0x82>
lea    0xe8f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2de2(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1228 <test1+0xc8>
movsbl -0x11(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f0 <test1+0x90>
jmp    122d <test1+0xcd>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2da5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1265 <test1+0x105>
movsbl -0x11(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122d <test1+0xcd>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %r15
push   %r14
push   %rbx
lea    0xeb7(%rip),%rdi
call   1040 <puts@plt>
lea    0xec8(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6c(%rip),%rdi
lea    0xe70(%rip),%rbx
mov    %rbx,%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe60(%rip),%rdi
mov    %rbx,%rsi
call   1070 <fopen@plt>
test   %r14,%r14
je     1245 <test1+0xd5>
mov    %rax,%r15
test   %rax,%rax
je     1245 <test1+0xd5>
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2e03(%rip),%rbx
cmp    (%rbx),%al
je     1218 <test1+0xa8>
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    (%rbx),%al
jne    11f0 <test1+0x80>
jmp    1218 <test1+0xa8>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1060 <fgetc@plt>
cmp    (%rbx),%al
jne    1210 <test1+0xa0>
lea    0xe61(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <fclose@plt>
lea    0xdcc(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"\0ACase: \09Reading empty fifos\0A\0A\00"
@.str.1 = [40 x i8] c"Opening read ends of fifo 0 and fifo 1\0A\00"
@.str.2 = [11 x i8] c"/dev/fifo1\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [11 x i8] c"/dev/fifo3\00"
@.str.5 = [27 x i8] c"Error while opening fifo.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [22 x i8] c"Reading date. Read: \0A\00"
@EOF = global i8 0
@.str.7 = [3 x i8] c"%c\00"
@.str.8 = [40 x i8] c"Closing read ends of fifo 0 and fifo 1\0A\00"
define void @test1() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i8
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %6, i32** %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %2
%8 = load i32*, i32** %1
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10, %0
%14 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %10
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
br label %19
19: ; preds = %26, %17
%20 = load i32*, i32** %1
%21 = call signext i8 @fgetc(i32* %20)
store i8 %21, i8* %3
%22 = sext i8 %21 to i32
%23 = load i8, i8* @EOF
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = load i8, i8* %3
%28 = sext i8 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %28)
br label %19
30: ; preds = %19
br label %31
31: ; preds = %38, %30
%32 = load i32*, i32** %2
%33 = call signext i8 @fgetc(i32* %32)
store i8 %33, i8* %3
%34 = sext i8 %33 to i32
%35 = load i8, i8* @EOF
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %34, %36
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i8, i8* %3
%40 = sext i8 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %40)
br label %31
42: ; preds = %31
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
%44 = load i32*, i32** %1
%45 = call i32 @fclose(i32* %44)
%46 = load i32*, i32** %2
%47 = call i32 @fclose(i32* %46)
ret void
}

LLVM IR (-O2):
@.str.2 = [11 x i8] c"/dev/fifo1\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [11 x i8] c"/dev/fifo3\00"
@.str.5 = [27 x i8] c"Error while opening fifo.\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@str = [29 x i8] c"\0ACase: \09Reading empty fifos\0A\00"
@str.9 = [39 x i8] c"Opening read ends of fifo 0 and fifo 1\00"
@str.10 = [21 x i8] c"Reading date. Read: \00"
@str.11 = [39 x i8] c"Closing read ends of fifo 0 and fifo 1\00"
define void @test1() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.9, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp eq i32* %3, null
%6 = icmp eq i32* %4, null
%7 = or i1 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.10, i64 0, i64 0))
%14 = tail call signext i8 @fgetc(i32* %3)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %21, %12
%18 = tail call signext i8 @fgetc(i32* %4)
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %18, %19
br i1 %20, label %35, label %28
21: ; preds = %12, %21
%22 = phi i8 [ %25, %21 ], [ %14, %12 ]
%23 = sext i8 %22 to i32
%24 = tail call i32 @putchar(i32 %23)
%25 = tail call signext i8 @fgetc(i32* %3)
%26 = load i8, i8* @EOF
%27 = icmp eq i8 %25, %26
br i1 %27, label %17, label %21
28: ; preds = %17, %28
%29 = phi i8 [ %32, %28 ], [ %18, %17 ]
%30 = sext i8 %29 to i32
%31 = tail call i32 @putchar(i32 %30)
%32 = tail call signext i8 @fgetc(i32* %4)
%33 = load i8, i8* @EOF
%34 = icmp eq i8 %32, %33
br i1 %34, label %35, label %28
35: ; preds = %28, %17
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.11, i64 0, i64 0))
%37 = tail call i32 @fclose(i32* %3)
%38 = tail call i32 @fclose(i32* %4)
ret void
}