#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 MAP_ANON;
int MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
scalar_t__ fork();
int *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char const *argv[]) {
  int *ptr = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE,
                  MAP_SHARED | MAP_ANON, -1, 0);
  *ptr = 0;
  if (fork() == 0) {
    int i = 0;
    for (i = 0; i < 100; i++) {
      (*ptr)++;
    }
    printf("hijo %d\n", *ptr);
    return 0;
  }
  int i = 0;
  for (i = 0; i < 100; i++) {
    (*ptr)--;
  }
  wait(NULL);
  printf("%d\n", *ptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
mov    0x2e6a(%rip),%rax
or     (%rax),%edx
mov    0x2e79(%rip),%rax
mov    (%rax),%ecx
mov    0x2e50(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x4,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    11ff <main+0xbf>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x64,-0x1c(%rbp)
jge    11e1 <main+0xa1>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11be <main+0x7e>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1252 <main+0x112>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x64,-0x20(%rbp)
jge    1230 <main+0xf0>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    120d <main+0xcd>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xdbf(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e8e(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x4,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
movl   $0x0,(%rax)
xor    %eax,%eax
call   1060 <fork@plt>
mov    (%rbx),%esi
test   %rax,%rax
je     11a8 <main+0x68>
add    $0xffffff9c,%esi
mov    %esi,(%rbx)
xor    %edi,%edi
call   1050 <wait@plt>
mov    (%rbx),%esi
lea    0xe5f(%rip),%rdi
jmp    11b4 <main+0x74>
add    $0x64,%esi
mov    %esi,(%rbx)
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANON = global i32 0
@.str = [9 x i8] c"hijo %d\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @PROT_READ
%10 = load i32, i32* @PROT_WRITE
%11 = or i32 %9, %10
%12 = load i32, i32* @MAP_SHARED
%13 = load i32, i32* @MAP_ANON
%14 = or i32 %12, %13
%15 = call i32* @mmap(i32* null, i32 4, i32 %11, i32 %14, i32 -1, i32 0)
store i32* %15, i32** %6
%16 = load i32*, i32** %6
store i32 0, i32* %16
%17 = call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %34
19: ; preds = %2
store i32 0, i32* %7
store i32 0, i32* %7
br label %20
20: ; preds = %27, %19
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 100
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = load i32*, i32** %6
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1
store i32 %26, i32* %24
br label %27
27: ; preds = %23
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %20
30: ; preds = %20
%31 = load i32*, i32** %6
%32 = load i32, i32* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %32)
store i32 0, i32* %3
br label %50
34: ; preds = %2
store i32 0, i32* %8
store i32 0, i32* %8
br label %35
35: ; preds = %42, %34
%36 = load i32, i32* %8
%37 = icmp slt i32 %36, 100
br i1 %37, label %38, label %45
38: ; preds = %35
%39 = load i32*, i32** %6
%40 = load i32, i32* %39
%41 = add nsw i32 %40, -1
store i32 %41, i32* %39
br label %42
42: ; preds = %38
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %35
45: ; preds = %35
%46 = call i32 @wait(i32* null)
%47 = load i32*, i32** %6
%48 = load i32, i32* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %48)
store i32 0, i32* %3
br label %50
50: ; preds = %45, %30
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANON = global i32 0
@.str = [9 x i8] c"hijo %d\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %4, %3
%6 = load i32, i32* @MAP_SHARED
%7 = load i32, i32* @MAP_ANON
%8 = or i32 %7, %6
%9 = tail call i32* @mmap(i32* null, i32 4, i32 %5, i32 %8, i32 -1, i32 0)
store i32 0, i32* %9
%10 = tail call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
%12 = load i32, i32* %9
br i1 %11, label %18, label %13
13: ; preds = %2
%14 = add i32 %12, -100
store i32 %14, i32* %9
%15 = tail call i32 @wait(i32* null)
%16 = load i32, i32* %9
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %21
18: ; preds = %2
%19 = add i32 %12, 100
store i32 %19, i32* %9
%20 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %13, %18
ret i32 0
}