#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 */
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
scalar_t__ vfork();
void *routine2(void *data) {
  pid_t child = vfork();
  if (child == 0) {
    int i, j;
    puts("vforked");
    for (i = 0; i < 100000; ++i)
      for (j = 0; j < 10000; ++j)
        ;
    puts("vforked child exiting");
    _exit(0);
  }
  puts("parent continuing");
  return NULL;
}


x86 assembly (clang, -O0):
<routine2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <vfork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bf <routine2+0x8f>
lea    0xea7(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x186a0,-0x14(%rbp)
jge    11ac <routine2+0x7c>
movl   $0x0,-0x18(%rbp)
cmpl   $0x2710,-0x18(%rbp)
jge    1199 <routine2+0x69>
jmp    118b <routine2+0x5b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1179 <routine2+0x49>
jmp    119e <routine2+0x6e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <routine2+0x35>
lea    0xe55(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
lea    0xe58(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<routine2>:
push   %rax
xor    %eax,%eax
call   1050 <vfork@plt>
test   %rax,%rax
je     114d <routine2+0x1d>
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xeac(%rip),%rdi
call   1040 <puts@plt>
lea    0xea8(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"vforked\00"
@.str.1 = [22 x i8] c"vforked child exiting\00"
@.str.2 = [18 x i8] c"parent continuing\00"
define i8* @routine2(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i64 (...) @vfork()
store i64 %6, i64* %3
%7 = load i64, i64* %3
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %1
%10 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %11
11: ; preds = %23, %9
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 100000
br i1 %13, label %14, label %26
14: ; preds = %11
store i32 0, i32* %5
br label %15
15: ; preds = %19, %14
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 10000
br i1 %17, label %18, label %22
18: ; preds = %15
br label %19
19: ; preds = %18
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %15
22: ; preds = %15
br label %23
23: ; preds = %22
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %11
26: ; preds = %11
%27 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @_exit(i32 0)
unreachable
29: ; preds = %1
%30 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
ret i8* null
}

LLVM IR (-O2):
@.str = [8 x i8] c"vforked\00"
@.str.1 = [22 x i8] c"vforked child exiting\00"
@.str.2 = [18 x i8] c"parent continuing\00"
define noalias i8* @routine2(i8* nocapture readnone %0) {
%2 = tail call i64 (...) @vfork()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @_exit(i32 0)
unreachable
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
ret i8* null
}