#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 main(int argc, char *argv[], char *env[]) {
  printf("--------------------LAB1--------------------\n");
  pid_t pid;
  pid = fork();
  int i;
  if (pid == -1) {
    exit(-1);
  } else if (pid == 0) {
    printf("Я сын и мой id:%d; А ид моего отца:%d\n", getpid(), getppid());
    for (i = 0; i < 10; i++)
      printf("Сын говорит: %d\n", i);
    printf("--------------------LAB1ENDchild--------------------\n");
  } else {
    printf("Я отец и мой id:%d; А ид моего сына:%d\n", getpid(), pid);
    for (i = 0; i < 100; i++)
      printf("Отец говорит: %d\n", i);
    printf("--------------------LAB1ENDparent--------------------\n");
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1196 <main+0x46>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1207 <main+0xb7>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0xa,-0x20(%rbp)
jge    11f4 <main+0xa4>
mov    -0x20(%rbp),%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11cb <main+0x7b>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125f <main+0x10f>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x64,-0x20(%rbp)
jge    1251 <main+0x101>
mov    -0x20(%rbp),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1228 <main+0xd8>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1264 <main+0x114>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xf45(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1190 <main+0x30>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1255 <main+0xf5>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe59(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe82(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec0(%rip),%r14
jmp    1294 <main+0x134>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdf3(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1e(%rip),%rbx
lea    0xe61(%rip),%r14
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1280 <main+0x120>
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"--------------------LAB1--------------------\0A\00"
@.str.1 = [59 x i8] c"\D0\AF \D1\81\D1\8B\D0\BD \D0\B8 \D0\BC\D0\BE\D0\B9 id:%d; \D0\90 \D0\B8\D0\B4 \D0\BC\D0\BE\D0\B5\D0\B3\D0\BE \D0\BE\D1\82\D1\86\D0\B0:%d\0A\00"
@.str.2 = [27 x i8] c"\D0\A1\D1\8B\D0\BD \D0\B3\D0\BE\D0\B2\D0\BE\D1\80\D0\B8\D1\82: %d\0A\00"
@.str.3 = [54 x i8] c"--------------------LAB1ENDchild--------------------\0A\00"
@.str.4 = [61 x i8] c"\D0\AF \D0\BE\D1\82\D0\B5\D1\86 \D0\B8 \D0\BC\D0\BE\D0\B9 id:%d; \D0\90 \D0\B8\D0\B4 \D0\BC\D0\BE\D0\B5\D0\B3\D0\BE \D1\81\D1\8B\D0\BD\D0\B0:%d\0A\00"
@.str.5 = [29 x i8] c"\D0\9E\D1\82\D0\B5\D1\86 \D0\B3\D0\BE\D0\B2\D0\BE\D1\80\D0\B8\D1\82: %d\0A\00"
@.str.6 = [55 x i8] c"--------------------LAB1ENDparent--------------------\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
%9 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (...) @fork()
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %3
%17 = load i32, i32* %8
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %34
19: ; preds = %16
%20 = call i32 (...) @getpid()
%21 = call i32 (...) @getppid()
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21)
store i32 0, i32* %9
br label %23
23: ; preds = %29, %19
%24 = load i32, i32* %9
%25 = icmp slt i32 %24, 10
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* %9
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
br label %23
32: ; preds = %23
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
br label %49
34: ; preds = %16
%35 = call i32 (...) @getpid()
%36 = load i32, i32* %8
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %35, i32 %36)
store i32 0, i32* %9
br label %38
38: ; preds = %44, %34
%39 = load i32, i32* %9
%40 = icmp slt i32 %39, 100
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i32, i32* %9
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %38
47: ; preds = %38
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0))
br label %49
49: ; preds = %47, %32
br label %50
50: ; preds = %49
%51 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [59 x i8] c"\D0\AF \D1\81\D1\8B\D0\BD \D0\B8 \D0\BC\D0\BE\D0\B9 id:%d; \D0\90 \D0\B8\D0\B4 \D0\BC\D0\BE\D0\B5\D0\B3\D0\BE \D0\BE\D1\82\D1\86\D0\B0:%d\0A\00"
@.str.2 = [27 x i8] c"\D0\A1\D1\8B\D0\BD \D0\B3\D0\BE\D0\B2\D0\BE\D1\80\D0\B8\D1\82: %d\0A\00"
@.str.4 = [61 x i8] c"\D0\AF \D0\BE\D1\82\D0\B5\D1\86 \D0\B8 \D0\BC\D0\BE\D0\B9 id:%d; \D0\90 \D0\B8\D0\B4 \D0\BC\D0\BE\D0\B5\D0\B3\D0\BE \D1\81\D1\8B\D0\BD\D0\B0:%d\0A\00"
@.str.5 = [29 x i8] c"\D0\9E\D1\82\D0\B5\D1\86 \D0\B3\D0\BE\D0\B2\D0\BE\D1\80\D0\B8\D1\82: %d\0A\00"
@str = [45 x i8] c"--------------------LAB1--------------------\00"
@str.7 = [54 x i8] c"--------------------LAB1ENDparent--------------------\00"
@str.8 = [53 x i8] c"--------------------LAB1ENDchild--------------------\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (...) @fork()
switch i32 %5, label %22 [
i32 -1, label %6
i32 0, label %8
]
6: ; preds = %3
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %3
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (...) @getppid()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 0)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 1)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 2)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 3)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 4)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 5)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 6)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 7)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 8)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 9)
br label %30
22: ; preds = %3
%23 = tail call i32 (...) @getpid()
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0), i32 %23, i32 %5)
br label %25
25: ; preds = %22, %25
%26 = phi i32 [ 0, %22 ], [ %28, %25 ]
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = add nuw nsw i32 %26, 1
%29 = icmp eq i32 %28, 100
br i1 %29, label %30, label %25
30: ; preds = %25, %8
%31 = phi i8* [ getelementptr inbounds ([53 x i8], [53 x i8]* @str.8, i64 0, i64 0), %8 ], [ getelementptr inbounds ([54 x i8], [54 x i8]* @str.7, i64 0, i64 0), %25 ]
%32 = tail call i32 @puts(i8* dereferenceable(1) %31)
%33 = tail call i32 @exit(i32 0)
unreachable
}