#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, int *);
int switchcopy(int);
int *trimarray(int *, int, int *, int);
int mergesort_itr(int A[(2)][(25)], int fullsize) {
  int samplesize = 1, arraysize;
  int copyfrom = (0);
  int begin, begin1, size1, begin2, size2;
  int mdst, msrc = 1;
  int *arr1, *arr2, *res;
  while (samplesize <= fullsize) {
    msrc = switchcopy(msrc);
    mdst = 1 - msrc;
    samplesize = samplesize * 2;
    begin = 0;
    while (begin < fullsize) {
      begin1 = begin;
      size1 = samplesize / 2;
      begin2 = begin1 + size1;
      size2 = samplesize / 2;
      arr1 = trimarray(A[msrc], begin1, &size1, fullsize);
      arr2 = trimarray(A[msrc], begin2, &size2, fullsize);
      res = &A[mdst][begin1];
      merge(arr1, size1, arr2, size2, res);
      begin = begin + samplesize;
    }
  }
  return mdst;
}


x86 assembly (clang, -O0):
<mergesort_itr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1249 <mergesort_itr+0x119>
mov    -0x34(%rbp),%edi
call   1050 <switchcopy@plt>
mov    %eax,-0x34(%rbp)
mov    $0x1,%eax
sub    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1244 <mergesort_itr+0x114>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x34(%rbp),%rax
imul   $0x64,%rax,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%esi
mov    -0xc(%rbp),%ecx
lea    -0x24(%rbp),%rdx
call   1030 <trimarray@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x34(%rbp),%rax
imul   $0x64,%rax,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%esi
mov    -0xc(%rbp),%ecx
lea    -0x2c(%rbp),%rdx
call   1030 <trimarray@plt>
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x30(%rbp),%rcx
imul   $0x64,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x48(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x50(%rbp),%r8
call   1040 <merge@plt>
mov    -0x1c(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1186 <mergesort_itr+0x56>
jmp    1154 <mergesort_itr+0x24>
mov    -0x30(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergesort_itr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
test   %esi,%esi
jle    1265 <mergesort_itr+0x135>
mov    %rdi,%rbp
mov    %esi,%ebx
lea    0x64(%rdi),%rax
mov    %rax,0x20(%rsp)
mov    $0x1,%eax
lea    0x8(%rsp),%r15
mov    $0x1,%edi
mov    %rbp,0x28(%rsp)
mov    %esi,0xc(%rsp)
mov    %rbx,0x30(%rsp)
mov    0xc(%rsp),%r12d
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%r14d
call   1050 <switchcopy@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
mov    %ecx,0x14(%rsp)
mov    %r14,0x50(%rsp)
lea    (%r14,%r14,1),%ecx
mov    %eax,0x1c(%rsp)
cltq
imul   $0x64,%rax,%rdx
add    %rbp,%rdx
mov    %rdx,0x48(%rsp)
mov    %ecx,0x18(%rsp)
movslq %ecx,%rcx
imul   $0xffffffffffffff9c,%rax,%r13
add    0x20(%rsp),%r13
mov    %rcx,0x40(%rsp)
lea    0x0(,%rcx,4),%rax
mov    %rax,0x38(%rsp)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x50(%rsp),%r14
mov    %r14d,0x8(%rsp)
mov    %r14d,0x10(%rsp)
mov    0x48(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %r12d,%ecx
call   1030 <trimarray@plt>
mov    %rax,%r15
lea    (%r14,%rbp,1),%esi
mov    %rbx,%rdi
lea    0x10(%rsp),%rdx
mov    %r12d,%ecx
call   1030 <trimarray@plt>
mov    0x8(%rsp),%esi
mov    0x10(%rsp),%ecx
mov    %r15,%rdi
lea    0x8(%rsp),%r15
mov    0x30(%rsp),%rbx
mov    %rax,%rdx
mov    %r13,%r8
call   1040 <merge@plt>
add    0x40(%rsp),%rbp
add    0x38(%rsp),%r13
cmp    %rbx,%rbp
jl     11e0 <mergesort_itr+0xb0>
mov    0x18(%rsp),%eax
mov    0xc(%rsp),%esi
cmp    %esi,%eax
mov    0x28(%rsp),%rbp
mov    0x1c(%rsp),%edi
jle    1180 <mergesort_itr+0x50>
jmp    1265 <mergesort_itr+0x135>
mov    0x14(%rsp),%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @mergesort_itr([25 x i32]* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp slt i32 %1, 1
br i1 %7, label %35, label %8
8: ; preds = %2
%9 = zext i32 %1 to i64
br label %12
10: ; preds = %22
%11 = icmp sgt i32 %17, %1
br i1 %11, label %35, label %12
12: ; preds = %10, %8
%13 = phi i32 [ 1, %8 ], [ %17, %10 ]
%14 = phi i32 [ 1, %8 ], [ %15, %10 ]
%15 = call i32 @switchcopy(i32 %14)
%16 = sub nsw i32 1, %15
%17 = shl i32 %13, 1
%18 = sext i32 %15 to i64
%19 = getelementptr inbounds [25 x i32], [25 x i32]* %0, i64 %18, i64 0
%20 = sext i32 %16 to i64
%21 = sext i32 %17 to i64
br label %22
22: ; preds = %12, %22
%23 = phi i64 [ 0, %12 ], [ %33, %22 ]
store i32 %13, i32* %3
store i32 %13, i32* %4
%24 = trunc i64 %23 to i32
%25 = call i32* @trimarray(i32* %19, i32 %24, i32* %3, i32 %1)
%26 = trunc i64 %23 to i32
%27 = add i32 %13, %26
%28 = call i32* @trimarray(i32* %19, i32 %27, i32* %4, i32 %1)
%29 = getelementptr inbounds [25 x i32], [25 x i32]* %0, i64 %20, i64 %23
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call i32 @merge(i32* %25, i32 %30, i32* %28, i32 %31, i32* %29)
%33 = add i64 %23, %21
%34 = icmp slt i64 %33, %9
br i1 %34, label %22, label %10
35: ; preds = %10, %2
%36 = phi i32 [ undef, %2 ], [ %16, %10 ]
ret i32 %36
}