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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ pipe(int *);
int read(int, int **, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, ...);
int main() {
  int pid, read_size;
  int pd[2];
  int c[1 << 10];
  char *message = "Neiko lapa slivi na poleto\n";
  pipe(pd);
  pid = fork();
  if (pid < 0) {
    close(pd[0]);
    close(pd[1]);
    err(1, "error creating the child process");
  }
  if (pid > 0) {
    close(pd[0]);
    write(pd[1], message, strlen(message));
    close(pd[1]);
  } else {
    close(pd[1]);
    read_size = read(pd[0], &c, sizeof(c));
    write(1, &c, read_size);
    close(pd[1]);
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rax
mov    %rax,-0x1028(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <pipe@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11de <main+0x5e>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
lea    0xe43(%rip),%rsi
call   1080 <err@plt>
cmpl   $0x0,-0x8(%rbp)
jle    1236 <main+0xb6>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1034(%rbp)
mov    -0x1028(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    -0x1028(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1034(%rbp),%edi
mov    -0x1030(%rbp),%rsi
mov    %eax,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
jmp    127a <main+0xfa>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edx
mov    $0x1,%edi
lea    -0x1020(%rbp),%rsi
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1018,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
js     11e1 <main+0x61>
je     1204 <main+0x84>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%ebx
lea    0xe4b(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
lea    0xe22(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Neiko lapa slivi na poleto\0A\00"
@.str.1 = [33 x i8] c"error creating the child process\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca [1024 x i32]
%6 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = call i32 (...) @fork()
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %0
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%14 = load i32, i32* %13
%15 = call i32 @close(i32 %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
%19 = call i32 @err(i32 1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %12, %0
%21 = load i32, i32* %2
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %20
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%28 = load i32, i32* %27
%29 = load i8*, i8** %6
%30 = load i8*, i8** %6
%31 = call i32 @strlen(i8* %30)
%32 = call i32 (i32, ...) @write(i32 %28, i8* %29, i32 %31)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%34 = load i32, i32* %33
%35 = call i32 @close(i32 %34)
br label %50
36: ; preds = %20
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%41 = load i32, i32* %40
%42 = bitcast [1024 x i32]* %5 to i32**
%43 = call i32 @read(i32 %41, i32** %42, i32 4096)
store i32 %43, i32* %3
%44 = load i32, i32* %3
%45 = call i32 (i32, ...) @write(i32 1, [1024 x i32]* %5, i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @close(i32 %47)
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %23
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Neiko lapa slivi na poleto\0A\00"
@.str.1 = [33 x i8] c"error creating the child process\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [1024 x i32]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = bitcast [1024 x i32]* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = load i32, i32* %5
%11 = call i32 @close(i32 %10)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = call i32 @err(i32 1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %27
16: ; preds = %0
%17 = icmp eq i32 %7, 0
br i1 %17, label %27, label %18
18: ; preds = %16
%19 = load i32, i32* %5
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @strlen(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%24 = call i32 (i32, ...) @write(i32 %22, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %21
%26 = call i32 @close(i32 %25)
ret i32 0
27: ; preds = %9, %16
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = load i32, i32* %5
%32 = bitcast [1024 x i32]* %2 to i32**
%33 = call i32 @read(i32 %31, i32** %32, i32 4096)
%34 = call i32 (i32, ...) @write(i32 1, [1024 x i32]* %2, i32 %33)
%35 = load i32, i32* %28
%36 = call i32 @close(i32 %35)
%37 = call i32 @exit(i32 0)
unreachable
}