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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, ...);
scalar_t__ wait(int *);
int /*<<< orphan*/ warten();
int main() {
  pid_t k, pid;
  int p, status;
  k = fork();
  if (k != 0) {
    for (p = 0; p < 20; p++) {
      printf("\t\t\tElternteil %d, Kind=%d\n", p, k);
      warten();
    }
    pid = wait(&status);
    printf("\t\t\tIst Kindprozess beendet? PID war, %d\n", pid);
    while (1)
      ;
  } else {
    printf("Kindprozessnummer= %d \n", getpid());
    for (p = 0; p < 10; p++) {
      printf("Kind %d,%d\n", p, k);
      warten();
    }
    exit(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e6 <main+0x86>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jge    11c0 <main+0x60>
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <warten@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118c <main+0x2c>
lea    -0x20(%rbp),%rdi
call   1070 <wait@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e1 <main+0x81>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    1238 <main+0xd8>
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <warten@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1204 <main+0xa4>
mov    $0x1,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1392 <main+0x232>
mov    %rax,%rbx
lea    0xe82(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x6,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x7,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x8,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x9,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0xa,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0xb,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0xc,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0xd,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0xe,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0xf,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x10,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x11,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x12,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %r14,%rdi
mov    $0x13,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
lea    0xc9b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
nopl   0x0(%rax)
jmp    1390 <main+0x230>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xca4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xcac(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <warten@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"\09\09\09Elternteil %d, Kind=%d\0A\00"
@.str.1 = [41 x i8] c"\09\09\09Ist Kindprozess beendet? PID war, %d\0A\00"
@.str.2 = [24 x i8] c"Kindprozessnummer= %d \0A\00"
@.str.3 = [12 x i8] c"Kind %d,%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i64 (...) @fork()
store i64 %6, i64* %2
%7 = load i64, i64* %2
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %0
store i32 0, i32* %4
br label %10
10: ; preds = %18, %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 20
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i32, i32* %4
%15 = load i64, i64* %2
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %14, i64 %15)
%17 = call i32 (...) @warten()
br label %18
18: ; preds = %13
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
br label %10
21: ; preds = %10
%22 = call i64 @wait(i32* %5)
store i64 %22, i64* %3
%23 = load i64, i64* %3
%24 = trunc i64 %23 to i32
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %21, %26
br label %26
27: ; preds = %0
%28 = call i32 (...) @getpid()
%29 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %28)
store i32 0, i32* %4
br label %30
30: ; preds = %38, %27
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 10
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i32, i32* %4
%35 = load i64, i64* %2
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 %34, i64 %35)
%37 = call i32 (...) @warten()
br label %38
38: ; preds = %33
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %30
41: ; preds = %30
%42 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [27 x i8] c"\09\09\09Elternteil %d, Kind=%d\0A\00"
@.str.1 = [41 x i8] c"\09\09\09Ist Kindprozess beendet? PID war, %d\0A\00"
@.str.2 = [24 x i8] c"Kindprozessnummer= %d \0A\00"
@.str.3 = [12 x i8] c"Kind %d,%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %50, label %5
5: ; preds = %0
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 0, i64 %3)
%7 = tail call i32 (...) @warten()
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 1, i64 %3)
%9 = tail call i32 (...) @warten()
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 2, i64 %3)
%11 = tail call i32 (...) @warten()
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 3, i64 %3)
%13 = tail call i32 (...) @warten()
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 4, i64 %3)
%15 = tail call i32 (...) @warten()
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 5, i64 %3)
%17 = tail call i32 (...) @warten()
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 6, i64 %3)
%19 = tail call i32 (...) @warten()
%20 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 7, i64 %3)
%21 = tail call i32 (...) @warten()
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 8, i64 %3)
%23 = tail call i32 (...) @warten()
%24 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 9, i64 %3)
%25 = tail call i32 (...) @warten()
%26 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 10, i64 %3)
%27 = tail call i32 (...) @warten()
%28 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 11, i64 %3)
%29 = tail call i32 (...) @warten()
%30 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 12, i64 %3)
%31 = tail call i32 (...) @warten()
%32 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 13, i64 %3)
%33 = tail call i32 (...) @warten()
%34 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 14, i64 %3)
%35 = tail call i32 (...) @warten()
%36 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 15, i64 %3)
%37 = tail call i32 (...) @warten()
%38 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 16, i64 %3)
%39 = tail call i32 (...) @warten()
%40 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 17, i64 %3)
%41 = tail call i32 (...) @warten()
%42 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 18, i64 %3)
%43 = tail call i32 (...) @warten()
%44 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 19, i64 %3)
%45 = tail call i32 (...) @warten()
%46 = call i64 @wait(i32* %1)
%47 = trunc i64 %46 to i32
%48 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %49, %5
br label %49
50: ; preds = %0
%51 = tail call i32 (...) @getpid()
%52 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %51)
%53 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 0, i64 0)
%54 = tail call i32 (...) @warten()
%55 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 1, i64 0)
%56 = tail call i32 (...) @warten()
%57 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 2, i64 0)
%58 = tail call i32 (...) @warten()
%59 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 3, i64 0)
%60 = tail call i32 (...) @warten()
%61 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 4, i64 0)
%62 = tail call i32 (...) @warten()
%63 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 5, i64 0)
%64 = tail call i32 (...) @warten()
%65 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 6, i64 0)
%66 = tail call i32 (...) @warten()
%67 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 7, i64 0)
%68 = tail call i32 (...) @warten()
%69 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 8, i64 0)
%70 = tail call i32 (...) @warten()
%71 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i32 9, i64 0)
%72 = tail call i32 (...) @warten()
%73 = tail call i32 @exit(i32 1)
unreachable
}