#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 */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ write(int, int /*<<< orphan*/, int /*<<< orphan*/);
void main() {
  char bufor[30];
  char nazwa[30];
  int wPliku;
  FILE *plik;
  int fifo;
  system("mkfifo fifo");
  do {
    puts("Podaj nazwe pliku: ");
    scanf("%s", nazwa);
    plik = fopen(nazwa, "r");
    if (strcmp("koniec", nazwa) != 0 && plik == NULL) {
      puts("Nie udalo sie otworzyc pliku.");
      return;
    }
    fifo = open("fifo", O_RDWR);
    if (strcmp("koniec", nazwa) != 0 && fifo == -1) {
      puts("Nie udalo sie utworzyc potoku FIFO.");
      return;
    }
    while (strcmp("koniec", nazwa) != 0 && fscanf(plik, "%s\n", bufor) > 0)
      write(fifo, strcat(bufor, "\n"), strlen(bufor));
    fclose(plik);
    close(fifo);
  } while (strcmp("koniec", nazwa) != 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xe31(%rip),%rdi
call   1070 <system@plt>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
lea    -0x40(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   10b0 <scanf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xe16(%rip),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     123a <main+0x7a>
cmpq   $0x0,-0x50(%rbp)
jne    123a <main+0x7a>
lea    0xdfc(%rip),%rdi
call   1030 <puts@plt>
jmp    133b <main+0x17b>
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
lea    0xdbd(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x54(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xdc8(%rip),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1287 <main+0xc7>
cmpl   $0xffffffff,-0x54(%rbp)
jne    1287 <main+0xc7>
lea    0xdcd(%rip),%rdi
call   1030 <puts@plt>
jmp    133b <main+0x17b>
jmp    128c <main+0xcc>
lea    -0x40(%rbp),%rsi
lea    0xd8e(%rip),%rdi
call   10a0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x55(%rbp)
je     12cc <main+0x10c>
mov    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rdx
lea    0xdb1(%rip),%rsi
call   1080 <fscanf@plt>
cmp    $0x0,%rax
setg   %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    12dc <main+0x11c>
jmp    1310 <main+0x150>
mov    -0x54(%rbp),%eax
mov    %eax,-0x60(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xd83(%rip),%rsi
call   10e0 <strcat@plt>
mov    %eax,-0x5c(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x60(%rbp),%edi
mov    -0x5c(%rbp),%esi
mov    %eax,%edx
call   1040 <write@plt>
jmp    128c <main+0xcc>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x54(%rbp),%edi
call   1090 <close@plt>
lea    -0x40(%rbp),%rsi
lea    0xcf9(%rip),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    11d4 <main+0x14>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe2b(%rip),%rdi
call   1070 <system@plt>
mov    %rsp,%rbx
lea    0xe41(%rip),%rbp
lea    0x20(%rsp),%r12
jmp    1214 <main+0x54>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     12fd <main+0x13d>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf9(%rip),%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    %rbx,%rdi
lea    0xdea(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %r13,%r13
jne    125a <main+0x9a>
test   %rax,%rax
jne    12e8 <main+0x128>
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
lea    0xd9d(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
cmp    $0xffffffff,%r14d
jne    1290 <main+0xd0>
test   %rax,%rax
jne    12f1 <main+0x131>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     11f0 <main+0x30>
mov    %r13,%rdi
lea    0xdc0(%rip),%rsi
mov    %r12,%rdx
call   1080 <fscanf@plt>
test   %rax,%rax
jle    11f0 <main+0x30>
mov    %r12,%rdi
lea    0xda7(%rip),%rsi
call   10e0 <strcat@plt>
mov    %eax,%r15d
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %r14d,%edi
mov    %r15d,%esi
mov    %eax,%edx
call   1040 <write@plt>
jmp    1290 <main+0xd0>
lea    0xd3d(%rip),%rdi
jmp    12f8 <main+0x138>
lea    0xd52(%rip),%rdi
call   1030 <puts@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"mkfifo fifo\00"
@.str.1 = [20 x i8] c"Podaj nazwe pliku: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [7 x i8] c"koniec\00"
@.str.5 = [30 x i8] c"Nie udalo sie otworzyc pliku.\00"
@.str.6 = [5 x i8] c"fifo\00"
@O_RDWR = global i32 0
@.str.7 = [36 x i8] c"Nie udalo sie utworzyc potoku FIFO.\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [2 x i8] c"\0A\00"
define void @main() {
%1 = alloca [30 x i8]
%2 = alloca [30 x i8]
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %56, %0
%8 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %4
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%14 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %7
%17 = load i32*, i32** %4
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
br label %60
21: ; preds = %16, %7
%22 = load i32, i32* @O_RDWR
%23 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %22)
store i32 %23, i32* %5
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%25 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
br label %60
32: ; preds = %27, %21
br label %33
33: ; preds = %44, %32
%34 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%35 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %33
%38 = load i32*, i32** %4
%39 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%40 = call i64 @fscanf(i32* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %39)
%41 = icmp sgt i64 %40, 0
br label %42
42: ; preds = %37, %33
%43 = phi i1 [ false, %33 ], [ %41, %37 ]
br i1 %43, label %44, label %51
44: ; preds = %42
%45 = load i32, i32* %5
%46 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%47 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%48 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = call i32 @write(i32 %45, i32 %47, i32 %49)
br label %33
51: ; preds = %42
%52 = load i32*, i32** %4
%53 = call i32 @fclose(i32* %52)
%54 = load i32, i32* %5
%55 = call i32 @close(i32 %54)
br label %56
56: ; preds = %51
%57 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%58 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %7, label %60
60: ; preds = %19, %30, %56
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"mkfifo fifo\00"
@.str.1 = [20 x i8] c"Podaj nazwe pliku: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [7 x i8] c"koniec\00"
@.str.5 = [30 x i8] c"Nie udalo sie otworzyc pliku.\00"
@.str.6 = [5 x i8] c"fifo\00"
@O_RDWR = global i32 0
@.str.7 = [36 x i8] c"Nie udalo sie utworzyc potoku FIFO.\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [2 x i8] c"\0A\00"
define void @main() {
%1 = alloca [30 x i8]
%2 = alloca [30 x i8]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %33, %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%9 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%11 = icmp ne i64 %10, 0
%12 = icmp eq i32* %9, null
%13 = and i1 %12, %11
br i1 %13, label %38, label %14
14: ; preds = %6
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %15)
%17 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%18 = icmp ne i64 %17, 0
%19 = icmp eq i32 %16, -1
%20 = and i1 %19, %18
br i1 %20, label %38, label %21
21: ; preds = %14
%22 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %21, %27
%25 = call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %3)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%29 = call i32 @strlen(i8* %3)
%30 = call i32 @write(i32 %16, i32 %28, i32 %29)
%31 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %24
33: ; preds = %24, %27, %21
%34 = call i32 @fclose(i32* %9)
%35 = call i32 @close(i32 %16)
%36 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%37 = icmp eq i64 %36, 0
br i1 %37, label %41, label %6
38: ; preds = %14, %6
%39 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), %6 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), %14 ]
%40 = call i32 @puts(i8* dereferenceable(1) %39)
br label %41
41: ; preds = %33, %38
ret void
}