#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SIGTERM;
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int wait(int *);
int main(int argc, char *argv[]) {
  pid_t wysylanie, odbieranie;
  if ((odbieranie = fork()) == 0) {
    execl("./odbieranie", "NULL", NULL);
    printf("Blad execl odbierania\n");
    _exit(EXIT_FAILURE);
  } else if (odbieranie == -1) {
    perror("Blad fork odbierania");
    exit(EXIT_FAILURE);
  }
  if ((wysylanie = fork()) == 0) {
    execl("./wysylanie", "NULL", NULL);
    printf("Blad wysylania w execl\n");
    exit(EXIT_FAILURE);
  } else if (wysylanie == -1) {
    perror("Blad fork wysylania");
    exit(EXIT_FAILURE);
  }
  int status = 0;
  if (wait(&status) == -1)
    printf("Blad wait()\n");
  else {
    if (WIFEXITED(status) && WEXITSTATUS(status)) {
      printf("Odbieranie zatrzymane. Koniec wysylania\n");
      kill(wysylanie, SIGTERM);
    }
  }
  printf("Wysylanie i pobieranie zakonczone\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    11fa <main+0x5a>
lea    0xe30(%rip),%rdi
lea    0xe36(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <execl@plt>
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    121e <main+0x7e>
lea    0xe1e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1223 <main+0x83>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1267 <main+0xc7>
lea    0xe01(%rip),%rdi
lea    0xdc9(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <execl@plt>
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpl   $0xffffffff,-0x14(%rbp)
jne    128b <main+0xeb>
lea    0xdea(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1290 <main+0xf0>
movl   $0x0,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   10b0 <wait@plt>
cmp    $0xffffffff,%eax
jne    12ba <main+0x11a>
lea    0xdc6(%rip),%rdi
call   1040 <printf@plt>
jmp    1300 <main+0x160>
mov    -0x1c(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12fb <main+0x15b>
mov    -0x1c(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     12fb <main+0x15b>
lea    0xd9e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
jmp    1300 <main+0x160>
lea    0xda5(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     11e4 <main+0x44>
test   %eax,%eax
jne    11ed <main+0x4d>
lea    0xe44(%rip),%rdi
lea    0xe4a(%rip),%rsi
xor    %edx,%edx
call   10a0 <execl@plt>
lea    0xee3(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
lea    0xe27(%rip),%rdi
jmp    1229 <main+0x89>
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     1222 <main+0x82>
mov    %eax,%ebx
test   %eax,%eax
jne    123c <main+0x9c>
lea    0xe21(%rip),%rdi
lea    0xe00(%rip),%rsi
xor    %edx,%edx
call   10a0 <execl@plt>
lea    0xe82(%rip),%rdi
call   1040 <puts@plt>
jmp    122e <main+0x8e>
lea    0xe0a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   10b0 <wait@plt>
cmp    $0xffffffff,%eax
jne    1261 <main+0xc1>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
jmp    1299 <main+0xf9>
mov    0xc(%rsp),%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
je     1299 <main+0xf9>
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
test   %rax,%rax
je     1299 <main+0xf9>
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <kill@plt>
lea    0xda7(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"./odbieranie\00"
@.str.1 = [5 x i8] c"NULL\00"
@.str.2 = [23 x i8] c"Blad execl odbierania\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [21 x i8] c"Blad fork odbierania\00"
@.str.4 = [12 x i8] c"./wysylanie\00"
@.str.5 = [24 x i8] c"Blad wysylania w execl\0A\00"
@.str.6 = [20 x i8] c"Blad fork wysylania\00"
@.str.7 = [13 x i8] c"Blad wait()\0A\00"
@.str.8 = [41 x i8] c"Odbieranie zatrzymane. Koniec wysylania\0A\00"
@SIGTERM = global i32 0
@.str.9 = [35 x i8] c"Wysylanie i pobieranie zakonczone\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @fork()
store i32 %9, i32* %7
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null)
%13 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @_exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %16
br label %24
24: ; preds = %23
%25 = call i32 (...) @fork()
store i32 %25, i32* %6
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = call i32 @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null)
%29 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %24
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %32
br label %40
40: ; preds = %39
store i32 0, i32* %8
%41 = call i32 @wait(i32* %8)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %59
45: ; preds = %40
%46 = load i32, i32* %8
%47 = call i64 @WIFEXITED(i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %58
49: ; preds = %45
%50 = load i32, i32* %8
%51 = call i64 @WEXITSTATUS(i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %49
%54 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.8, i64 0, i64 0))
%55 = load i32, i32* %6
%56 = load i32, i32* @SIGTERM
%57 = call i32 @kill(i32 %55, i32 %56)
br label %58
58: ; preds = %53, %49, %45
br label %59
59: ; preds = %58, %43
%60 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0))
%61 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"./odbieranie\00"
@.str.1 = [5 x i8] c"NULL\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [21 x i8] c"Blad fork odbierania\00"
@.str.4 = [12 x i8] c"./wysylanie\00"
@.str.6 = [20 x i8] c"Blad fork wysylania\00"
@SIGTERM = global i32 0
@str = [34 x i8] c"Wysylanie i pobieranie zakonczone\00"
@str.10 = [40 x i8] c"Odbieranie zatrzymane. Koniec wysylania\00"
@str.11 = [12 x i8] c"Blad wait()\00"
@str.12 = [23 x i8] c"Blad wysylania w execl\00"
@str.13 = [22 x i8] c"Blad execl odbierania\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 (...) @fork()
switch i32 %4, label %14 [
i32 0, label %5
i32 -1, label %10
]
5: ; preds = %2
%6 = tail call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.13, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @_exit(i32 %8)
unreachable
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = tail call i32 (...) @fork()
switch i32 %15, label %25 [
i32 0, label %16
i32 -1, label %21
]
16: ; preds = %14
%17 = tail call i32 @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null)
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.12, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %14
%22 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %14
%26 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%27 = call i32 @wait(i32* %3)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0))
br label %43
31: ; preds = %25
%32 = load i32, i32* %3
%33 = call i64 @WIFEXITED(i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %43, label %35
35: ; preds = %31
%36 = load i32, i32* %3
%37 = call i64 @WEXITSTATUS(i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.10, i64 0, i64 0))
%41 = load i32, i32* @SIGTERM
%42 = call i32 @kill(i32 %15, i32 %41)
br label %43
43: ; preds = %31, %35, %39, %29
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%45 = call i32 @exit(i32 0)
unreachable
}