#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sleep(int);
int main() {
  int id = 1;
  int a, b;
  while (1) {
    if (id == 1) {
      a = 1;
      b = 5000;
    } else if (id == 2) {
      a = 5001;
      b = 10000;
    }
    if (fork()) {
      if (id++ < 2) {
        continue;
      }
      while (1) {
        printf("parent:%d\n", getpid());
        sleep(1);
      }
      exit(1);
    } else {
      while (1) {
        printf("child:%d,a:%d,b:%d\n", getpid(), a, b);
        sleep(1);
      }
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1173 <main+0x33>
movl   $0x1,-0xc(%rbp)
movl   $0x1388,-0x10(%rbp)
jmp    1190 <main+0x50>
cmpl   $0x2,-0x8(%rbp)
jne    118b <main+0x4b>
movl   $0x1389,-0xc(%rbp)
movl   $0x2710,-0x10(%rbp)
jmp    1190 <main+0x50>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
je     11e5 <main+0xa5>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x2,%eax
jge    11ba <main+0x7a>
jmp    1156 <main+0x16>
jmp    11bf <main+0x7f>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    11bf <main+0x7f>
jmp    11ea <main+0xaa>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    11ea <main+0xaa>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     118f <main+0x4f>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     119b <main+0x5b>
lea    0xe9d(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1170 <main+0x30>
mov    $0x1388,%ebx
mov    $0x1,%ebp
jmp    11a5 <main+0x65>
mov    $0x2710,%ebx
mov    $0x1389,%ebp
lea    0xe5f(%rip),%r14
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    11b0 <main+0x70>

LLVM IR (-O0):
@.str = [11 x i8] c"parent:%d\0A\00"
@.str.1 = [20 x i8] c"child:%d,a:%d,b:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
br label %5
5: ; preds = %0, %21
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %5
store i32 1, i32* %3
store i32 5000, i32* %4
br label %14
9: ; preds = %5
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 5001, i32* %3
store i32 10000, i32* %4
br label %13
13: ; preds = %12, %9
br label %14
14: ; preds = %13, %8
%15 = call i64 (...) @fork()
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %14
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
%20 = icmp slt i32 %18, 2
br i1 %20, label %21, label %22
21: ; preds = %17
br label %5
22: ; preds = %17
br label %23
23: ; preds = %22, %23
%24 = call i32 (...) @getpid()
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = call i32 @sleep(i32 1)
br label %23
27: ; preds = %14
br label %28
28: ; preds = %27, %28
%29 = call i32 (...) @getpid()
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %30, i32 %31)
%33 = call i32 @sleep(i32 1)
br label %28
}

LLVM IR (-O2):
@.str = [11 x i8] c"parent:%d\0A\00"
@.str.1 = [20 x i8] c"child:%d,a:%d,b:%d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %6, %0
%4 = phi i32 [ 1, %0 ], [ 5001, %6 ]
%5 = phi i32 [ 5000, %0 ], [ 10000, %6 ]
br label %13
6: ; preds = %0
%7 = tail call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %3, label %9
9: ; preds = %6, %9
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = tail call i32 @sleep(i32 1)
br label %9
13: ; preds = %3, %13
%14 = tail call i32 (...) @getpid()
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %4, i32 %5)
%16 = tail call i32 @sleep(i32 1)
br label %13
}