#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*/ copy(char *, char *, int);
int /*<<< orphan*/ distribute(char **, char *, int, int (*)(void *, void *),
                              int);
int mergesort(char **, int, int (*)(void *, void *), int *);
int fsort(char *sortedfilename, char *unsortedfilename, int elementsize,
          int (*elementorder)(void *, void *), int heapsize,
          char **auxfilename) {
  int sortedfilenumber, mergepasses;
  distribute(auxfilename, unsortedfilename, elementsize, elementorder,
             heapsize);
  sortedfilenumber =
      mergesort(auxfilename, elementsize, elementorder, &mergepasses);
  copy(sortedfilename, auxfilename[sortedfilenumber], elementsize);
  return mergepasses + 2;
}


x86 assembly (clang, -O0):
<fsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
call   1050 <distribute@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1040 <mergesort@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x14(%rbp),%edx
call   1030 <copy@plt>
mov    -0x38(%rbp),%eax
add    $0x2,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rdi,%r15
mov    %r9,%rdi
call   1050 <distribute@plt>
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1040 <mergesort@plt>
cltq
mov    (%rbx,%rax,8),%rsi
mov    %r15,%rdi
mov    %ebp,%edx
call   1030 <copy@plt>
mov    0x4(%rsp),%eax
add    $0x2,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fsort(i8* %0, i8* %1, i32 %2, i32 (i8*, i8*)* %3, i32 %4, i8** %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32 (i8*, i8*)*
%11 = alloca i32
%12 = alloca i8**
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %10
store i32 %4, i32* %11
store i8** %5, i8*** %12
%15 = load i8**, i8*** %12
%16 = load i8*, i8** %8
%17 = load i32, i32* %9
%18 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
%19 = load i32, i32* %11
%20 = call i32 @distribute(i8** %15, i8* %16, i32 %17, i32 (i8*, i8*)* %18, i32 %19)
%21 = load i8**, i8*** %12
%22 = load i32, i32* %9
%23 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %10
%24 = call i32 @mergesort(i8** %21, i32 %22, i32 (i8*, i8*)* %23, i32* %14)
store i32 %24, i32* %13
%25 = load i8*, i8** %7
%26 = load i8**, i8*** %12
%27 = load i32, i32* %13
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = load i32, i32* %9
%32 = call i32 @copy(i8* %25, i8* %30, i32 %31)
%33 = load i32, i32* %14
%34 = add nsw i32 %33, 2
ret i32 %34
}

LLVM IR (-O2):
define i32 @fsort(i8* %0, i8* %1, i32 %2, i32 (i8*, i8*)* %3, i32 %4, i8** %5) {
%7 = alloca i32
%8 = bitcast i32* %7 to i8*
%9 = tail call i32 @distribute(i8** %5, i8* %1, i32 %2, i32 (i8*, i8*)* %3, i32 %4)
%10 = call i32 @mergesort(i8** %5, i32 %2, i32 (i8*, i8*)* %3, i32* %7)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8*, i8** %5, i64 %11
%13 = load i8*, i8** %12
%14 = call i32 @copy(i8* %0, i8* %13, i32 %2)
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 2
ret i32 %16
}