#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);
int main(int argc, char *argv[], char *env[]) {
  pid_t pid;
  pid = fork();
  if (pid == -1) {
    exit(-1);
  } else if (pid == 0) {
    printf("Потомок, имеющий id:%d\n", getpid());
    printf("Родитель потомка, имеющий id:%d\n", getppid());
  } else {
    printf("Родитель, имеющий id:%d\n", getpid());
    printf("Потомок родителя, имеющий id:%d\n", pid);
  }
  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    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1188 <main+0x38>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11c1 <main+0x71>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
jmp    11e5 <main+0x95>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
jmp    11ea <main+0x9a>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     116d <main+0x1d>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1194 <main+0x44>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe85(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getppid@plt>
mov    %eax,%ebx
lea    0xe94(%rip),%rdi
jmp    11b0 <main+0x60>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xebb(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xed5(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"\D0\9F\D0\BE\D1\82\D0\BE\D0\BC\D0\BE\D0\BA, \D0\B8\D0\BC\D0\B5\D1\8E\D1\89\D0\B8\D0\B9 id:%d\0A\00"
@.str.1 = [55 x i8] c"\D0\A0\D0\BE\D0\B4\D0\B8\D1\82\D0\B5\D0\BB\D1\8C \D0\BF\D0\BE\D1\82\D0\BE\D0\BC\D0\BA\D0\B0, \D0\B8\D0\BC\D0\B5\D1\8E\D1\89\D0\B8\D0\B9 id:%d\0A\00"
@.str.2 = [40 x i8] c"\D0\A0\D0\BE\D0\B4\D0\B8\D1\82\D0\B5\D0\BB\D1\8C, \D0\B8\D0\BC\D0\B5\D1\8E\D1\89\D0\B8\D0\B9 id:%d\0A\00"
@.str.3 = [55 x i8] c"\D0\9F\D0\BE\D1\82\D0\BE\D0\BC\D0\BE\D0\BA \D1\80\D0\BE\D0\B4\D0\B8\D1\82\D0\B5\D0\BB\D1\8F, \D0\B8\D0\BC\D0\B5\D1\8E\D1\89\D0\B8\D0\B9 id:%d\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%9 = call i32 (...) @fork()
store i32 %9, i32* %8
%10 = load i32, i32* %8
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %3
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = call i32 (...) @getpid()
%19 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 (...) @getppid()
%21 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %27
22: ; preds = %14
%23 = call i32 (...) @getpid()
%24 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %8
%26 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %22, %17
br label %28
28: ; preds = %27
%29 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [38 x i8] c"\D0\9F\D0\BE\D1\82\D0\BE\D0\BC\D0\BE\D0\BA, \D0\B8\D0\BC\D0\B5\D1\8E\D1\89\D0\B8\D0\B9 id:%d\0A\00"
@.str.1 = [55 x i8] c"\D0\A0\D0\BE\D0\B4\D0\B8\D1\82\D0\B5\D0\BB\D1\8C \D0\BF\D0\BE\D1\82\D0\BE\D0\BC\D0\BA\D0\B0, \D0\B8\D0\BC\D0\B5\D1\8E\D1\89\D0\B8\D0\B9 id:%d\0A\00"
@.str.2 = [40 x i8] c"\D0\A0\D0\BE\D0\B4\D0\B8\D1\82\D0\B5\D0\BB\D1\8C, \D0\B8\D0\BC\D0\B5\D1\8E\D1\89\D0\B8\D0\B9 id:%d\0A\00"
@.str.3 = [55 x i8] c"\D0\9F\D0\BE\D1\82\D0\BE\D0\BC\D0\BE\D0\BA \D1\80\D0\BE\D0\B4\D0\B8\D1\82\D0\B5\D0\BB\D1\8F, \D0\B8\D0\BC\D0\B5\D1\8E\D1\89\D0\B8\D0\B9 id:%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = tail call i32 (...) @fork()
switch i32 %4, label %11 [
i32 -1, label %5
i32 0, label %7
]
5: ; preds = %3
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %3
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 (...) @getppid()
br label %14
11: ; preds = %3
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %7, %11
%15 = phi i32 [ %10, %7 ], [ %4, %11 ]
%16 = phi i8* [ getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), %11 ]
%17 = tail call i32 @printf(i8* %16, i32 %15)
%18 = tail call i32 @exit(i32 0)
unreachable
}