#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*/ copy(double *, double *, int, double);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ transpose_aligned(double *, double *, int, int, double);
int /*<<< orphan*/ transpose_misaligned(double *, double *, int, int, double);
void tce_sort_2_(double *unsorted, double *sorted, int *a_in, int *b_in,
                 int *i_in, int *j_in, double *factor_in) {
  int a = *a_in;
  int b = *b_in;
  int i = *i_in;
  int j = *j_in;
  double factor = *factor_in;
  if (i == 1 && j == 2) {
    copy(unsorted, sorted, a * b, factor);
    return;
  }
  if (a <= 0 || b <= 0) {
    printf("Dimensions must be larger than zero! \n");
  } else if (a % (64 / sizeof(double)) == 0 && b % (64 / sizeof(double)) == 0 &&
             (long)unsorted % 64 == 0 && (long)sorted % 64 == 0) {
    transpose_aligned(unsorted, sorted, a, b, factor);
  } else {
    transpose_misaligned(unsorted, sorted, a, b, factor);
  }
}


x86 assembly (clang, -O0):
<tce_sort_2_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
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    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x1,-0x3c(%rbp)
jne    11c7 <tce_sort_2_+0x87>
cmpl   $0x2,-0x40(%rbp)
jne    11c7 <tce_sort_2_+0x87>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%edx
imul   -0x38(%rbp),%edx
movsd  -0x48(%rbp),%xmm0
call   1050 <copy@plt>
jmp    127a <tce_sort_2_+0x13a>
cmpl   $0x0,-0x34(%rbp)
jle    11db <tce_sort_2_+0x9b>
cmpl   $0x0,-0x38(%rbp)
jg     11ec <tce_sort_2_+0xac>
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
jmp    127a <tce_sort_2_+0x13a>
movslq -0x34(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    125d <tce_sort_2_+0x11d>
movslq -0x38(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    125d <tce_sort_2_+0x11d>
mov    -0x8(%rbp),%rax
mov    $0x40,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    125d <tce_sort_2_+0x11d>
mov    -0x10(%rbp),%rax
mov    $0x40,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    125d <tce_sort_2_+0x11d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
movsd  -0x48(%rbp),%xmm0
call   1030 <transpose_aligned@plt>
jmp    1275 <tce_sort_2_+0x135>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
movsd  -0x48(%rbp),%xmm0
call   1060 <transpose_misaligned@plt>
jmp    127a <tce_sort_2_+0x13a>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tce_sort_2_>:
mov    0x8(%rsp),%rax
mov    (%rdx),%edx
mov    (%rcx),%ecx
movsd  (%rax),%xmm0
cmpl   $0x1,(%r8)
jne    1163 <tce_sort_2_+0x23>
cmpl   $0x2,(%r9)
jne    1163 <tce_sort_2_+0x23>
imul   %edx,%ecx
mov    %ecx,%edx
jmp    1050 <copy@plt>
test   %edx,%edx
jle    1186 <tce_sort_2_+0x46>
test   %ecx,%ecx
jle    1186 <tce_sort_2_+0x46>
mov    %esi,%eax
or     %edi,%eax
test   $0x3f,%al
jne    1192 <tce_sort_2_+0x52>
mov    %edx,%eax
and    $0x7,%eax
jne    1192 <tce_sort_2_+0x52>
mov    %ecx,%eax
and    $0x7,%eax
jne    1192 <tce_sort_2_+0x52>
jmp    1040 <transpose_aligned@plt>
lea    0xe73(%rip),%rdi
jmp    1030 <puts@plt>
jmp    1060 <transpose_misaligned@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"Dimensions must be larger than zero! \0A\00"
define void @tce_sort_2_(double* %0, double* %1, i32* %2, i32* %3, i32* %4, i32* %5, double* %6) {
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
store double* %0, double** %8
store double* %1, double** %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
store double* %6, double** %14
%20 = load i32*, i32** %10
%21 = load i32, i32* %20
store i32 %21, i32* %15
%22 = load i32*, i32** %11
%23 = load i32, i32* %22
store i32 %23, i32* %16
%24 = load i32*, i32** %12
%25 = load i32, i32* %24
store i32 %25, i32* %17
%26 = load i32*, i32** %13
%27 = load i32, i32* %26
store i32 %27, i32* %18
%28 = load double*, double** %14
%29 = load double, double* %28
store double %29, double* %19
%30 = load i32, i32* %17
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %43
32: ; preds = %7
%33 = load i32, i32* %18
%34 = icmp eq i32 %33, 2
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = load double*, double** %8
%37 = load double*, double** %9
%38 = load i32, i32* %15
%39 = load i32, i32* %16
%40 = mul nsw i32 %38, %39
%41 = load double, double* %19
%42 = call i32 @copy(double* %36, double* %37, i32 %40, double %41)
br label %86
43: ; preds = %32, %7
%44 = load i32, i32* %15
%45 = icmp sle i32 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i32, i32* %16
%48 = icmp sle i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46, %43
%50 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %86
51: ; preds = %46
%52 = load i32, i32* %15
%53 = sext i32 %52 to i64
%54 = urem i64 %53, 8
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %78
56: ; preds = %51
%57 = load i32, i32* %16
%58 = sext i32 %57 to i64
%59 = urem i64 %58, 8
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %78
61: ; preds = %56
%62 = load double*, double** %8
%63 = ptrtoint double* %62 to i64
%64 = srem i64 %63, 64
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %78
66: ; preds = %61
%67 = load double*, double** %9
%68 = ptrtoint double* %67 to i64
%69 = srem i64 %68, 64
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %66
%72 = load double*, double** %8
%73 = load double*, double** %9
%74 = load i32, i32* %15
%75 = load i32, i32* %16
%76 = load double, double* %19
%77 = call i32 @transpose_aligned(double* %72, double* %73, i32 %74, i32 %75, double %76)
br label %85
78: ; preds = %66, %61, %56, %51
%79 = load double*, double** %8
%80 = load double*, double** %9
%81 = load i32, i32* %15
%82 = load i32, i32* %16
%83 = load double, double* %19
%84 = call i32 @transpose_misaligned(double* %79, double* %80, i32 %81, i32 %82, double %83)
br label %85
85: ; preds = %78, %71
br label %86
86: ; preds = %35, %85, %49
ret void
}

LLVM IR (-O2):
@str = [38 x i8] c"Dimensions must be larger than zero! \00"
define void @tce_sort_2_(double* %0, double* %1, i32* nocapture %2, i32* nocapture %3, i32* nocapture %4, i32* nocapture %5, double* nocapture %6) {
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = load double, double* %6
%13 = icmp eq i32 %10, 1
%14 = icmp eq i32 %11, 2
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %19
16: ; preds = %7
%17 = mul nsw i32 %9, %8
%18 = tail call i32 @copy(double* %0, double* %1, i32 %17, double %12)
br label %41
19: ; preds = %7
%20 = icmp slt i32 %8, 1
%21 = icmp slt i32 %9, 1
%22 = select i1 %20, i1 true, i1 %21
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %41
25: ; preds = %19
%26 = and i32 %8, 7
%27 = icmp eq i32 %26, 0
%28 = and i32 %9, 7
%29 = icmp eq i32 %28, 0
%30 = select i1 %27, i1 %29, i1 false
%31 = ptrtoint double* %0 to i64
%32 = ptrtoint double* %1 to i64
%33 = or i64 %32, %31
%34 = and i64 %33, 63
%35 = icmp eq i64 %34, 0
%36 = and i1 %35, %30
br i1 %36, label %37, label %39
37: ; preds = %25
%38 = tail call i32 @transpose_aligned(double* %0, double* %1, i32 %8, i32 %9, double %12)
br label %41
39: ; preds = %25
%40 = tail call i32 @transpose_misaligned(double* %0, double* %1, i32 %8, i32 %9, double %12)
br label %41
41: ; preds = %23, %39, %37, %16
ret void
}