#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*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sort_asc(int);
int /*<<< orphan*/ sort_desc(int);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int status;
  switch (fork()) {
  case -1:
    perror("Fork error");
    return -1;
  case 0:
    printf("The child sort in ascending order:\n");
    sort_asc(10);
    break;
  default:
    wait(&status);
    printf("The parent sort in descending order:\n");
    sort_desc(10);
    break;
  }
  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)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
sub    $0xffffffff,%eax
je     11a0 <main+0x40>
jmp    1190 <main+0x30>
mov    -0x18(%rbp),%eax
test   %eax,%eax
je     11b8 <main+0x58>
jmp    11d3 <main+0x73>
lea    0xe59(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <main+0x99>
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <sort_asc@plt>
jmp    11f2 <main+0x92>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1050 <sort_desc@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     119b <main+0x3b>
cmp    $0xffffffff,%eax
je     11b9 <main+0x59>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1050 <sort_desc@plt>
xor    %ebx,%ebx
jmp    11b1 <main+0x51>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1040 <sort_asc@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe40(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11b1 <main+0x51>

LLVM IR (-O0):
@.str = [11 x i8] c"Fork error\00"
@.str.1 = [36 x i8] c"The child sort in ascending order:\0A\00"
@.str.2 = [38 x i8] c"The parent sort in descending order:\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @fork()
switch i32 %7, label %13 [
i32 -1, label %8
i32 0, label %10
]
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %18
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @sort_asc(i32 10)
br label %17
13: ; preds = %2
%14 = call i32 @wait(i32* %6)
%15 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @sort_desc(i32 10)
br label %17
17: ; preds = %13, %10
store i32 0, i32* %3
br label %18
18: ; preds = %17, %8
%19 = load i32, i32* %3
ret i32 %19
}

LLVM IR (-O2):
@.str = [11 x i8] c"Fork error\00"
@str = [35 x i8] c"The child sort in ascending order:\00"
@str.3 = [37 x i8] c"The parent sort in descending order:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (...) @fork()
switch i32 %5, label %11 [
i32 -1, label %6
i32 0, label %8
]
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %15
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @sort_asc(i32 10)
br label %15
11: ; preds = %2
%12 = call i32 @wait(i32* %3)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.3, i64 0, i64 0))
%14 = call i32 @sort_desc(i32 10)
br label %15
15: ; preds = %8, %11, %6
%16 = phi i32 [ -1, %6 ], [ 0, %11 ], [ 0, %8 ]
ret i32 %16
}