#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 fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, int, ...);
void main(int argc, char **argv) {
  int x = 0;
  int pid;
  printf("%d --x est: %d\n", getpid(), x);
  pid = fork();
  if (pid == 0)
    x++;
  printf("%d --x est: %d adresse est %p\n", getpid(), x, &x);
  pid = fork();
  if (pid == 0)
    x++;
  printf("%d --x est: %d adresse est %p\n", getpid(), x, &x);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    117d <main+0x4d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe80(%rip),%rdi
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11b8 <main+0x88>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe45(%rip),%rdi
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xeb3(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
jne    1170 <main+0x40>
movl   $0x1,0xc(%rsp)
mov    $0x1,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe92(%rip),%rdi
lea    0xc(%rsp),%rcx
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
jne    119e <main+0x6e>
addl   $0x1,0xc(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0xc(%rsp),%edx
lea    0xe60(%rip),%rdi
lea    0xc(%rsp),%rcx
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"%d --x est: %d\0A\00"
@.str.1 = [31 x i8] c"%d --x est: %d adresse est %p\0A\00"
define void @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5, i32 0)
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 1, i32* %3
br label %10
10: ; preds = %9, %2
%11 = phi i32 [ 1, %9 ], [ 0, %2 ]
%12 = tail call i32 (...) @getpid()
%13 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %11, i32* %3)
%14 = call i32 (...) @fork()
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %10
%20 = call i32 (...) @getpid()
%21 = load i32, i32* %3
%22 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21, i32* %3)
ret void
}