#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_loadu_pd(double *);
int /*<<< orphan*/ _mm_store_sd(double *, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_storeu_pd(double *, int /*<<< orphan*/);
void kernel_dgecp_2_0_lib4(int tri, int kmax, double *A, double *B) {
  if (tri == 1) {
    kmax += 1;
  }
  if (kmax <= 0)
    return;
  const int bs = 4;
  __m128d a_0;
  int k;
  for (k = 0; k < kmax - 3; k += 4) {
    a_0 = _mm_loadu_pd(&A[0 + bs * 0]);
    _mm_storeu_pd(&B[0 + bs * 0], a_0);
    a_0 = _mm_loadu_pd(&A[0 + bs * 1]);
    _mm_storeu_pd(&B[0 + bs * 1], a_0);
    a_0 = _mm_loadu_pd(&A[0 + bs * 2]);
    _mm_storeu_pd(&B[0 + bs * 2], a_0);
    a_0 = _mm_loadu_pd(&A[0 + bs * 3]);
    _mm_storeu_pd(&B[0 + bs * 3], a_0);
    A += 16;
    B += 16;
  }
  for (; k < kmax; k++) {
    a_0 = _mm_loadu_pd(&A[0 + bs * 0]);
    _mm_storeu_pd(&B[0 + bs * 0], a_0);
    A += 4;
    B += 4;
  }
  if (tri == 1) {
    a_0 = _mm_load_sd(&A[1 + bs * 0]);
    _mm_store_sd(&B[1 + bs * 0], a_0);
  }
}


x86 assembly (clang, -O0):
<kernel_dgecp_2_0_lib4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    1169 <kernel_dgecp_2_0_lib4+0x29>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1178 <kernel_dgecp_2_0_lib4+0x38>
jmp    12b2 <kernel_dgecp_2_0_lib4+0x172>
movl   $0x4,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jge    1239 <kernel_dgecp_2_0_lib4+0xf9>
mov    -0x10(%rbp),%rdi
call   1050 <_mm_loadu_pd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <_mm_storeu_pd@plt>
mov    -0x10(%rbp),%rdi
add    $0x20,%rdi
call   1050 <_mm_loadu_pd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x20,%rdi
mov    -0x20(%rbp),%esi
call   1040 <_mm_storeu_pd@plt>
mov    -0x10(%rbp),%rdi
add    $0x40,%rdi
call   1050 <_mm_loadu_pd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x40,%rdi
mov    -0x20(%rbp),%esi
call   1040 <_mm_storeu_pd@plt>
mov    -0x10(%rbp),%rdi
add    $0x60,%rdi
call   1050 <_mm_loadu_pd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x60,%rdi
mov    -0x20(%rbp),%esi
call   1040 <_mm_storeu_pd@plt>
mov    -0x10(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
jmp    1186 <kernel_dgecp_2_0_lib4+0x46>
jmp    123e <kernel_dgecp_2_0_lib4+0xfe>
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1288 <kernel_dgecp_2_0_lib4+0x148>
mov    -0x10(%rbp),%rdi
call   1050 <_mm_loadu_pd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <_mm_storeu_pd@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    123e <kernel_dgecp_2_0_lib4+0xfe>
cmpl   $0x1,-0x4(%rbp)
jne    12b2 <kernel_dgecp_2_0_lib4+0x172>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x8,%rdi
mov    -0x20(%rbp),%esi
call   1060 <_mm_store_sd@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_dgecp_2_0_lib4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r12d,%r12d
cmp    $0x1,%edi
sete   %r12b
add    %esi,%r12d
test   %r12d,%r12d
jle    123e <kernel_dgecp_2_0_lib4+0xfe>
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %edi,%r15d
xor    %ebp,%ebp
cmp    $0x4,%r12d
jb     11de <kernel_dgecp_2_0_lib4+0x9e>
lea    -0x3(%r12),%r13d
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <_mm_loadu_pd@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <_mm_storeu_pd@plt>
lea    0x20(%rbx),%rdi
call   1050 <_mm_loadu_pd@plt>
lea    0x20(%r14),%rdi
mov    %eax,%esi
call   1040 <_mm_storeu_pd@plt>
lea    0x40(%rbx),%rdi
call   1050 <_mm_loadu_pd@plt>
lea    0x40(%r14),%rdi
mov    %eax,%esi
call   1040 <_mm_storeu_pd@plt>
lea    0x60(%rbx),%rdi
call   1050 <_mm_loadu_pd@plt>
lea    0x60(%r14),%rdi
mov    %eax,%esi
call   1040 <_mm_storeu_pd@plt>
sub    $0xffffffffffffff80,%rbx
sub    $0xffffffffffffff80,%r14
add    $0x4,%ebp
cmp    %r13d,%ebp
jl     1180 <kernel_dgecp_2_0_lib4+0x40>
cmp    %r12d,%ebp
jge    1210 <kernel_dgecp_2_0_lib4+0xd0>
sub    %ebp,%r12d
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <_mm_loadu_pd@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <_mm_storeu_pd@plt>
add    $0x20,%rbx
add    $0x20,%r14
add    $0xffffffff,%r12d
jne    11f0 <kernel_dgecp_2_0_lib4+0xb0>
cmp    $0x1,%r15d
jne    123e <kernel_dgecp_2_0_lib4+0xfe>
add    $0x8,%rbx
mov    %rbx,%rdi
call   1030 <_mm_load_sd@plt>
add    $0x8,%r14
mov    %r14,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <_mm_store_sd@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @kernel_dgecp_2_0_lib4(i32 %0, i32 %1, double* %2, double* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store double* %2, double** %7
store double* %3, double** %8
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %17
14: ; preds = %4
%15 = load i32, i32* %6
%16 = add nsw i32 %15, 1
store i32 %16, i32* %6
br label %17
17: ; preds = %14, %4
%18 = load i32, i32* %6
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
br label %94
21: ; preds = %17
store i32 4, i32* %9
store i32 0, i32* %11
br label %22
22: ; preds = %60, %21
%23 = load i32, i32* %11
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 3
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %63
27: ; preds = %22
%28 = load double*, double** %7
%29 = getelementptr inbounds double, double* %28, i64 0
%30 = call i32 @_mm_loadu_pd(double* %29)
store i32 %30, i32* %10
%31 = load double*, double** %8
%32 = getelementptr inbounds double, double* %31, i64 0
%33 = load i32, i32* %10
%34 = call i32 @_mm_storeu_pd(double* %32, i32 %33)
%35 = load double*, double** %7
%36 = getelementptr inbounds double, double* %35, i64 4
%37 = call i32 @_mm_loadu_pd(double* %36)
store i32 %37, i32* %10
%38 = load double*, double** %8
%39 = getelementptr inbounds double, double* %38, i64 4
%40 = load i32, i32* %10
%41 = call i32 @_mm_storeu_pd(double* %39, i32 %40)
%42 = load double*, double** %7
%43 = getelementptr inbounds double, double* %42, i64 8
%44 = call i32 @_mm_loadu_pd(double* %43)
store i32 %44, i32* %10
%45 = load double*, double** %8
%46 = getelementptr inbounds double, double* %45, i64 8
%47 = load i32, i32* %10
%48 = call i32 @_mm_storeu_pd(double* %46, i32 %47)
%49 = load double*, double** %7
%50 = getelementptr inbounds double, double* %49, i64 12
%51 = call i32 @_mm_loadu_pd(double* %50)
store i32 %51, i32* %10
%52 = load double*, double** %8
%53 = getelementptr inbounds double, double* %52, i64 12
%54 = load i32, i32* %10
%55 = call i32 @_mm_storeu_pd(double* %53, i32 %54)
%56 = load double*, double** %7
%57 = getelementptr inbounds double, double* %56, i64 16
store double* %57, double** %7
%58 = load double*, double** %8
%59 = getelementptr inbounds double, double* %58, i64 16
store double* %59, double** %8
br label %60
60: ; preds = %27
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 4
store i32 %62, i32* %11
br label %22
63: ; preds = %22
br label %64
64: ; preds = %80, %63
%65 = load i32, i32* %11
%66 = load i32, i32* %6
%67 = icmp slt i32 %65, %66
br i1 %67, label %68, label %83
68: ; preds = %64
%69 = load double*, double** %7
%70 = getelementptr inbounds double, double* %69, i64 0
%71 = call i32 @_mm_loadu_pd(double* %70)
store i32 %71, i32* %10
%72 = load double*, double** %8
%73 = getelementptr inbounds double, double* %72, i64 0
%74 = load i32, i32* %10
%75 = call i32 @_mm_storeu_pd(double* %73, i32 %74)
%76 = load double*, double** %7
%77 = getelementptr inbounds double, double* %76, i64 4
store double* %77, double** %7
%78 = load double*, double** %8
%79 = getelementptr inbounds double, double* %78, i64 4
store double* %79, double** %8
br label %80
80: ; preds = %68
%81 = load i32, i32* %11
%82 = add nsw i32 %81, 1
store i32 %82, i32* %11
br label %64
83: ; preds = %64
%84 = load i32, i32* %5
%85 = icmp eq i32 %84, 1
br i1 %85, label %86, label %94
86: ; preds = %83
%87 = load double*, double** %7
%88 = getelementptr inbounds double, double* %87, i64 1
%89 = call i32 @_mm_load_sd(double* %88)
store i32 %89, i32* %10
%90 = load double*, double** %8
%91 = getelementptr inbounds double, double* %90, i64 1
%92 = load i32, i32* %10
%93 = call i32 @_mm_store_sd(double* %91, i32 %92)
br label %94
94: ; preds = %20, %86, %83
ret void
}

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