#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*/ Intercala(int, int, int, int *);
int /*<<< orphan*/ debug(char *, int *);
int /*<<< orphan*/ printf(char *, int, int, int);
void MergesortI(int n, int v[]) {
  int p, r, b = 1;
  while (b < n) {
    p = 0;
    while (p + b < n) {
      r = p + 2 * b;
      if (r > n)
        r = n;
      printf("Intercala(%2d, %2d, %2d, v)\n", p, p + b, r);
      Intercala(p, p + b, r, v);
      p = p + 2 * b;
    }
    b = 2 * b;
    debug("Inter  ", v);
  }
}


x86 assembly (clang, -O0):
<MergesortI>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11e6 <MergesortI+0xb6>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c8 <MergesortI+0x98>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jle    1188 <MergesortI+0x58>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
add    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
add    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1050 <Intercala@plt>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <MergesortI+0x29>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1030 <debug@plt>
jmp    1146 <MergesortI+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MergesortI>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     11f0 <MergesortI+0xc0>
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1,%ecx
mov    %rsi,(%rsp)
jmp    1177 <MergesortI+0x47>
nopw   0x0(%rax,%rax,1)
lea    0xeb6(%rip),%rdi
mov    %r14,%rsi
call   1030 <debug@plt>
mov    %r15d,%ecx
cmp    %ebp,%r15d
jge    11f0 <MergesortI+0xc0>
lea    (%rcx,%rcx,1),%r15d
cmp    %ebp,%ecx
lea    0xe7c(%rip),%r13
jge    1160 <MergesortI+0x30>
xor    %ebx,%ebx
mov    %r15,0x10(%rsp)
mov    %rcx,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rcx,%rbx,1),%r14d
lea    (%rbx,%r15,1),%r12d
cmp    %ebp,%r12d
mov    %r12d,%r15d
cmovg  %ebp,%r15d
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
call   1040 <printf@plt>
mov    %ebx,%edi
mov    %r14d,%esi
mov    %r15d,%edx
mov    0x10(%rsp),%r15
mov    (%rsp),%r14
mov    %r14,%rcx
call   1050 <Intercala@plt>
mov    0x8(%rsp),%rcx
lea    (%rcx,%r12,1),%eax
mov    %r12d,%ebx
cmp    %ebp,%eax
jl     11a0 <MergesortI+0x70>
jmp    1160 <MergesortI+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Intercala(%2d, %2d, %2d, v)\0A\00"
@.str.1 = [8 x i8] c"Inter \00"
define void @MergesortI(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 1, i32* %7
br label %8
8: ; preds = %47, %2
%9 = load i32, i32* %7
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %52
12: ; preds = %8
store i32 0, i32* %5
br label %13
13: ; preds = %29, %12
%14 = load i32, i32* %5
%15 = load i32, i32* %7
%16 = add nsw i32 %14, %15
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %47
19: ; preds = %13
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = mul nsw i32 2, %21
%23 = add nsw i32 %20, %22
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = load i32, i32* %3
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = load i32, i32* %3
store i32 %28, i32* %6
br label %29
29: ; preds = %27, %19
%30 = load i32, i32* %5
%31 = load i32, i32* %5
%32 = load i32, i32* %7
%33 = add nsw i32 %31, %32
%34 = load i32, i32* %6
%35 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %33, i32 %34)
%36 = load i32, i32* %5
%37 = load i32, i32* %5
%38 = load i32, i32* %7
%39 = add nsw i32 %37, %38
%40 = load i32, i32* %6
%41 = load i32*, i32** %4
%42 = call i32 @Intercala(i32 %36, i32 %39, i32 %40, i32* %41)
%43 = load i32, i32* %5
%44 = load i32, i32* %7
%45 = mul nsw i32 2, %44
%46 = add nsw i32 %43, %45
store i32 %46, i32* %5
br label %13
47: ; preds = %13
%48 = load i32, i32* %7
%49 = mul nsw i32 2, %48
store i32 %49, i32* %7
%50 = load i32*, i32** %4
%51 = call i32 @debug(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %50)
br label %8
52: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Intercala(%2d, %2d, %2d, v)\0A\00"
@.str.1 = [8 x i8] c"Inter \00"
define void @MergesortI(i32 %0, i32* %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %21
4: ; preds = %2, %18
%5 = phi i32 [ %7, %18 ], [ 1, %2 ]
%6 = icmp slt i32 %5, %0
%7 = shl nsw i32 %5, 1
br i1 %6, label %8, label %18
8: ; preds = %4, %8
%9 = phi i32 [ %16, %8 ], [ %5, %4 ]
%10 = phi i32 [ %11, %8 ], [ 0, %4 ]
%11 = add nsw i32 %10, %7
%12 = icmp sgt i32 %11, %0
%13 = select i1 %12, i32 %0, i32 %11
%14 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %9, i32 %13)
%15 = tail call i32 @Intercala(i32 %10, i32 %9, i32 %13, i32* %1)
%16 = add nuw nsw i32 %11, %5
%17 = icmp slt i32 %16, %0
br i1 %17, label %8, label %18
18: ; preds = %8, %4
%19 = tail call i32 @debug(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%20 = icmp slt i32 %7, %0
br i1 %20, label %4, label %21
21: ; preds = %18, %2
ret void
}