#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[], char *env[]) {
  int i, a = 1;
  for (i = 0; i < 10; i++) {
    switch (fork()) {
    case 0:
      a = 3;
      printf("a=%d\n", a);
      break;
    case -1:
      printf("Error al crear el proceso hijo\n");
      exit(0);
    default:
      printf("a=%d\n", a);
      break;
    }
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11e2 <main+0xb2>
xor    %eax,%eax
call   1050 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
sub    $0xffffffff,%eax
je     11a9 <main+0x79>
jmp    117c <main+0x4c>
mov    -0x24(%rbp),%eax
test   %eax,%eax
jne    11be <main+0x8e>
jmp    118c <main+0x5c>
movl   $0x3,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cf <main+0x9f>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <exit@plt>
mov    -0x20(%rbp),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d4 <main+0xa4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1158 <main+0x28>
xor    %edi,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
mov    $0x3,%ebx
mov    $0x3,%ebp
test   %eax,%eax
je     1166 <main+0x26>
cmp    $0xffffffff,%eax
je     12ed <main+0x1ad>
mov    $0x1,%ebp
lea    0xe93(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     12ed <main+0x1ad>
test   %eax,%eax
je     118c <main+0x4c>
mov    %ebp,%ebx
lea    0xe6d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     12ed <main+0x1ad>
mov    $0x3,%ebp
test   %eax,%eax
je     11b7 <main+0x77>
mov    %ebx,%ebp
lea    0xe42(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     12ed <main+0x1ad>
mov    $0x3,%ebx
test   %eax,%eax
je     11e2 <main+0xa2>
mov    %ebp,%ebx
lea    0xe17(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     12ed <main+0x1ad>
mov    $0x3,%ebp
test   %eax,%eax
je     120d <main+0xcd>
mov    %ebx,%ebp
lea    0xdec(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     12ed <main+0x1ad>
mov    $0x3,%ebx
test   %eax,%eax
je     1238 <main+0xf8>
mov    %ebp,%ebx
lea    0xdc1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     12ed <main+0x1ad>
mov    $0x3,%ebp
test   %eax,%eax
je     1263 <main+0x123>
mov    %ebx,%ebp
lea    0xd96(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     12ed <main+0x1ad>
mov    $0x3,%ebx
test   %eax,%eax
je     128a <main+0x14a>
mov    %ebp,%ebx
lea    0xd6f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     12ed <main+0x1ad>
mov    $0x3,%ebp
test   %eax,%eax
je     12b1 <main+0x171>
mov    %ebx,%ebp
lea    0xd48(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     12ed <main+0x1ad>
mov    $0x3,%esi
test   %eax,%eax
je     12d8 <main+0x198>
mov    %ebp,%esi
lea    0xd21(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xd12(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"a=%d\0A\00"
@.str.1 = [32 x i8] c"Error al crear el proceso hijo\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 1, i32* %9
store i32 0, i32* %8
br label %10
10: ; preds = %25, %3
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %28
13: ; preds = %10
%14 = call i32 (...) @fork()
switch i32 %14, label %21 [
i32 0, label %15
i32 -1, label %18
]
15: ; preds = %13
store i32 3, i32* %9
%16 = load i32, i32* %9
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %24
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %13
%22 = load i32, i32* %9
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %15
br label %25
25: ; preds = %24
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %10
28: ; preds = %10
%29 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"a=%d\0A\00"
@str = [31 x i8] c"Error al crear el proceso hijo\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = tail call i32 (...) @fork()
switch i32 %4, label %8 [
i32 0, label %9
i32 -1, label %5
]
5: ; preds = %49, %44, %39, %34, %29, %24, %19, %14, %9, %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %3
br label %9
9: ; preds = %3, %8
%10 = phi i32 [ 1, %8 ], [ 3, %3 ]
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = tail call i32 (...) @fork()
switch i32 %12, label %13 [
i32 0, label %14
i32 -1, label %5
]
13: ; preds = %9
br label %14
14: ; preds = %9, %13
%15 = phi i32 [ %10, %13 ], [ 3, %9 ]
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = tail call i32 (...) @fork()
switch i32 %17, label %18 [
i32 0, label %19
i32 -1, label %5
]
18: ; preds = %14
br label %19
19: ; preds = %14, %18
%20 = phi i32 [ %15, %18 ], [ 3, %14 ]
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = tail call i32 (...) @fork()
switch i32 %22, label %23 [
i32 0, label %24
i32 -1, label %5
]
23: ; preds = %19
br label %24
24: ; preds = %19, %23
%25 = phi i32 [ %20, %23 ], [ 3, %19 ]
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = tail call i32 (...) @fork()
switch i32 %27, label %28 [
i32 0, label %29
i32 -1, label %5
]
28: ; preds = %24
br label %29
29: ; preds = %24, %28
%30 = phi i32 [ %25, %28 ], [ 3, %24 ]
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = tail call i32 (...) @fork()
switch i32 %32, label %33 [
i32 0, label %34
i32 -1, label %5
]
33: ; preds = %29
br label %34
34: ; preds = %29, %33
%35 = phi i32 [ %30, %33 ], [ 3, %29 ]
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = tail call i32 (...) @fork()
switch i32 %37, label %38 [
i32 0, label %39
i32 -1, label %5
]
38: ; preds = %34
br label %39
39: ; preds = %34, %38
%40 = phi i32 [ %35, %38 ], [ 3, %34 ]
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = tail call i32 (...) @fork()
switch i32 %42, label %43 [
i32 0, label %44
i32 -1, label %5
]
43: ; preds = %39
br label %44
44: ; preds = %39, %43
%45 = phi i32 [ %40, %43 ], [ 3, %39 ]
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %45)
%47 = tail call i32 (...) @fork()
switch i32 %47, label %48 [
i32 0, label %49
i32 -1, label %5
]
48: ; preds = %44
br label %49
49: ; preds = %44, %48
%50 = phi i32 [ %45, %48 ], [ 3, %44 ]
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %50)
%52 = tail call i32 (...) @fork()
switch i32 %52, label %53 [
i32 0, label %54
i32 -1, label %5
]
53: ; preds = %49
br label %54
54: ; preds = %49, %53
%55 = phi i32 [ %50, %53 ], [ 3, %49 ]
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = tail call i32 @exit(i32 0)
unreachable
}