#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ *compare_array(int *, int *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fmerge_sort(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ merge_sort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *read_file(char *, int *, int);
int /*<<< orphan*/ *write_file(char *, int *, int);
void test_simple_fmerge_sort() {
  int a[] = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  int b[16];
  FILE *f = 0;
  merge_sort(a, 0, 5);
  assert(write_file("file.temp", a, 16));
  f = fopen("file.temp", "rb");
  assert(f);
  fmerge_sort(f, sizeof(int) * 2, 16 * sizeof(int));
  fclose(f);
  assert(read_file("file.temp", b, 16));
  merge_sort(a, 0, 15);
  assert(compare_array(a, b, 16));
}


x86 assembly (clang, -O0):
<test_simple_fmerge_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x40(%rbp),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x40,%edx
call   1070 <memcpy@plt>
movq   $0x0,-0x88(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1090 <merge_sort@plt>
lea    -0x40(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x10,%edx
call   1050 <write_file@plt>
mov    %rax,%rdi
call   1060 <assert@plt>
lea    0xe51(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x88(%rbp),%rdi
mov    $0x8,%esi
mov    $0x40,%edx
call   1040 <fmerge_sort@plt>
mov    -0x88(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x80(%rbp),%rsi
lea    0xe05(%rip),%rdi
mov    $0x10,%edx
call   1080 <read_file@plt>
mov    %rax,%rdi
call   1060 <assert@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0xf,%edx
call   1090 <merge_sort@plt>
lea    -0x40(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <compare_array@plt>
mov    %rax,%rdi
call   1060 <assert@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_simple_fmerge_sort>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
movaps 0xe9d(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe81(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe65(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe49(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1080 <merge_sort@plt>
lea    0xe6c(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <write_file@plt>
mov    %rax,%rdi
call   1060 <assert@plt>
lea    0xe57(%rip),%rsi
mov    %r15,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    $0x40,%edx
call   1040 <fmerge_sort@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0x40(%rsp),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1070 <read_file@plt>
mov    %rax,%rdi
call   1060 <assert@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xf,%edx
call   1080 <merge_sort@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   10a0 <compare_array@plt>
mov    %rax,%rdi
call   1060 <assert@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.test_simple_fmerge_sort.a = [16 x i32] [i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1]
@.str = [10 x i8] c"file.temp\00"
@.str.1 = [3 x i8] c"rb\00"
define void @test_simple_fmerge_sort() {
%1 = alloca [16 x i32]
%2 = alloca [16 x i32]
%3 = alloca i32*
%4 = bitcast [16 x i32]* %1 to i8*
store i32* null, i32** %3
%5 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%6 = call i32 @merge_sort(i32* %5, i32 0, i32 5)
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%8 = call i32* @write_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %7, i32 16)
%9 = call i32 @assert(i32* %8)
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = call i32 @assert(i32* %11)
%13 = load i32*, i32** %3
%14 = call i32 @fmerge_sort(i32* %13, i32 8, i32 64)
%15 = load i32*, i32** %3
%16 = call i32 @fclose(i32* %15)
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%18 = call i32* @read_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %17, i32 16)
%19 = call i32 @assert(i32* %18)
%20 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%21 = call i32 @merge_sort(i32* %20, i32 0, i32 15)
%22 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%23 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%24 = call i32* @compare_array(i32* %22, i32* %23, i32 16)
%25 = call i32 @assert(i32* %24)
ret void
}

LLVM IR (-O2):
@__const.test_simple_fmerge_sort.a = [16 x i32] [i32 16, i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1]
@.str = [10 x i8] c"file.temp\00"
@.str.1 = [3 x i8] c"rb\00"
define void @test_simple_fmerge_sort() {
%1 = alloca [16 x i32]
%2 = alloca [16 x i32]
%3 = bitcast [16 x i32]* %1 to i8*
%4 = bitcast [16 x i32]* %2 to i8*
%5 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%6 = call i32 @merge_sort(i32* %5, i32 0, i32 5)
%7 = call i32* @write_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %5, i32 16)
%8 = call i32 @assert(i32* %7)
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @assert(i32* %9)
%11 = call i32 @fmerge_sort(i32* %9, i32 8, i32 64)
%12 = call i32 @fclose(i32* %9)
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%14 = call i32* @read_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %13, i32 16)
%15 = call i32 @assert(i32* %14)
%16 = call i32 @merge_sort(i32* %5, i32 0, i32 15)
%17 = call i32* @compare_array(i32* %5, i32* %13, i32 16)
%18 = call i32 @assert(i32* %17)
ret void
}