#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 scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ comp(void *, scalar_t__, scalar_t__,
                int (*)(void const *, void const *, void *), void *, scalar_t__,
                scalar_t__);
int /*<<< orphan*/ copy(void *, void *, scalar_t__, scalar_t__, scalar_t__,
                        scalar_t__);
int merge(void *base, ssize_t nmemb, ssize_t size,
          int (*compare)(const void *a, const void *b, void *context),
          void *context, void *aux, ssize_t lo, ssize_t mid, ssize_t hi) {
  ssize_t i;
  ssize_t j;
  ssize_t k;
  (void)nmemb;
  for (k = lo; k <= hi; k++) {
    copy(aux, base, nmemb, size, k, k);
  }
  i = lo;
  j = mid + 1;
  for (k = lo; k <= hi; k++) {
    if (i > mid) {
      copy(base, aux, nmemb, size, k, j);
      j++;
    } else if (j > hi) {
      copy(base, aux, nmemb, size, k, i);
      i++;
    } else if (comp(aux, nmemb, size, compare, context, j, i) < 0) {
      copy(base, aux, nmemb, size, k, j);
      j++;
    } else {
      copy(base, aux, nmemb, size, k, i);
      i++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    0x20(%rbp),%rax
jg     1190 <merge+0x70>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x48(%rbp),%r9
call   1040 <copy@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1154 <merge+0x34>
mov    0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    0x20(%rbp),%rax
jg     12d8 <merge+0x1b8>
mov    -0x38(%rbp),%rax
cmp    0x18(%rbp),%rax
jle    11f6 <merge+0xd6>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x40(%rbp),%r9
call   1040 <copy@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12c2 <merge+0x1a2>
mov    -0x40(%rbp),%rax
cmp    0x20(%rbp),%rax
jle    1232 <merge+0x112>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x38(%rbp),%r9
call   1040 <copy@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12bd <merge+0x19d>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x40(%rbp),%r9
mov    -0x38(%rbp),%rax
mov    %rax,(%rsp)
call   1030 <comp@plt>
cmp    $0x0,%rax
jge    128f <merge+0x16f>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x40(%rbp),%r9
call   1040 <copy@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12b8 <merge+0x198>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x38(%rbp),%r9
call   1040 <copy@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12bd <merge+0x19d>
jmp    12c2 <merge+0x1a2>
jmp    12c7 <merge+0x1a7>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    11ac <merge+0x8c>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,0x50(%rsp)
mov    %rcx,0x48(%rsp)
mov    0x90(%rsp),%rbp
cmp    0xa0(%rsp),%rbp
jg     11bc <merge+0x9c>
mov    %rdx,%rbx
mov    %rsi,%rdx
mov    %rdi,%rax
mov    0xa0(%rsp),%rcx
add    $0x1,%rcx
mov    %rbx,0x20(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r9,%rdi
mov    %rax,%r15
mov    %rax,%rsi
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rbx,%rcx
mov    %rbp,%r8
mov    %r9,%r13
mov    %rbp,%r9
call   1040 <copy@plt>
mov    %r14,%rdx
mov    0x20(%rsp),%rbx
mov    %r13,%r9
mov    %r12,%rcx
mov    %r15,%rax
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1170 <merge+0x50>
mov    0x90(%rsp),%rbp
cmp    0xa0(%rsp),%rbp
jle    11cd <merge+0xad>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x98(%rsp),%rcx
lea    0x1(%rcx),%r10
mov    %rbp,%r11
mov    %r14,0x18(%rsp)
mov    %r13,0x38(%rsp)
mov    %r15,0x30(%rsp)
jmp    1236 <merge+0x116>
nopl   (%rax)
mov    %rax,%rdi
mov    %r9,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rbp,%rbx
mov    %rbp,%r8
mov    %r10,%r9
mov    %r11,%rbp
call   1040 <copy@plt>
mov    %rbp,%r11
mov    0x10(%rsp),%r10
mov    %rbx,%rbp
mov    %r14,%rdx
mov    0x20(%rsp),%rbx
mov    %r13,%r9
mov    %r12,%rcx
mov    %r15,%rax
add    $0x1,%r10
add    $0x1,%rbp
cmp    %rbp,%rcx
je     11bc <merge+0x9c>
cmp    0x98(%rsp),%r11
mov    %r10,0x10(%rsp)
jg     11f0 <merge+0xd0>
cmp    0xa0(%rsp),%r10
jle    1290 <merge+0x170>
mov    %rax,%rdi
mov    %r9,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rbp,%rbx
mov    %rbp,%r8
mov    %r11,%r9
mov    %r11,%rbp
call   1040 <copy@plt>
mov    %rbp,%r11
mov    0x10(%rsp),%r10
mov    %rbx,%rbp
mov    %r14,%rdx
mov    0x20(%rsp),%rbx
mov    %r13,%r9
mov    %r12,%rcx
mov    %r15,%rax
add    $0x1,%r11
jmp    122d <merge+0x10d>
xchg   %ax,%ax
mov    %rbp,0x40(%rsp)
mov    %r11,(%rsp)
mov    %r9,%rdi
mov    %rdx,%rsi
mov    %rbx,%rdx
mov    0x48(%rsp),%rcx
mov    0x50(%rsp),%r8
mov    %r9,%rbp
mov    %r10,%r9
mov    %r11,0x28(%rsp)
call   1030 <comp@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
test   %rax,%rax
js     130e <merge+0x1ee>
mov    0x18(%rsp),%rdx
mov    %rbx,%rcx
mov    0x40(%rsp),%rbx
mov    %rbx,%r8
mov    0x28(%rsp),%r9
call   1040 <copy@plt>
mov    %rbx,%rbp
mov    0x30(%rsp),%rax
mov    0x28(%rsp),%r11
add    $0x1,%r11
mov    %r12,%rcx
mov    0x38(%rsp),%r9
mov    0x20(%rsp),%rbx
mov    0x18(%rsp),%rdx
mov    0x10(%rsp),%r10
jmp    122d <merge+0x10d>
mov    0x18(%rsp),%rdx
mov    %rbx,%rcx
mov    0x40(%rsp),%rbp
mov    %rbp,%r8
mov    0x10(%rsp),%r9
call   1040 <copy@plt>
mov    0x30(%rsp),%rax
mov    0x10(%rsp),%r10
add    $0x1,%r10
mov    %r12,%rcx
mov    0x38(%rsp),%r9
mov    0x18(%rsp),%rdx
mov    0x28(%rsp),%r11
jmp    122d <merge+0x10d>

LLVM IR (-O0):
define i32 @merge(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i8* %5, i64 %6, i64 %7, i64 %8) {
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32 (i8*, i8*, i8*)*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
%21 = alloca i64
store i8* %0, i8** %10
store i64 %1, i64* %11
store i64 %2, i64* %12
store i32 (i8*, i8*, i8*)* %3, i32 (i8*, i8*, i8*)** %13
store i8* %4, i8** %14
store i8* %5, i8** %15
store i64 %6, i64* %16
store i64 %7, i64* %17
store i64 %8, i64* %18
%22 = load i64, i64* %11
%23 = load i64, i64* %16
store i64 %23, i64* %21
br label %24
24: ; preds = %36, %9
%25 = load i64, i64* %21
%26 = load i64, i64* %18
%27 = icmp sle i64 %25, %26
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = load i8*, i8** %15
%30 = load i8*, i8** %10
%31 = load i64, i64* %11
%32 = load i64, i64* %12
%33 = load i64, i64* %21
%34 = load i64, i64* %21
%35 = call i32 @copy(i8* %29, i8* %30, i64 %31, i64 %32, i64 %33, i64 %34)
br label %36
36: ; preds = %28
%37 = load i64, i64* %21
%38 = add nsw i64 %37, 1
store i64 %38, i64* %21
br label %24
39: ; preds = %24
%40 = load i64, i64* %16
store i64 %40, i64* %19
%41 = load i64, i64* %17
%42 = add nsw i64 %41, 1
store i64 %42, i64* %20
%43 = load i64, i64* %16
store i64 %43, i64* %21
br label %44
44: ; preds = %109, %39
%45 = load i64, i64* %21
%46 = load i64, i64* %18
%47 = icmp sle i64 %45, %46
br i1 %47, label %48, label %112
48: ; preds = %44
%49 = load i64, i64* %19
%50 = load i64, i64* %17
%51 = icmp sgt i64 %49, %50
br i1 %51, label %52, label %62
52: ; preds = %48
%53 = load i8*, i8** %10
%54 = load i8*, i8** %15
%55 = load i64, i64* %11
%56 = load i64, i64* %12
%57 = load i64, i64* %21
%58 = load i64, i64* %20
%59 = call i32 @copy(i8* %53, i8* %54, i64 %55, i64 %56, i64 %57, i64 %58)
%60 = load i64, i64* %20
%61 = add nsw i64 %60, 1
store i64 %61, i64* %20
br label %108
62: ; preds = %48
%63 = load i64, i64* %20
%64 = load i64, i64* %18
%65 = icmp sgt i64 %63, %64
br i1 %65, label %66, label %76
66: ; preds = %62
%67 = load i8*, i8** %10
%68 = load i8*, i8** %15
%69 = load i64, i64* %11
%70 = load i64, i64* %12
%71 = load i64, i64* %21
%72 = load i64, i64* %19
%73 = call i32 @copy(i8* %67, i8* %68, i64 %69, i64 %70, i64 %71, i64 %72)
%74 = load i64, i64* %19
%75 = add nsw i64 %74, 1
store i64 %75, i64* %19
br label %107
76: ; preds = %62
%77 = load i8*, i8** %15
%78 = load i64, i64* %11
%79 = load i64, i64* %12
%80 = load i32 (i8*, i8*, i8*)*, i32 (i8*, i8*, i8*)** %13
%81 = load i8*, i8** %14
%82 = load i64, i64* %20
%83 = load i64, i64* %19
%84 = call i64 @comp(i8* %77, i64 %78, i64 %79, i32 (i8*, i8*, i8*)* %80, i8* %81, i64 %82, i64 %83)
%85 = icmp slt i64 %84, 0
br i1 %85, label %86, label %96
86: ; preds = %76
%87 = load i8*, i8** %10
%88 = load i8*, i8** %15
%89 = load i64, i64* %11
%90 = load i64, i64* %12
%91 = load i64, i64* %21
%92 = load i64, i64* %20
%93 = call i32 @copy(i8* %87, i8* %88, i64 %89, i64 %90, i64 %91, i64 %92)
%94 = load i64, i64* %20
%95 = add nsw i64 %94, 1
store i64 %95, i64* %20
br label %106
96: ; preds = %76
%97 = load i8*, i8** %10
%98 = load i8*, i8** %15
%99 = load i64, i64* %11
%100 = load i64, i64* %12
%101 = load i64, i64* %21
%102 = load i64, i64* %19
%103 = call i32 @copy(i8* %97, i8* %98, i64 %99, i64 %100, i64 %101, i64 %102)
%104 = load i64, i64* %19
%105 = add nsw i64 %104, 1
store i64 %105, i64* %19
br label %106
106: ; preds = %96, %86
br label %107
107: ; preds = %106, %66
br label %108
108: ; preds = %107, %52
br label %109
109: ; preds = %108
%110 = load i64, i64* %21
%111 = add nsw i64 %110, 1
store i64 %111, i64* %21
br label %44
112: ; preds = %44
ret i32 0
}

LLVM IR (-O2):
define i32 @merge(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i8* %5, i64 %6, i64 %7, i64 %8) {
%10 = icmp sgt i64 %6, %8
br i1 %10, label %46, label %11
11: ; preds = %9, %11
%12 = phi i64 [ %14, %11 ], [ %6, %9 ]
%13 = tail call i32 @copy(i8* %5, i8* %0, i64 %1, i64 %2, i64 %12, i64 %12)
%14 = add i64 %12, 1
%15 = icmp eq i64 %12, %8
br i1 %15, label %16, label %11
16: ; preds = %11
br i1 %10, label %46, label %17
17: ; preds = %16
%18 = add nsw i64 %7, 1
br label %19
19: ; preds = %17, %41
%20 = phi i64 [ %44, %41 ], [ %6, %17 ]
%21 = phi i64 [ %43, %41 ], [ %18, %17 ]
%22 = phi i64 [ %42, %41 ], [ %6, %17 ]
%23 = icmp sgt i64 %22, %7
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = tail call i32 @copy(i8* %0, i8* %5, i64 %1, i64 %2, i64 %20, i64 %21)
%26 = add nsw i64 %21, 1
br label %41
27: ; preds = %19
%28 = icmp sgt i64 %21, %8
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = tail call i32 @copy(i8* %0, i8* %5, i64 %1, i64 %2, i64 %20, i64 %22)
%31 = add nsw i64 %22, 1
br label %41
32: ; preds = %27
%33 = tail call i64 @comp(i8* %5, i64 %1, i64 %2, i32 (i8*, i8*, i8*)* %3, i8* %4, i64 %21, i64 %22)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = tail call i32 @copy(i8* %0, i8* %5, i64 %1, i64 %2, i64 %20, i64 %21)
%37 = add nsw i64 %21, 1
br label %41
38: ; preds = %32
%39 = tail call i32 @copy(i8* %0, i8* %5, i64 %1, i64 %2, i64 %20, i64 %22)
%40 = add nsw i64 %22, 1
br label %41
41: ; preds = %24, %35, %38, %29
%42 = phi i64 [ %22, %24 ], [ %31, %29 ], [ %22, %35 ], [ %40, %38 ]
%43 = phi i64 [ %26, %24 ], [ %21, %29 ], [ %37, %35 ], [ %21, %38 ]
%44 = add i64 %20, 1
%45 = icmp eq i64 %20, %8
br i1 %45, label %46, label %19
46: ; preds = %41, %9, %16
ret i32 0
}