#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_store_sd(double *, int /*<<< orphan*/);
void kernel_dgecp_1_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_load_sd(&A[0 + bs * 0]);
    _mm_store_sd(&B[0 + bs * 0], a_0);
    a_0 = _mm_load_sd(&A[0 + bs * 1]);
    _mm_store_sd(&B[0 + bs * 1], a_0);
    a_0 = _mm_load_sd(&A[0 + bs * 2]);
    _mm_store_sd(&B[0 + bs * 2], a_0);
    a_0 = _mm_load_sd(&A[0 + bs * 3]);
    _mm_store_sd(&B[0 + bs * 3], a_0);
    A += 16;
    B += 16;
  }
  for (; k < kmax; k++) {
    a_0 = _mm_load_sd(&A[0 + bs * 0]);
    _mm_store_sd(&B[0 + bs * 0], a_0);
    A += 4;
    B += 4;
  }
}


x86 assembly (clang, -O0):
<kernel_dgecp_1_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    1149 <kernel_dgecp_1_0_lib4+0x29>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     1158 <kernel_dgecp_1_0_lib4+0x38>
jmp    1268 <kernel_dgecp_1_0_lib4+0x148>
movl   $0x4,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jge    1219 <kernel_dgecp_1_0_lib4+0xf9>
mov    -0x10(%rbp),%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <_mm_store_sd@plt>
mov    -0x10(%rbp),%rdi
add    $0x20,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x20,%rdi
mov    -0x20(%rbp),%esi
call   1040 <_mm_store_sd@plt>
mov    -0x10(%rbp),%rdi
add    $0x40,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x40,%rdi
mov    -0x20(%rbp),%esi
call   1040 <_mm_store_sd@plt>
mov    -0x10(%rbp),%rdi
add    $0x60,%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x60,%rdi
mov    -0x20(%rbp),%esi
call   1040 <_mm_store_sd@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    1166 <kernel_dgecp_1_0_lib4+0x46>
jmp    121e <kernel_dgecp_1_0_lib4+0xfe>
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1268 <kernel_dgecp_1_0_lib4+0x148>
mov    -0x10(%rbp),%rdi
call   1030 <_mm_load_sd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <_mm_store_sd@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    121e <kernel_dgecp_1_0_lib4+0xfe>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_dgecp_1_0_lib4>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
cmp    $0x1,%edi
sete   %r15b
add    %esi,%r15d
test   %r15d,%r15d
jle    11f0 <kernel_dgecp_1_0_lib4+0xd0>
mov    %rcx,%r14
mov    %rdx,%rbx
xor    %ebp,%ebp
cmp    $0x4,%r15d
jb     11be <kernel_dgecp_1_0_lib4+0x9e>
lea    -0x3(%r15),%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <_mm_load_sd@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <_mm_store_sd@plt>
lea    0x20(%rbx),%rdi
call   1030 <_mm_load_sd@plt>
lea    0x20(%r14),%rdi
mov    %eax,%esi
call   1040 <_mm_store_sd@plt>
lea    0x40(%rbx),%rdi
call   1030 <_mm_load_sd@plt>
lea    0x40(%r14),%rdi
mov    %eax,%esi
call   1040 <_mm_store_sd@plt>
lea    0x60(%rbx),%rdi
call   1030 <_mm_load_sd@plt>
lea    0x60(%r14),%rdi
mov    %eax,%esi
call   1040 <_mm_store_sd@plt>
sub    $0xffffffffffffff80,%rbx
sub    $0xffffffffffffff80,%r14
add    $0x4,%ebp
cmp    %r12d,%ebp
jl     1160 <kernel_dgecp_1_0_lib4+0x40>
cmp    %r15d,%ebp
jge    11f0 <kernel_dgecp_1_0_lib4+0xd0>
sub    %ebp,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <_mm_load_sd@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <_mm_store_sd@plt>
add    $0x20,%rbx
add    $0x20,%r14
add    $0xffffffff,%r15d
jne    11d0 <kernel_dgecp_1_0_lib4+0xb0>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @kernel_dgecp_1_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 %83
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_load_sd(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_store_sd(double* %32, i32 %33)
%35 = load double*, double** %7
%36 = getelementptr inbounds double, double* %35, i64 4
%37 = call i32 @_mm_load_sd(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_store_sd(double* %39, i32 %40)
%42 = load double*, double** %7
%43 = getelementptr inbounds double, double* %42, i64 8
%44 = call i32 @_mm_load_sd(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_store_sd(double* %46, i32 %47)
%49 = load double*, double** %7
%50 = getelementptr inbounds double, double* %49, i64 12
%51 = call i32 @_mm_load_sd(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_store_sd(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_load_sd(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_store_sd(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 = %20, %64
ret void
}

LLVM IR (-O2):
define void @kernel_dgecp_1_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 %49, 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_load_sd(double* %20)
%22 = tail call i32 @_mm_store_sd(double* %19, i32 %21)
%23 = getelementptr inbounds double, double* %20, i64 4
%24 = tail call i32 @_mm_load_sd(double* %23)
%25 = getelementptr inbounds double, double* %19, i64 4
%26 = tail call i32 @_mm_store_sd(double* %25, i32 %24)
%27 = getelementptr inbounds double, double* %20, i64 8
%28 = tail call i32 @_mm_load_sd(double* %27)
%29 = getelementptr inbounds double, double* %19, i64 8
%30 = tail call i32 @_mm_store_sd(double* %29, i32 %28)
%31 = getelementptr inbounds double, double* %20, i64 12
%32 = tail call i32 @_mm_load_sd(double* %31)
%33 = getelementptr inbounds double, double* %19, i64 12
%34 = tail call i32 @_mm_store_sd(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_load_sd(double* %42)
%44 = tail call i32 @_mm_store_sd(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, %4
ret void
}