#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 /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int main(void) {
  int n = 10;
  int a = 0, b = 1;
  int pid, i;
  if ((pid = fork()) > 0) {
    for (i = 1; i <= n; i++) {
      a += i;
    }
    printf("%d", a);
  } else if (pid == 0) {
    for (i = 1; i <= n; i++) {
      b = b * i;
    }
    printf("%d", b);
    sleep(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    11a5 <main+0x75>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     1191 <main+0x61>
mov    -0x18(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116e <main+0x3e>
mov    -0xc(%rbp),%esi
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
jmp    11f8 <main+0xc8>
cmpl   $0x0,-0x14(%rbp)
jne    11f3 <main+0xc3>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11da <main+0xaa>
mov    -0x10(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b6 <main+0x86>
mov    -0x10(%rbp),%esi
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
jmp    11f8 <main+0xc8>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
jle    114f <main+0x1f>
lea    0xebd(%rip),%rdi
mov    $0x37,%esi
call   1030 <printf@plt>
jmp    116c <main+0x3c>
jne    116c <main+0x3c>
lea    0xea8(%rip),%rdi
mov    $0x375f00,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 10, i32* %2
store i32 0, i32* %3
store i32 1, i32* %4
%7 = call i32 (...) @fork()
store i32 %7, i32* %5
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %0
store i32 1, i32* %6
br label %10
10: ; preds = %18, %9
%11 = load i32, i32* %6
%12 = load i32, i32* %2
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i32, i32* %6
%16 = load i32, i32* %3
%17 = add nsw i32 %16, %15
store i32 %17, i32* %3
br label %18
18: ; preds = %14
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
br label %10
21: ; preds = %10
%22 = load i32, i32* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %22)
br label %44
24: ; preds = %0
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %43
27: ; preds = %24
store i32 1, i32* %6
br label %28
28: ; preds = %36, %27
%29 = load i32, i32* %6
%30 = load i32, i32* %2
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i32, i32* %4
%34 = load i32, i32* %6
%35 = mul nsw i32 %33, %34
store i32 %35, i32* %4
br label %36
36: ; preds = %32
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %28
39: ; preds = %28
%40 = load i32, i32* %4
%41 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = call i32 @sleep(i32 1)
br label %43
43: ; preds = %39, %24
br label %44
44: ; preds = %43, %21
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp sgt i32 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 55)
br label %10
5: ; preds = %0
%6 = icmp eq i32 %1, 0
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3628800)
%9 = tail call i32 @sleep(i32 1)
br label %10
10: ; preds = %5, %7, %3
ret i32 0
}