#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ compareArrays(int *, int *, int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printArray(int *, int);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void testAlgorithms(void (*alg1)(int *, int, bool),
                    void (*alg2)(int *, int, bool), int test_num,
                    bool isOrderASC) {
  srand(time(NULL));
  for (int i = 0; i < test_num; i++) {
    int n = rand() % 20 + 10;
    int *pt_array1 = (int *)malloc(n * sizeof(int));
    int *pt_array2 = (int *)malloc(n * sizeof(int));
    for (int j = 0; j < n; j++) {
      pt_array1[j] = pt_array2[j] = rand() % 100 - 50;
    }
    if (false) {
      printf("--------------------------------------------------\n");
      printf("arrays before being sorted:\n");
      printArray(pt_array1, n);
    }
    alg1(pt_array1, n, true);
    alg2(pt_array2, n, true);
    if (false) {
      printf("arrays after being sorted:\n");
      printArray(pt_array1, n);
      printArray(pt_array2, n);
    }
    assert(compareArrays(pt_array1, pt_array2, n));
    free(pt_array1);
    free(pt_array2);
  }
}


x86 assembly (clang, -O0):
<testAlgorithms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1288 <testAlgorithms+0x118>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x14,%ecx
cltd
idiv   %ecx
add    $0xa,%edx
mov    %edx,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    122d <testAlgorithms+0xbd>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
sub    $0x32,%edx
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11eb <testAlgorithms+0x7b>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    $0x1,%edx
call   *%rax
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    $0x1,%edx
call   *%rax
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <compareArrays@plt>
mov    %eax,%edi
call   1060 <assert@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119d <testAlgorithms+0x2d>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testAlgorithms>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,0x10(%rsp)
mov    %rdi,0x8(%rsp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    %ebx,0x4(%rsp)
test   %ebx,%ebx
jle    12ae <testAlgorithms+0x13e>
xor    %r14d,%r14d
jmp    1202 <testAlgorithms+0x92>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r13d,%esi
mov    $0x1,%edx
call   *0x8(%rsp)
mov    %rbp,%rdi
mov    %r13d,%esi
mov    $0x1,%edx
call   *0x10(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
call   1030 <compareArrays@plt>
mov    %eax,%edi
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
add    $0x1,%r14d
cmp    0x4(%rsp),%r14d
je     12ae <testAlgorithms+0x13e>
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
shl    $0x2,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%r15d
sub    %ecx,%r15d
neg    %ecx
lea    (%rax,%rcx,1),%r13d
add    $0xa,%r13d
lea    0x28(,%r15,4),%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
cmp    $0xfffffff7,%r15d
jl     11b0 <testAlgorithms+0x40>
mov    %r13d,%r15d
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
neg    %ecx
add    %ecx,%eax
add    $0xffffffce,%eax
mov    %eax,0x0(%rbp,%r12,4)
mov    %eax,(%rbx,%r12,4)
add    $0x1,%r12
cmp    %r12,%r15
jne    1270 <testAlgorithms+0x100>
jmp    11b0 <testAlgorithms+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @testAlgorithms(void (i32*, i32, i32)* %0, void (i32*, i32, i32)* %1, i32 %2, i32 %3) {
%5 = alloca void (i32*, i32, i32)*
%6 = alloca void (i32*, i32, i32)*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
store void (i32*, i32, i32)* %0, void (i32*, i32, i32)** %5
store void (i32*, i32, i32)* %1, void (i32*, i32, i32)** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = call i32 @time(i32* null)
%15 = call i32 @srand(i32 %14)
store i32 0, i32* %9
br label %16
16: ; preds = %71, %4
%17 = load i32, i32* %9
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %74
20: ; preds = %16
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 20
%23 = add nsw i32 %22, 10
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 4
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i32*
store i32* %29, i32** %11
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = trunc i64 %32 to i32
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i32*
store i32* %35, i32** %12
store i32 0, i32* %13
br label %36
36: ; preds = %52, %20
%37 = load i32, i32* %13
%38 = load i32, i32* %10
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %55
40: ; preds = %36
%41 = call i32 (...) @rand()
%42 = srem i32 %41, 100
%43 = sub nsw i32 %42, 50
%44 = load i32*, i32** %12
%45 = load i32, i32* %13
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
store i32 %43, i32* %47
%48 = load i32*, i32** %11
%49 = load i32, i32* %13
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
store i32 %43, i32* %51
br label %52
52: ; preds = %40
%53 = load i32, i32* %13
%54 = add nsw i32 %53, 1
store i32 %54, i32* %13
br label %36
55: ; preds = %36
%56 = load void (i32*, i32, i32)*, void (i32*, i32, i32)** %5
%57 = load i32*, i32** %11
%58 = load i32, i32* %10
%59 = load void (i32*, i32, i32)*, void (i32*, i32, i32)** %6
%60 = load i32*, i32** %12
%61 = load i32, i32* %10
%62 = load i32*, i32** %11
%63 = load i32*, i32** %12
%64 = load i32, i32* %10
%65 = call i32 @compareArrays(i32* %62, i32* %63, i32 %64)
%66 = call i32 @assert(i32 %65)
%67 = load i32*, i32** %11
%68 = call i32 @free(i32* %67)
%69 = load i32*, i32** %12
%70 = call i32 @free(i32* %69)
br label %71
71: ; preds = %55
%72 = load i32, i32* %9
%73 = add nsw i32 %72, 1
store i32 %73, i32* %9
br label %16
74: ; preds = %16
ret void
}

LLVM IR (-O2):
define void @testAlgorithms(void (i32*, i32, i32)* nocapture %0, void (i32*, i32, i32)* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %9, label %8
8: ; preds = %22, %4
ret void
9: ; preds = %4, %22
%10 = phi i32 [ %27, %22 ], [ 0, %4 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 20
%13 = add nsw i32 %12, 10
%14 = shl nsw i32 %13, 2
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
%17 = tail call i64 @malloc(i32 %14)
%18 = inttoptr i64 %17 to i32*
%19 = icmp sgt i32 %12, -10
br i1 %19, label %20, label %22
20: ; preds = %9
%21 = zext i32 %13 to i64
br label %29
22: ; preds = %29, %9
tail call void %0(i32* %16, i32 %13, i32 1)
tail call void %1(i32* %18, i32 %13, i32 1)
%23 = tail call i32 @compareArrays(i32* %16, i32* %18, i32 %13)
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i32 @free(i32* %16)
%26 = tail call i32 @free(i32* %18)
%27 = add nuw nsw i32 %10, 1
%28 = icmp eq i32 %27, %2
br i1 %28, label %8, label %9
29: ; preds = %20, %29
%30 = phi i64 [ 0, %20 ], [ %36, %29 ]
%31 = tail call i32 (...) @rand()
%32 = srem i32 %31, 100
%33 = add nsw i32 %32, -50
%34 = getelementptr inbounds i32, i32* %18, i64 %30
store i32 %33, i32* %34
%35 = getelementptr inbounds i32, i32* %16, i64 %30
store i32 %33, i32* %35
%36 = add nuw nsw i64 %30, 1
%37 = icmp eq i64 %36, %21
br i1 %37, label %22, label %29
}