#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*/ merge(int *, int, int);
int /*<<< orphan*/ mergesort_seq(int *, int, int);
void mergesort_parall(int *v, int a, int b, int threads) {
  if (b - a <= 1)
    return;
  int m = a + (b - a) / 2;
  if (threads > 1) {
#pragma omp parallel sections
    {
#pragma omp section
      mergesort_parall(v, a, m, threads / 2);
#pragma omp section
      mergesort_parall(v, m, b, threads - threads / 2);
    }
  } else {
    mergesort_seq(v, a, m);
    mergesort_seq(v, m, b);
  }
  merge(v, a, b);
}


x86 assembly (clang, -O0):
<mergesort_parall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x1,%eax
jg     1159 <mergesort_parall+0x29>
jmp    11fc <mergesort_parall+0xcc>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    11cf <mergesort_parall+0x9f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
call   1030 <mergesort_parall@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x14(%rbp),%eax
mov    $0x2,%r8d
cltd
idiv   %r8d
mov    -0x20(%rbp),%edx
sub    %eax,%ecx
call   1030 <mergesort_parall@plt>
jmp    11ed <mergesort_parall+0xbd>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <mergesort_seq@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <mergesort_seq@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <merge@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergesort_parall>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
sub    %esi,%ebx
cmp    $0x2,%ebx
jge    1153 <mergesort_parall+0x23>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ecx,%r12d
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
shr    %ebx
add    %esi,%ebx
cmp    $0x2,%ecx
jl     1191 <mergesort_parall+0x61>
mov    %r12d,%r13d
shr    %r13d
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
call   1030 <mergesort_parall@plt>
sub    %r13d,%r12d
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r12d,%ecx
call   1030 <mergesort_parall@plt>
jmp    11aa <mergesort_parall+0x7a>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1050 <mergesort_seq@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1050 <mergesort_seq@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <merge@plt>

LLVM IR (-O0):
define void @mergesort_parall(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = sub nsw i32 %10, %11
%13 = icmp sle i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %4
br label %51
15: ; preds = %4
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = sub nsw i32 %17, %18
%20 = sdiv i32 %19, 2
%21 = add nsw i32 %16, %20
store i32 %21, i32* %9
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 1
br i1 %23, label %24, label %37
24: ; preds = %15
%25 = load i32*, i32** %5
%26 = load i32, i32* %6
%27 = load i32, i32* %9
%28 = load i32, i32* %8
%29 = sdiv i32 %28, 2
%30 = load i32*, i32** %5
%31 = load i32, i32* %9
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = load i32, i32* %8
%35 = sdiv i32 %34, 2
%36 = sub nsw i32 %33, %35
br label %46
37: ; preds = %15
%38 = load i32*, i32** %5
%39 = load i32, i32* %6
%40 = load i32, i32* %9
%41 = call i32 @mergesort_seq(i32* %38, i32 %39, i32 %40)
%42 = load i32*, i32** %5
%43 = load i32, i32* %9
%44 = load i32, i32* %7
%45 = call i32 @mergesort_seq(i32* %42, i32 %43, i32 %44)
br label %46
46: ; preds = %37, %24
%47 = load i32*, i32** %5
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = call i32 @merge(i32* %47, i32 %48, i32 %49)
br label %51
51: ; preds = %46, %14
ret void
}

LLVM IR (-O2):
define void @mergesort_parall(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = sub nsw i32 %2, %1
%6 = icmp slt i32 %5, 2
br i1 %6, label %19, label %7
7: ; preds = %4
%8 = lshr i32 %5, 1
%9 = add nsw i32 %8, %1
%10 = icmp sgt i32 %3, 1
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = lshr i32 %3, 1
tail call void @mergesort_parall(i32* %0, i32 %1, i32 %9, i32 %12)
%13 = sub nsw i32 %3, %12
tail call void @mergesort_parall(i32* %0, i32 %9, i32 %2, i32 %13)
br label %17
14: ; preds = %7
%15 = tail call i32 @mergesort_seq(i32* %0, i32 %1, i32 %9)
%16 = tail call i32 @mergesort_seq(i32* %0, i32 %9, i32 %2)
br label %17
17: ; preds = %14, %11
%18 = tail call i32 @merge(i32* %0, i32 %1, i32 %2)
br label %19
19: ; preds = %4, %17
ret void
}