#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 pid_t;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int execlp(char *, char *, int /*<<< orphan*/ *);
int fork();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
void main() {
  pid_t pid;
  int potok_fd[2];
  char bufor[BUFSIZ];
  char nazwa[30];
  int wPliku;
  int obraz;
  pipe(potok_fd);
  if ((pid = fork()) == -1)
    return;
  if (pid != 0) {
    puts("Podaj nazwe pliku: ");
    scanf("%s", nazwa);
    obraz = open(nazwa, O_RDONLY);
    if (obraz == -1) {
      puts("Plik nie istnieje.");
      return;
    }
    close(1);
    dup(potok_fd[1]);
    close(potok_fd[1]);
    close(potok_fd[0]);
    while ((wPliku = read(obraz, bufor, BUFSIZ)) > 0)
      write(1, bufor, wPliku);
    close(obraz);
  }
  if (pid == 0) {
    close(0);
    dup(potok_fd[0]);
    close(potok_fd[0]);
    close(potok_fd[1]);
    if (execlp("display", "display", NULL) == -1)
      ;
    return;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11fc <main+0x5c>
movl   $0x1,-0x4c(%rbp)
jmp    1317 <main+0x177>
cmpl   $0x0,-0x4(%rbp)
je     12ba <main+0x11a>
lea    0xdf3(%rip),%rdi
call   1030 <puts@plt>
lea    -0x40(%rbp),%rsi
lea    0xdf7(%rip),%rdi
call   1090 <scanf@plt>
lea    -0x40(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    1259 <main+0xb9>
lea    0xdcf(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4c(%rbp)
jmp    1317 <main+0x177>
mov    $0x1,%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <dup@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x58(%rbp),%rsi
mov    -0x48(%rbp),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jle    12b2 <main+0x112>
mov    -0x58(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
jmp    127b <main+0xdb>
mov    -0x48(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1310 <main+0x170>
xor    %edi,%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
call   1050 <dup@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
lea    0xd40(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   10b0 <execlp@plt>
cmp    $0xffffffff,%eax
jne    1304 <main+0x164>
jmp    1304 <main+0x164>
movl   $0x1,-0x4c(%rbp)
jmp    1317 <main+0x177>
movl   $0x0,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%r12
mov    0x2e1d(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x30(%rbp),%rdi
call   1070 <pipe@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     12ea <main+0x14a>
mov    %eax,%r14d
test   %eax,%eax
jne    1225 <main+0x85>
xor    %edi,%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%edi
call   1050 <dup@plt>
mov    -0x30(%rbp),%edi
call   1060 <close@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
lea    0xe14(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   10b0 <execlp@plt>
jmp    12ea <main+0x14a>
lea    0xdd4(%rip),%rdi
call   1030 <puts@plt>
lea    0xddc(%rip),%rdi
lea    -0x50(%rbp),%r15
mov    %r15,%rsi
call   1090 <scanf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     12d4 <main+0x134>
mov    %eax,%r15d
mov    $0x1,%edi
call   1060 <close@plt>
mov    -0x2c(%rbp),%edi
call   1050 <dup@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%edi
call   1060 <close@plt>
mov    0x0(%r13),%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1080 <read@plt>
test   %eax,%eax
jle    12e2 <main+0x142>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    0x0(%r13),%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1080 <read@plt>
test   %eax,%eax
jg     12a0 <main+0x100>
mov    %r15d,%edi
call   1060 <close@plt>
test   %r14d,%r14d
jne    12ea <main+0x14a>
jmp    11f0 <main+0x50>
lea    0xd3c(%rip),%rdi
call   1030 <puts@plt>
jmp    12ea <main+0x14a>
mov    %r15d,%edi
call   1060 <close@plt>
mov    %r12,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [20 x i8] c"Podaj nazwe pliku: \00"
@.str.1 = [3 x i8] c"%s\00"
@O_RDONLY = global i32 0
@.str.2 = [19 x i8] c"Plik nie istnieje.\00"
@.str.3 = [8 x i8] c"display\00"
define void @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [30 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %3
%12 = alloca i8, i64 %10
store i64 %10, i64* %4
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = call i32 (...) @fork()
store i32 %15, i32* %1
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %0
store i32 1, i32* %8
br label %73
18: ; preds = %0
%19 = load i32, i32* %1
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %54
21: ; preds = %18
%22 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %25, i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %8
br label %73
32: ; preds = %21
%33 = call i32 @close(i32 1)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%35 = load i32, i32* %34
%36 = call i32 @dup(i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
br label %43
43: ; preds = %48, %32
%44 = load i32, i32* %7
%45 = load i32, i32* @BUFSIZ
%46 = call i32 @read(i32 %44, i8* %12, i32 %45)
store i32 %46, i32* %6
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = load i32, i32* %6
%50 = call i32 @write(i32 1, i8* %12, i32 %49)
br label %43
51: ; preds = %43
%52 = load i32, i32* %7
%53 = call i32 @close(i32 %52)
br label %54
54: ; preds = %51, %18
%55 = load i32, i32* %1
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %72
57: ; preds = %54
%58 = call i32 @close(i32 0)
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%60 = load i32, i32* %59
%61 = call i32 @dup(i32 %60)
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
%65 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%66 = load i32, i32* %65
%67 = call i32 @close(i32 %66)
%68 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* null)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %71
70: ; preds = %57
br label %71
71: ; preds = %70, %57
store i32 1, i32* %8
br label %73
72: ; preds = %54
store i32 0, i32* %8
br label %73
73: ; preds = %72, %71, %30, %17
%74 = load i8*, i8** %3
%75 = load i32, i32* %8
switch i32 %75, label %77 [
i32 0, label %76
i32 1, label %76
]
76: ; preds = %73, %73
ret void
77: ; preds = %73
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [20 x i8] c"Podaj nazwe pliku: \00"
@.str.1 = [3 x i8] c"%s\00"
@O_RDONLY = global i32 0
@.str.2 = [19 x i8] c"Plik nie istnieje.\00"
@.str.3 = [8 x i8] c"display\00"
define void @main() {
%1 = alloca [2 x i32]
%2 = alloca [30 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = call i32 (...) @fork()
switch i32 %11, label %12 [
i32 -1, label %53
i32 0, label %43
]
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %8, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %53
20: ; preds = %12
%21 = call i32 @close(i32 1)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @dup(i32 %23)
%25 = load i32, i32* %22
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %9
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* @BUFSIZ
%30 = call i32 @read(i32 %16, i8* %7, i32 %29)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %20
%33 = call i32 @close(i32 %16)
br label %53
34: ; preds = %20, %34
%35 = phi i32 [ %38, %34 ], [ %30, %20 ]
%36 = call i32 @write(i32 1, i8* %7, i32 %35)
%37 = load i32, i32* @BUFSIZ
%38 = call i32 @read(i32 %16, i8* %7, i32 %37)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %34, label %40
40: ; preds = %34
%41 = call i32 @close(i32 %16)
%42 = icmp eq i32 %11, 0
br i1 %42, label %43, label %53
43: ; preds = %0, %40
%44 = call i32 @close(i32 0)
%45 = load i32, i32* %9
%46 = call i32 @dup(i32 %45)
%47 = load i32, i32* %9
%48 = call i32 @close(i32 %47)
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
%52 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %53
53: ; preds = %32, %40, %0, %43, %18
ret void
}