#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);
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void main() {
  pid_t pid, ppid;
  srand(time(NULL));
  pid = fork();
  if (pid == -1) {
    printf("Не удалось форкнуться");
    exit(-1);
  } else if (pid == 0) {
    ppid = getppid();
    if (ppid == 1) {
      printf("\n Мой отец умер :( \n");
    } else {
      printf("\n Мой отец жив :) \n");
    }
    printf("Я сын мой id =%d, мой отец =%d \n", getpid(), ppid);
  } else {
    printf("Я отец мой id =%d, id моего сына =%d \n", getpid(), pid);
    int i = 0;
    int j = 1;
    while (i < j) {
      j = rand();
      i++;
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11c4 <main+0x44>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x4(%rbp)
jne    1222 <main+0xa2>
mov    $0x0,%al
call   1070 <getppid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11f5 <main+0x75>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1203 <main+0x83>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1273 <main+0xf3>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%edx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    126e <main+0xee>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    124a <main+0xca>
jmp    1273 <main+0xf3>
jmp    1278 <main+0xf8>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11c9 <main+0x39>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    120c <main+0x7c>
lea    0xe48(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
xor    %eax,%eax
call   1080 <getppid@plt>
mov    %eax,%ebx
cmp    $0x1,%eax
lea    0xed1(%rip),%rax
lea    0xead(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe2f(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe3e(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10b0 <rand@plt>
add    $0x1,%ebx
cmp    %eax,%ebx
jl     1230 <main+0xa0>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"\D0\9D\D0\B5 \D1\83\D0\B4\D0\B0\D0\BB\D0\BE\D1\81\D1\8C \D1\84\D0\BE\D1\80\D0\BA\D0\BD\D1\83\D1\82\D1\8C\D1\81\D1\8F\00"
@.str.1 = [32 x i8] c"\0A \D0\9C\D0\BE\D0\B9 \D0\BE\D1\82\D0\B5\D1\86 \D1\83\D0\BC\D0\B5\D1\80 :( \0A\00"
@.str.2 = [30 x i8] c"\0A \D0\9C\D0\BE\D0\B9 \D0\BE\D1\82\D0\B5\D1\86 \D0\B6\D0\B8\D0\B2 :) \0A\00"
@.str.3 = [47 x i8] c"\D0\AF \D1\81\D1\8B\D0\BD \D0\BC\D0\BE\D0\B9 id =%d, \D0\BC\D0\BE\D0\B9 \D0\BE\D1\82\D0\B5\D1\86 =%d \0A\00"
@.str.4 = [56 x i8] c"\D0\AF \D0\BE\D1\82\D0\B5\D1\86 \D0\BC\D0\BE\D0\B9 id =%d, id \D0\BC\D0\BE\D0\B5\D0\B3\D0\BE \D1\81\D1\8B\D0\BD\D0\B0 =%d \0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @time(i32* null)
%6 = call i32 @srand(i32 %5)
%7 = call i32 (...) @fork()
store i32 %7, i32* %1
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %13
%17 = call i32 (...) @getppid()
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %24
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
%25 = call i32 (...) @getpid()
%26 = load i32, i32* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %26)
br label %41
28: ; preds = %13
%29 = call i32 (...) @getpid()
%30 = load i32, i32* %1
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %29, i32 %30)
store i32 0, i32* %3
store i32 1, i32* %4
br label %32
32: ; preds = %36, %28
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = call i32 (...) @rand()
store i32 %37, i32* %4
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %32
40: ; preds = %32
br label %41
41: ; preds = %40, %24
br label %42
42: ; preds = %41
%43 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [41 x i8] c"\D0\9D\D0\B5 \D1\83\D0\B4\D0\B0\D0\BB\D0\BE\D1\81\D1\8C \D1\84\D0\BE\D1\80\D0\BA\D0\BD\D1\83\D1\82\D1\8C\D1\81\D1\8F\00"
@.str.3 = [47 x i8] c"\D0\AF \D1\81\D1\8B\D0\BD \D0\BC\D0\BE\D0\B9 id =%d, \D0\BC\D0\BE\D0\B9 \D0\BE\D1\82\D0\B5\D1\86 =%d \0A\00"
@.str.4 = [56 x i8] c"\D0\AF \D0\BE\D1\82\D0\B5\D1\86 \D0\BC\D0\BE\D0\B9 id =%d, id \D0\BC\D0\BE\D0\B5\D0\B3\D0\BE \D1\81\D1\8B\D0\BD\D0\B0 =%d \0A\00"
@str = [29 x i8] c"\0A \D0\9C\D0\BE\D0\B9 \D0\BE\D1\82\D0\B5\D1\86 \D0\B6\D0\B8\D0\B2 :) \00"
@str.5 = [31 x i8] c"\0A \D0\9C\D0\BE\D0\B9 \D0\BE\D1\82\D0\B5\D1\86 \D1\83\D0\BC\D0\B5\D1\80 :( \00"
define void @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
%3 = tail call i32 (...) @fork()
switch i32 %3, label %14 [
i32 -1, label %4
i32 0, label %7
]
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %0
%8 = tail call i32 (...) @getppid()
%9 = icmp eq i32 %8, 1
%10 = select i1 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0)
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %8)
br label %22
14: ; preds = %0
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i32 %15, i32 %3)
br label %17
17: ; preds = %14, %17
%18 = phi i32 [ 0, %14 ], [ %20, %17 ]
%19 = tail call i32 (...) @rand()
%20 = add nuw nsw i32 %18, 1
%21 = icmp slt i32 %20, %19
br i1 %21, label %17, label %22
22: ; preds = %17, %7
%23 = tail call i32 @exit(i32 0)
unreachable
}