#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_SUCCESS;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int getpgid(int);
int getpgrp();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int vfork();
void main() {
  int variable1 = 2;
  pid_t forkResult = vfork();
  if (forkResult == 0) {
    printf("PID %d: -Nooooooooooo\n", getpid());
    printf("Child process PID: %d\n", getpid());
    printf("Group process PID: %d\n", getpgrp());
    printf("Group leader PID: %d\n", getpgid(getpid()));
    printf("variable1 address = %p\n", &variable1);
    variable1 = 7;
    _exit(EXIT_SUCCESS);
  } else if (forkResult < 0) {
    printf("error :%d while trying to fork()\n", forkResult);
  } else {
    int status;
    printf("PID %d: ", getpid());
    printf("-New process, I'm you father !\n");
    printf("variable1 address = %p", &variable1);
    variable1 = 14;
  }
  printf("Variable 1: %d\n", variable1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x2,-0x4(%rbp)
call   1070 <vfork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    120b <main+0xab>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <getpgrp@plt>
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%edi
call   1080 <getpgid@plt>
mov    %eax,%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe70(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x7,-0x4(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
cmpl   $0x0,-0x8(%rbp)
jge    122b <main+0xcb>
mov    -0x8(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1269 <main+0x109>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe67(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xe,-0x4(%rbp)
jmp    126e <main+0x10e>
mov    -0x4(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x2,0xc(%rsp)
call   1080 <vfork@plt>
test   %eax,%eax
je     11f8 <main+0x88>
js     11cf <main+0x5f>
xor    %eax,%eax
mov    %eax,%ebx
call   1050 <getpid@plt>
lea    0xefd(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%eax
call   1060 <printf@plt>
lea    0xf1d(%rip),%rdi
call   1040 <puts@plt>
lea    0xeea(%rip),%rdi
lea    0xc(%rsp),%rsi
mov    %ebx,%eax
call   1060 <printf@plt>
movl   $0xe,0xc(%rsp)
mov    $0xe,%esi
jmp    11e4 <main+0x74>
mov    %eax,%esi
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x2,%esi
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
mov    %eax,%ebx
call   1050 <getpid@plt>
lea    0xdf8(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
call   1050 <getpid@plt>
lea    0xdf8(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
call   1070 <getpgrp@plt>
lea    0xdf8(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
call   1050 <getpid@plt>
mov    %eax,%edi
call   1090 <getpgid@plt>
lea    0xdf1(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%eax
call   1060 <printf@plt>
lea    0xdf7(%rip),%rdi
lea    0xc(%rsp),%rsi
mov    %ebx,%eax
call   1060 <printf@plt>
movl   $0x7,0xc(%rsp)
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"PID %d: -Nooooooooooo\0A\00"
@.str.1 = [23 x i8] c"Child process PID: %d\0A\00"
@.str.2 = [23 x i8] c"Group process PID: %d\0A\00"
@.str.3 = [22 x i8] c"Group leader PID: %d\0A\00"
@.str.4 = [24 x i8] c"variable1 address = %p\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.5 = [34 x i8] c"error :%d while trying to fork()\0A\00"
@.str.6 = [9 x i8] c"PID %d: \00"
@.str.7 = [32 x i8] c"-New process, I'm you father !\0A\00"
@.str.8 = [23 x i8] c"variable1 address = %p\00"
@.str.9 = [16 x i8] c"Variable 1: %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 2, i32* %1
%4 = call i32 @vfork()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %0
%8 = call i32 (...) @getpid()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 (...) @getpid()
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @getpgrp()
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = call i32 (...) @getpid()
%15 = call i32 @getpgid(i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32* %1)
store i32 7, i32* %1
%18 = load i32, i32* @EXIT_SUCCESS
%19 = call i32 @_exit(i32 %18)
unreachable
20: ; preds = %0
%21 = load i32, i32* %2
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %24)
br label %31
26: ; preds = %20
%27 = call i32 (...) @getpid()
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32* %1)
store i32 14, i32* %1
br label %31
31: ; preds = %26, %23
br label %32
32: ; preds = %31
%33 = load i32, i32* %1
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %33)
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"PID %d: -Nooooooooooo\0A\00"
@.str.1 = [23 x i8] c"Child process PID: %d\0A\00"
@.str.2 = [23 x i8] c"Group process PID: %d\0A\00"
@.str.3 = [22 x i8] c"Group leader PID: %d\0A\00"
@.str.4 = [24 x i8] c"variable1 address = %p\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.5 = [34 x i8] c"error :%d while trying to fork()\0A\00"
@.str.6 = [9 x i8] c"PID %d: \00"
@.str.8 = [23 x i8] c"variable1 address = %p\00"
@.str.9 = [16 x i8] c"Variable 1: %d\0A\00"
@str = [31 x i8] c"-New process, I'm you father !\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 2, i32* %1
%3 = call i32 @vfork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %0
%6 = call i32 (...) @getpid()
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 (...) @getpid()
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i32 (...) @getpgrp()
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @getpid()
%13 = call i32 @getpgid(i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32* %1)
store i32 7, i32* %1
%16 = load i32, i32* @EXIT_SUCCESS
%17 = call i32 @_exit(i32 %16)
unreachable
18: ; preds = %0
%19 = icmp slt i32 %3, 0
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %3)
br label %27
22: ; preds = %18
%23 = call i32 (...) @getpid()
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32* %1)
store i32 14, i32* %1
br label %27
27: ; preds = %20, %22
%28 = phi i32 [ 2, %20 ], [ 14, %22 ]
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %28)
ret void
}