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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x2,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11f6 <main+0xa6>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getpgrp@plt>
mov    %eax,%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
call   1060 <getpgid@plt>
mov    %eax,%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
lea    0xe75(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125b <main+0x10b>
cmpl   $0x0,-0x8(%rbp)
jge    1216 <main+0xc6>
mov    -0x8(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1256 <main+0x106>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
lea    0xe10(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    125b <main+0x10b>
mov    -0x4(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x2,0x4(%rsp)
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11a7 <main+0x47>
js     1227 <main+0xc7>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xf0d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf16(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,0x4(%rsp)
jmp    1212 <main+0xb2>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getpgrp@plt>
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%edi
call   1070 <getpgid@plt>
lea    0xe44(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x3,0x4(%rsp)
lea    0xe42(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1237 <main+0xd7>
lea    0xe45(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
pop    %rax
ret

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"
@.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 = [16 x i8] c"Variable 1: %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
store i32 2, i32* %1
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %19
6: ; preds = %0
%7 = call i32 (...) @getpid()
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 (...) @getpid()
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 (...) @getpgrp()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i32 (...) @getpid()
%14 = call i32 @getpgid(i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32* %1)
br label %33
19: ; preds = %0
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %23)
br label %32
25: ; preds = %19
%26 = call i32 (...) @getpid()
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
%29 = load i32, i32* %1
%30 = add nsw i32 %29, -1
store i32 %30, i32* %1
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32* %1)
br label %32
32: ; preds = %25, %22
br label %33
33: ; preds = %32, %6
%34 = load i32, i32* %1
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %34)
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"
@.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 = [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 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %0
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = tail call i32 (...) @getpgrp()
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 @getpgid(i32 %12)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %13)
store i32 3, i32* %1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32* %1)
br label %25
16: ; preds = %0
%17 = icmp slt i32 %3, 0
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail 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 %25
20: ; preds = %16
%21 = tail call i32 (...) @getpid()
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
store i32 1, i32* %1
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32* %1)
br label %25
25: ; preds = %18, %20, %5
%26 = load i32, i32* %1
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i32 %26)
ret void
}