#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
pid_t make_process(pid_t *process, int number) {
  pid_t p = fork();
  if (p != 0) {
    process[number++] = p;
    return p;
  }
  int times = 0;
  while (1) {
    sleep(1);
    times++;
    printf("in process %d\n", getpid());
    if (times == 2)
      break;
  }
  return p;
}


x86 assembly (clang, -O0):
<make_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118c <make_process+0x4c>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d7 <make_process+0x97>
movl   $0x0,-0x24(%rbp)
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x2,-0x24(%rbp)
jne    11ca <make_process+0x8a>
jmp    11cf <make_process+0x8f>
jmp    1193 <make_process+0x53>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_process>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1161 <make_process+0x21>
movslq %ebp,%rax
mov    %rbx,(%r14,%rax,8)
jmp    119e <make_process+0x5e>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe87(%rip),%rbp
mov    %rbp,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"in process %d\0A\00"
define i64 @make_process(i64* nocapture writeonly %0, i32 %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @sleep(i32 1)
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %15
12: ; preds = %2
%13 = sext i32 %1 to i64
%14 = getelementptr inbounds i64, i64* %0, i64 %13
store i64 %3, i64* %14
br label %15
15: ; preds = %5, %12
ret i64 %3
}