#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 */
typedef int /*<<< orphan*/ __m128d;

/* Variables and functions */
int /*<<< orphan*/ _mm_load_sd(double *);
int /*<<< orphan*/ _mm_loadh_pd(int /*<<< orphan*/, double *);
int /*<<< orphan*/ _mm_store_sd(double *, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_storeu_pd(double *, int /*<<< orphan*/);
void kernel_dgecp_2_3_lib4(int tri, int kmax, double *A0, int sda, double *B) {
  if (tri == 1) {
    kmax += 1;
  }
  if (kmax <= 0)
    return;
  const int bs = 4;
  double *A1 = A0 + bs * sda;
  __m128d a_0;
  int k;
  for (k = 0; k < kmax - 3; k += 4) {
    a_0 = _mm_load_sd(&A0[3 + bs * 0]);
    a_0 = _mm_loadh_pd(a_0, &A1[0 + bs * 0]);
    _mm_storeu_pd(&B[0 + bs * 0], a_0);
    a_0 = _mm_load_sd(&A0[3 + bs * 1]);
    a_0 = _mm_loadh_pd(a_0, &A1[0 + bs * 1]);
    _mm_storeu_pd(&B[0 + bs * 1], a_0);
    a_0 = _mm_load_sd(&A0[3 + bs * 2]);
    a_0 = _mm_loadh_pd(a_0, &A1[0 + bs * 2]);
    _mm_storeu_pd(&B[0 + bs * 2], a_0);
    a_0 = _mm_load_sd(&A0[3 + bs * 3]);
    a_0 = _mm_loadh_pd(a_0, &A1[0 + bs * 3]);
    _mm_storeu_pd(&B[0 + bs * 3], a_0);
    A0 += 16;
    A1 += 16;
    B += 16;
  }
  for (; k < kmax; k++) {
    a_0 = _mm_load_sd(&A0[3 + bs * 0]);
    a_0 = _mm_loadh_pd(a_0, &A1[0 + bs * 0]);
    _mm_storeu_pd(&B[0 + bs * 0], a_0);
    A0 += 4;
    A1 += 4;
    B += 4;
  }
  if (tri == 1) {
    a_0 = _mm_load_sd(&A1[0 + bs * 0]);
    _mm_store_sd(&B[1 + bs * 0], a_0);
  }
}


x86 assembly (clang, -O0):
<kernel_dgecp_2_3_lib4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    116c <kernel_dgecp_2_3_lib4+0x2c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     117b <kernel_dgecp_2_3_lib4+0x3b>
jmp    1342 <kernel_dgecp_2_3_lib4+0x202>
movl   $0x4,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jge    12ae <kernel_dgecp_2_3_lib4+0x16e>
mov    -0x10(%rbp),%rdi
add    $0x18,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1040 <_mm_loadh_pd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1050 <_mm_storeu_pd@plt>
mov    -0x10(%rbp),%rdi
add    $0x38,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
add    $0x20,%rsi
call   1040 <_mm_loadh_pd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x20,%rdi
mov    -0x34(%rbp),%esi
call   1050 <_mm_storeu_pd@plt>
mov    -0x10(%rbp),%rdi
add    $0x58,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
add    $0x40,%rsi
call   1040 <_mm_loadh_pd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x40,%rdi
mov    -0x34(%rbp),%esi
call   1050 <_mm_storeu_pd@plt>
mov    -0x10(%rbp),%rdi
add    $0x78,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
add    $0x60,%rsi
call   1040 <_mm_loadh_pd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x60,%rdi
mov    -0x34(%rbp),%esi
call   1050 <_mm_storeu_pd@plt>
mov    -0x10(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x38(%rbp)
jmp    11a1 <kernel_dgecp_2_3_lib4+0x61>
jmp    12b3 <kernel_dgecp_2_3_lib4+0x173>
mov    -0x38(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    131c <kernel_dgecp_2_3_lib4+0x1dc>
mov    -0x10(%rbp),%rdi
add    $0x18,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1040 <_mm_loadh_pd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1050 <_mm_storeu_pd@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    12b3 <kernel_dgecp_2_3_lib4+0x173>
cmpl   $0x1,-0x4(%rbp)
jne    1342 <kernel_dgecp_2_3_lib4+0x202>
mov    -0x30(%rbp),%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x8,%rdi
mov    -0x34(%rbp),%esi
call   1060 <_mm_store_sd@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_dgecp_2_3_lib4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebp,%ebp
cmp    $0x1,%edi
sete   %bpl
add    %esi,%ebp
test   %ebp,%ebp
jle    12d7 <kernel_dgecp_2_3_lib4+0x197>
mov    %r8,%rbx
mov    %rdx,%r12
mov    %edi,%r15d
shl    $0x2,%ecx
movslq %ecx,%rax
lea    (%rdx,%rax,8),%r14
xor    %eax,%eax
cmp    $0x4,%ebp
jb     1276 <kernel_dgecp_2_3_lib4+0x136>
mov    %r15d,0x4(%rsp)
mov    %rbp,0x10(%rsp)
lea    -0x3(%rbp),%eax
mov    %eax,0x8(%rsp)
xor    %r15d,%r15d
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,0xc(%rsp)
lea    (%r14,%r15,1),%rbp
lea    (%rbx,%r15,1),%r13
lea    (%r12,%r15,1),%rdi
add    $0x18,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1040 <_mm_loadh_pd@plt>
mov    %r13,%rdi
mov    %eax,%esi
call   1050 <_mm_storeu_pd@plt>
lea    (%r12,%r15,1),%rdi
add    $0x38,%rdi
call   1030 <_mm_load_sd@plt>
lea    (%r14,%r15,1),%rsi
add    $0x20,%rsi
mov    %eax,%edi
call   1040 <_mm_loadh_pd@plt>
lea    (%rbx,%r15,1),%rdi
add    $0x20,%rdi
mov    %eax,%esi
call   1050 <_mm_storeu_pd@plt>
lea    (%r12,%r15,1),%rdi
add    $0x58,%rdi
call   1030 <_mm_load_sd@plt>
lea    (%r14,%r15,1),%rsi
add    $0x40,%rsi
mov    %eax,%edi
call   1040 <_mm_loadh_pd@plt>
lea    (%rbx,%r15,1),%rdi
add    $0x40,%rdi
mov    %eax,%esi
call   1050 <_mm_storeu_pd@plt>
lea    (%r12,%r15,1),%rdi
add    $0x78,%rdi
call   1030 <_mm_load_sd@plt>
lea    (%r14,%r15,1),%rsi
add    $0x60,%rsi
mov    %eax,%edi
call   1040 <_mm_loadh_pd@plt>
lea    (%rbx,%r15,1),%rdi
add    $0x60,%rdi
mov    %eax,%esi
call   1050 <_mm_storeu_pd@plt>
mov    0xc(%rsp),%eax
add    $0x4,%eax
sub    $0xffffffffffffff80,%r15
cmp    0x8(%rsp),%eax
jl     11a0 <kernel_dgecp_2_3_lib4+0x60>
add    %r15,%r14
add    %r15,%rbx
add    %r15,%r12
mov    0x4(%rsp),%r15d
mov    0x10(%rsp),%rbp
cmp    %ebp,%eax
jge    12ad <kernel_dgecp_2_3_lib4+0x16d>
sub    %eax,%ebp
add    $0x18,%r12
mov    %r12,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <_mm_loadh_pd@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <_mm_storeu_pd@plt>
add    $0x20,%r14
add    $0x20,%rbx
add    $0x20,%r12
add    $0xffffffff,%ebp
jne    1280 <kernel_dgecp_2_3_lib4+0x140>
cmp    $0x1,%r15d
jne    12d7 <kernel_dgecp_2_3_lib4+0x197>
mov    %r14,%rdi
call   1030 <_mm_load_sd@plt>
add    $0x8,%rbx
mov    %rbx,%rdi
mov    %eax,%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <_mm_store_sd@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @kernel_dgecp_2_3_lib4(i32 %0, i32 %1, double* %2, i32 %3, double* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store double* %2, double** %8
store i32 %3, i32* %9
store double* %4, double** %10
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %5
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
br label %20
20: ; preds = %17, %5
%21 = load i32, i32* %7
%22 = icmp sle i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
br label %126
24: ; preds = %20
store i32 4, i32* %11
%25 = load double*, double** %8
%26 = load i32, i32* %9
%27 = mul nsw i32 4, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %25, i64 %28
store double* %29, double** %12
store i32 0, i32* %14
br label %30
30: ; preds = %86, %24
%31 = load i32, i32* %14
%32 = load i32, i32* %7
%33 = sub nsw i32 %32, 3
%34 = icmp slt i32 %31, %33
br i1 %34, label %35, label %89
35: ; preds = %30
%36 = load double*, double** %8
%37 = getelementptr inbounds double, double* %36, i64 3
%38 = call i32 @_mm_load_sd(double* %37)
store i32 %38, i32* %13
%39 = load i32, i32* %13
%40 = load double*, double** %12
%41 = getelementptr inbounds double, double* %40, i64 0
%42 = call i32 @_mm_loadh_pd(i32 %39, double* %41)
store i32 %42, i32* %13
%43 = load double*, double** %10
%44 = getelementptr inbounds double, double* %43, i64 0
%45 = load i32, i32* %13
%46 = call i32 @_mm_storeu_pd(double* %44, i32 %45)
%47 = load double*, double** %8
%48 = getelementptr inbounds double, double* %47, i64 7
%49 = call i32 @_mm_load_sd(double* %48)
store i32 %49, i32* %13
%50 = load i32, i32* %13
%51 = load double*, double** %12
%52 = getelementptr inbounds double, double* %51, i64 4
%53 = call i32 @_mm_loadh_pd(i32 %50, double* %52)
store i32 %53, i32* %13
%54 = load double*, double** %10
%55 = getelementptr inbounds double, double* %54, i64 4
%56 = load i32, i32* %13
%57 = call i32 @_mm_storeu_pd(double* %55, i32 %56)
%58 = load double*, double** %8
%59 = getelementptr inbounds double, double* %58, i64 11
%60 = call i32 @_mm_load_sd(double* %59)
store i32 %60, i32* %13
%61 = load i32, i32* %13
%62 = load double*, double** %12
%63 = getelementptr inbounds double, double* %62, i64 8
%64 = call i32 @_mm_loadh_pd(i32 %61, double* %63)
store i32 %64, i32* %13
%65 = load double*, double** %10
%66 = getelementptr inbounds double, double* %65, i64 8
%67 = load i32, i32* %13
%68 = call i32 @_mm_storeu_pd(double* %66, i32 %67)
%69 = load double*, double** %8
%70 = getelementptr inbounds double, double* %69, i64 15
%71 = call i32 @_mm_load_sd(double* %70)
store i32 %71, i32* %13
%72 = load i32, i32* %13
%73 = load double*, double** %12
%74 = getelementptr inbounds double, double* %73, i64 12
%75 = call i32 @_mm_loadh_pd(i32 %72, double* %74)
store i32 %75, i32* %13
%76 = load double*, double** %10
%77 = getelementptr inbounds double, double* %76, i64 12
%78 = load i32, i32* %13
%79 = call i32 @_mm_storeu_pd(double* %77, i32 %78)
%80 = load double*, double** %8
%81 = getelementptr inbounds double, double* %80, i64 16
store double* %81, double** %8
%82 = load double*, double** %12
%83 = getelementptr inbounds double, double* %82, i64 16
store double* %83, double** %12
%84 = load double*, double** %10
%85 = getelementptr inbounds double, double* %84, i64 16
store double* %85, double** %10
br label %86
86: ; preds = %35
%87 = load i32, i32* %14
%88 = add nsw i32 %87, 4
store i32 %88, i32* %14
br label %30
89: ; preds = %30
br label %90
90: ; preds = %112, %89
%91 = load i32, i32* %14
%92 = load i32, i32* %7
%93 = icmp slt i32 %91, %92
br i1 %93, label %94, label %115
94: ; preds = %90
%95 = load double*, double** %8
%96 = getelementptr inbounds double, double* %95, i64 3
%97 = call i32 @_mm_load_sd(double* %96)
store i32 %97, i32* %13
%98 = load i32, i32* %13
%99 = load double*, double** %12
%100 = getelementptr inbounds double, double* %99, i64 0
%101 = call i32 @_mm_loadh_pd(i32 %98, double* %100)
store i32 %101, i32* %13
%102 = load double*, double** %10
%103 = getelementptr inbounds double, double* %102, i64 0
%104 = load i32, i32* %13
%105 = call i32 @_mm_storeu_pd(double* %103, i32 %104)
%106 = load double*, double** %8
%107 = getelementptr inbounds double, double* %106, i64 4
store double* %107, double** %8
%108 = load double*, double** %12
%109 = getelementptr inbounds double, double* %108, i64 4
store double* %109, double** %12
%110 = load double*, double** %10
%111 = getelementptr inbounds double, double* %110, i64 4
store double* %111, double** %10
br label %112
112: ; preds = %94
%113 = load i32, i32* %14
%114 = add nsw i32 %113, 1
store i32 %114, i32* %14
br label %90
115: ; preds = %90
%116 = load i32, i32* %6
%117 = icmp eq i32 %116, 1
br i1 %117, label %118, label %126
118: ; preds = %115
%119 = load double*, double** %12
%120 = getelementptr inbounds double, double* %119, i64 0
%121 = call i32 @_mm_load_sd(double* %120)
store i32 %121, i32* %13
%122 = load double*, double** %10
%123 = getelementptr inbounds double, double* %122, i64 1
%124 = load i32, i32* %13
%125 = call i32 @_mm_store_sd(double* %123, i32 %124)
br label %126
126: ; preds = %23, %118, %115
ret void
}

LLVM IR (-O2):
define void @kernel_dgecp_2_3_lib4(i32 %0, i32 %1, double* %2, i32 %3, double* %4) {
%6 = icmp eq i32 %0, 1
%7 = zext i1 %6 to i32
%8 = add i32 %7, %1
%9 = icmp slt i32 %8, 1
br i1 %9, label %75, label %10
10: ; preds = %5
%11 = shl nsw i32 %3, 2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds double, double* %2, i64 %12
%14 = add nsw i32 %8, -3
%15 = icmp ugt i32 %8, 3
br i1 %15, label %22, label %16
16: ; preds = %22, %10
%17 = phi double* [ %2, %10 ], [ %49, %22 ]
%18 = phi double* [ %4, %10 ], [ %51, %22 ]
%19 = phi double* [ %13, %10 ], [ %50, %22 ]
%20 = phi i32 [ 0, %10 ], [ %52, %22 ]
%21 = icmp slt i32 %20, %8
br i1 %21, label %54, label %68
22: ; preds = %10, %22
%23 = phi i32 [ %52, %22 ], [ 0, %10 ]
%24 = phi double* [ %50, %22 ], [ %13, %10 ]
%25 = phi double* [ %51, %22 ], [ %4, %10 ]
%26 = phi double* [ %49, %22 ], [ %2, %10 ]
%27 = getelementptr inbounds double, double* %26, i64 3
%28 = tail call i32 @_mm_load_sd(double* %27)
%29 = tail call i32 @_mm_loadh_pd(i32 %28, double* %24)
%30 = tail call i32 @_mm_storeu_pd(double* %25, i32 %29)
%31 = getelementptr inbounds double, double* %26, i64 7
%32 = tail call i32 @_mm_load_sd(double* %31)
%33 = getelementptr inbounds double, double* %24, i64 4
%34 = tail call i32 @_mm_loadh_pd(i32 %32, double* %33)
%35 = getelementptr inbounds double, double* %25, i64 4
%36 = tail call i32 @_mm_storeu_pd(double* %35, i32 %34)
%37 = getelementptr inbounds double, double* %26, i64 11
%38 = tail call i32 @_mm_load_sd(double* %37)
%39 = getelementptr inbounds double, double* %24, i64 8
%40 = tail call i32 @_mm_loadh_pd(i32 %38, double* %39)
%41 = getelementptr inbounds double, double* %25, i64 8
%42 = tail call i32 @_mm_storeu_pd(double* %41, i32 %40)
%43 = getelementptr inbounds double, double* %26, i64 15
%44 = tail call i32 @_mm_load_sd(double* %43)
%45 = getelementptr inbounds double, double* %24, i64 12
%46 = tail call i32 @_mm_loadh_pd(i32 %44, double* %45)
%47 = getelementptr inbounds double, double* %25, i64 12
%48 = tail call i32 @_mm_storeu_pd(double* %47, i32 %46)
%49 = getelementptr inbounds double, double* %26, i64 16
%50 = getelementptr inbounds double, double* %24, i64 16
%51 = getelementptr inbounds double, double* %25, i64 16
%52 = add nuw nsw i32 %23, 4
%53 = icmp slt i32 %52, %14
br i1 %53, label %22, label %16
54: ; preds = %16, %54
%55 = phi i32 [ %66, %54 ], [ %20, %16 ]
%56 = phi double* [ %64, %54 ], [ %19, %16 ]
%57 = phi double* [ %65, %54 ], [ %18, %16 ]
%58 = phi double* [ %63, %54 ], [ %17, %16 ]
%59 = getelementptr inbounds double, double* %58, i64 3
%60 = tail call i32 @_mm_load_sd(double* %59)
%61 = tail call i32 @_mm_loadh_pd(i32 %60, double* %56)
%62 = tail call i32 @_mm_storeu_pd(double* %57, i32 %61)
%63 = getelementptr inbounds double, double* %58, i64 4
%64 = getelementptr inbounds double, double* %56, i64 4
%65 = getelementptr inbounds double, double* %57, i64 4
%66 = add i32 %55, 1
%67 = icmp eq i32 %66, %8
br i1 %67, label %68, label %54
68: ; preds = %54, %16
%69 = phi double* [ %18, %16 ], [ %65, %54 ]
%70 = phi double* [ %19, %16 ], [ %64, %54 ]
br i1 %6, label %71, label %75
71: ; preds = %68
%72 = tail call i32 @_mm_load_sd(double* %70)
%73 = getelementptr inbounds double, double* %69, i64 1
%74 = tail call i32 @_mm_store_sd(double* %73, i32 %72)
br label %75
75: ; preds = %68, %71, %5
ret void
}