#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ creat(char *, int);
int /*<<< orphan*/ execl(char *, char *, char *);
int /*<<< orphan*/ exit(int);
int fork();
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ panic(char *);
int /*<<< orphan*/ wait(int *);
void sort_xref() {
  int status, pid;
  pid = fork();
  if (pid > 0) {
    wait(&status);
    if (status != 0)
      panic("couldn't sort cross references");
  } else {
    close(0);
    close(1);
    if (open("xref.tmp", O_RDONLY) < 0)
      exit(1);
    if (creat("xref.sort", 0644) < 0)
      exit(2);
    execl("/bin/sort", "sort", (char *)0);
    execl("/usr/bin/sort", "sort", (char *)0);
    exit(3);
  }
}


x86 assembly (clang, -O0):
<sort_xref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11c0 <sort_xref+0x40>
lea    -0x4(%rbp),%rdi
call   1090 <wait@plt>
cmpl   $0x0,-0x4(%rbp)
je     11bb <sort_xref+0x3b>
lea    0xe4a(%rip),%rdi
call   1030 <panic@plt>
jmp    1257 <sort_xref+0xd7>
xor    %edi,%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1050 <open@plt>
cmp    $0x0,%rax
jge    11fa <sort_xref+0x7a>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe27(%rip),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
cmp    $0x0,%rax
jge    121f <sort_xref+0x9f>
mov    $0x2,%edi
call   1070 <exit@plt>
lea    0xe10(%rip),%rdi
lea    0xe00(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <execl@plt>
lea    0xdf5(%rip),%rdi
lea    0xde9(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <execl@plt>
mov    $0x3,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_xref>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
jle    11b3 <sort_xref+0x33>
lea    0xc(%rsp),%rdi
call   1090 <wait@plt>
cmpl   $0x0,0xc(%rsp)
je     11ad <sort_xref+0x2d>
lea    0xe58(%rip),%rdi
call   1030 <panic@plt>
add    $0x10,%rsp
pop    %rbx
ret
xor    %edi,%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
lea    0xe4b(%rip),%rdi
call   1050 <open@plt>
test   %rax,%rax
jns    11e8 <sort_xref+0x68>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe39(%rip),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
test   %rax,%rax
jns    1208 <sort_xref+0x88>
mov    $0x2,%edi
call   1070 <exit@plt>
lea    0xe27(%rip),%rdi
lea    0xe17(%rip),%rbx
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <execl@plt>
lea    0xe0b(%rip),%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <execl@plt>
mov    $0x3,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"couldn't sort cross references\00"
@.str.1 = [9 x i8] c"xref.tmp\00"
@O_RDONLY = global i32 0
@.str.2 = [10 x i8] c"xref.sort\00"
@.str.3 = [10 x i8] c"/bin/sort\00"
@.str.4 = [5 x i8] c"sort\00"
@.str.5 = [14 x i8] c"/usr/bin/sort\00"
define void @sort_xref() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = call i32 @wait(i32* %1)
%8 = load i32, i32* %1
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 @panic(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
br label %30
13: ; preds = %0
%14 = call i32 @close(i32 0)
%15 = call i32 @close(i32 1)
%16 = load i32, i32* @O_RDONLY
%17 = call i64 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = call i64 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 420)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @exit(i32 2)
unreachable
26: ; preds = %21
%27 = call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* null)
%28 = call i32 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* null)
%29 = call i32 @exit(i32 3)
unreachable
30: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"couldn't sort cross references\00"
@.str.1 = [9 x i8] c"xref.tmp\00"
@O_RDONLY = global i32 0
@.str.2 = [10 x i8] c"xref.sort\00"
@.str.3 = [10 x i8] c"/bin/sort\00"
@.str.4 = [5 x i8] c"sort\00"
@.str.5 = [14 x i8] c"/usr/bin/sort\00"
define void @sort_xref() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = call i32 @wait(i32* %1)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %28, label %9
9: ; preds = %5
%10 = call i32 @panic(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %28
11: ; preds = %0
%12 = tail call i32 @close(i32 0)
%13 = tail call i32 @close(i32 1)
%14 = load i32, i32* @O_RDONLY
%15 = tail call i64 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = tail call i64 @creat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 420)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @exit(i32 2)
unreachable
24: ; preds = %19
%25 = tail call i32 @execl(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* null)
%26 = tail call i32 @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* null)
%27 = tail call i32 @exit(i32 3)
unreachable
28: ; preds = %5, %9
ret void
}