#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(int /*<<< orphan*/);
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ usleep(int);
int main(void) {
  pid_t pid;
  int i;
  pid = fork();
  switch (pid) {
  case -1:
    perror("Could not fork");
    break;
  case 0:
    printf("\n... ich bin das Kind %d\n", getpid());
    for (i = 0; i < 10; i++) {
      usleep(500000);
      printf("Mein Elternprozess ist %d\n", getppid());
    }
    printf("... so das wars\n");
    break;
  default:
    sleep(2);
    exit(0);
    break;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0xffffffff,%eax
je     11bd <main+0x3d>
jmp    11ad <main+0x2d>
mov    -0x10(%rbp),%eax
test   %eax,%eax
je     11ce <main+0x4e>
jmp    1238 <main+0xb8>
lea    0xe3c(%rip),%rdi
call   1050 <perror@plt>
jmp    1249 <main+0xc9>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1225 <main+0xa5>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    $0x0,%al
call   1060 <getppid@plt>
mov    %eax,%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ec <main+0x6c>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1249 <main+0xc9>
mov    $0x2,%edi
call   1080 <sleep@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
jne    12f0 <main+0x160>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe61(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
lea    0xe5a(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x7a120,%edi
call   10b0 <usleep@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd5d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret
cmp    $0xffffffff,%eax
jne    1303 <main+0x173>
lea    0xd04(%rip),%rdi
call   1060 <perror@plt>
jmp    12ec <main+0x15c>
mov    $0x2,%edi
call   1090 <sleep@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Could not fork\00"
@.str.1 = [26 x i8] c"\0A... ich bin das Kind %d\0A\00"
@.str.2 = [27 x i8] c"Mein Elternprozess ist %d\0A\00"
@.str.3 = [17 x i8] c"... so das wars\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @fork()
store i32 %4, i32* %2
%5 = load i32, i32* %2
switch i32 %5, label %23 [
i32 -1, label %6
i32 0, label %8
]
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %26
8: ; preds = %0
%9 = call i32 (...) @getpid()
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %9)
store i32 0, i32* %3
br label %11
11: ; preds = %18, %8
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 10
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = call i32 @usleep(i32 500000)
%16 = call i32 (...) @getppid()
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %14
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %11
21: ; preds = %11
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %26
23: ; preds = %0
%24 = call i32 @sleep(i32 2)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %21, %6
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [15 x i8] c"Could not fork\00"
@.str.1 = [26 x i8] c"\0A... ich bin das Kind %d\0A\00"
@.str.2 = [27 x i8] c"Mein Elternprozess ist %d\0A\00"
@str = [16 x i8] c"... so das wars\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %38 [
i32 -1, label %2
i32 0, label %4
]
2: ; preds = %0
%3 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %41
4: ; preds = %0
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = tail call i32 @usleep(i32 500000)
%8 = tail call i32 (...) @getppid()
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = tail call i32 @usleep(i32 500000)
%11 = tail call i32 (...) @getppid()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = tail call i32 @usleep(i32 500000)
%14 = tail call i32 (...) @getppid()
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = tail call i32 @usleep(i32 500000)
%17 = tail call i32 (...) @getppid()
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = tail call i32 @usleep(i32 500000)
%20 = tail call i32 (...) @getppid()
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = tail call i32 @usleep(i32 500000)
%23 = tail call i32 (...) @getppid()
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = tail call i32 @usleep(i32 500000)
%26 = tail call i32 (...) @getppid()
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = tail call i32 @usleep(i32 500000)
%29 = tail call i32 (...) @getppid()
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = tail call i32 @usleep(i32 500000)
%32 = tail call i32 (...) @getppid()
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = tail call i32 @usleep(i32 500000)
%35 = tail call i32 (...) @getppid()
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %41
38: ; preds = %0
%39 = tail call i32 @sleep(i32 2)
%40 = tail call i32 @exit(i32 0)
unreachable
41: ; preds = %4, %2
ret i32 0
}