#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 WIFEXITED(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int waitpid(int, int *, int /*<<< orphan*/);
int main() {
  pid_t pid;
  int status;
  switch (pid = fork()) {
  case -1:
    perror("fork\n");
    return -1;
  case 0:
    printf("Выполняется дочерний процесс\n");
    exit(4);
  }
  printf("Выполняется родительский процесс\n");
  printf("Идетификатор дочернего процесса - %d\n", pid);
  if ((pid == waitpid(pid, &status, 0)) && WIFEXITED(status)) {
    printf("Дочерний процесс с PID = %d завершил выполнение\n", pid);
    printf("Код статуса завершения = %d\n", WIFEXITED(status));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
sub    $0xffffffff,%eax
je     119c <main+0x3c>
jmp    118c <main+0x2c>
mov    -0x10(%rbp),%eax
test   %eax,%eax
je     11b4 <main+0x54>
jmp    11cc <main+0x6c>
lea    0xe5d(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124d <main+0xed>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x4,%edi
call   1070 <exit@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jne    1246 <main+0xe6>
mov    -0xc(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%eax
je     1246 <main+0xe6>
mov    -0x8(%rbp),%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <WIFEXITED@plt>
mov    %eax,%esi
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11fa <main+0x8a>
mov    %eax,%ebp
test   %eax,%eax
je     120d <main+0x9d>
lea    0xf74(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6a(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    %eax,%ebp
jne    11f1 <main+0x81>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %eax,%eax
je     11f1 <main+0x81>
lea    0xe7c(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
lea    0xeb4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdff(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11f1 <main+0x81>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x4,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"fork\0A\00"
@.str.1 = [56 x i8] c"\D0\92\D1\8B\D0\BF\D0\BE\D0\BB\D0\BD\D1\8F\D0\B5\D1\82\D1\81\D1\8F \D0\B4\D0\BE\D1\87\D0\B5\D1\80\D0\BD\D0\B8\D0\B9 \D0\BF\D1\80\D0\BE\D1\86\D0\B5\D1\81\D1\81\0A\00"
@.str.2 = [64 x i8] c"\D0\92\D1\8B\D0\BF\D0\BE\D0\BB\D0\BD\D1\8F\D0\B5\D1\82\D1\81\D1\8F \D1\80\D0\BE\D0\B4\D0\B8\D1\82\D0\B5\D0\BB\D1\8C\D1\81\D0\BA\D0\B8\D0\B9 \D0\BF\D1\80\D0\BE\D1\86\D0\B5\D1\81\D1\81\0A\00"
@.str.3 = [67 x i8] c"\D0\98\D0\B4\D0\B5\D1\82\D0\B8\D1\84\D0\B8\D0\BA\D0\B0\D1\82\D0\BE\D1\80 \D0\B4\D0\BE\D1\87\D0\B5\D1\80\D0\BD\D0\B5\D0\B3\D0\BE \D0\BF\D1\80\D0\BE\D1\86\D0\B5\D1\81\D1\81\D0\B0 - %d\0A\00"
@.str.4 = [83 x i8] c"\D0\94\D0\BE\D1\87\D0\B5\D1\80\D0\BD\D0\B8\D0\B9 \D0\BF\D1\80\D0\BE\D1\86\D0\B5\D1\81\D1\81 \D1\81 PID = %d \D0\B7\D0\B0\D0\B2\D0\B5\D1\80\D1\88\D0\B8\D0\BB \D0\B2\D1\8B\D0\BF\D0\BE\D0\BB\D0\BD\D0\B5\D0\BD\D0\B8\D0\B5\0A\00"
@.str.5 = [49 x i8] c"\D0\9A\D0\BE\D0\B4 \D1\81\D1\82\D0\B0\D1\82\D1\83\D1\81\D0\B0 \D0\B7\D0\B0\D0\B2\D0\B5\D1\80\D1\88\D0\B5\D0\BD\D0\B8\D1\8F = %d\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
switch i32 %4, label %10 [
i32 -1, label %5
i32 0, label %7
]
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %29
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 4)
unreachable
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %2
%15 = load i32, i32* %2
%16 = call i32 @waitpid(i32 %15, i32* %3, i32 0)
%17 = icmp eq i32 %14, %16
br i1 %17, label %18, label %28
18: ; preds = %10
%19 = load i32, i32* %3
%20 = call i32 @WIFEXITED(i32 %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %3
%26 = call i32 @WIFEXITED(i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %22, %18, %10
store i32 0, i32* %1
br label %29
29: ; preds = %28, %5
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@.str = [6 x i8] c"fork\0A\00"
@.str.3 = [67 x i8] c"\D0\98\D0\B4\D0\B5\D1\82\D0\B8\D1\84\D0\B8\D0\BA\D0\B0\D1\82\D0\BE\D1\80 \D0\B4\D0\BE\D1\87\D0\B5\D1\80\D0\BD\D0\B5\D0\B3\D0\BE \D0\BF\D1\80\D0\BE\D1\86\D0\B5\D1\81\D1\81\D0\B0 - %d\0A\00"
@.str.4 = [83 x i8] c"\D0\94\D0\BE\D1\87\D0\B5\D1\80\D0\BD\D0\B8\D0\B9 \D0\BF\D1\80\D0\BE\D1\86\D0\B5\D1\81\D1\81 \D1\81 PID = %d \D0\B7\D0\B0\D0\B2\D0\B5\D1\80\D1\88\D0\B8\D0\BB \D0\B2\D1\8B\D0\BF\D0\BE\D0\BB\D0\BD\D0\B5\D0\BD\D0\B8\D0\B5\0A\00"
@.str.5 = [49 x i8] c"\D0\9A\D0\BE\D0\B4 \D1\81\D1\82\D0\B0\D1\82\D1\83\D1\81\D0\B0 \D0\B7\D0\B0\D0\B2\D0\B5\D1\80\D1\88\D0\B5\D0\BD\D0\B8\D1\8F = %d\0A\00"
@str = [55 x i8] c"\D0\92\D1\8B\D0\BF\D0\BE\D0\BB\D0\BD\D1\8F\D0\B5\D1\82\D1\81\D1\8F \D0\B4\D0\BE\D1\87\D0\B5\D1\80\D0\BD\D0\B8\D0\B9 \D0\BF\D1\80\D0\BE\D1\86\D0\B5\D1\81\D1\81\00"
@str.6 = [63 x i8] c"\D0\92\D1\8B\D0\BF\D0\BE\D0\BB\D0\BD\D1\8F\D0\B5\D1\82\D1\81\D1\8F \D1\80\D0\BE\D0\B4\D0\B8\D1\82\D0\B5\D0\BB\D1\8C\D1\81\D0\BA\D0\B8\D0\B9 \D0\BF\D1\80\D0\BE\D1\86\D0\B5\D1\81\D1\81\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
switch i32 %3, label %9 [
i32 -1, label %4
i32 0, label %6
]
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %23
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 4)
unreachable
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.6, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0), i32 %3)
%12 = call i32 @waitpid(i32 %3, i32* %1, i32 0)
%13 = icmp eq i32 %3, %12
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32, i32* %1
%16 = call i32 @WIFEXITED(i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @.str.4, i64 0, i64 0), i32 %3)
%20 = load i32, i32* %1
%21 = call i32 @WIFEXITED(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %9, %14, %18, %4
%24 = phi i32 [ -1, %4 ], [ 0, %18 ], [ 0, %14 ], [ 0, %9 ]
ret i32 %24
}