void colcpy_trans_upper_and_zero(double *dst, int ldD, const double *src,
                                 int ldS, int nR, int nC, int unit) {
  register double *Dcu, *Dcl, *Drl, *Dru;
  register const double *Sc, *Sr;
  register int j, i;
  Dcu = dst;
  Sc = src;
  Dcl = dst;
  for (j = 0; j < nC; j++) {
    Dru = Dcu;
    Drl = Dcl;
    Sr = Sc;
    for (i = 0; i < j; i++) {
      *Dru = 0.0;
      *Drl = *Sr;
      Sr++;
      Dru++;
      Drl += ldD;
    }
    *Dru = unit ? 1.0 : *Sr;
    Sc += ldS;
    Dcu += ldD;
    Dcl++;
  }
}


x86 assembly (clang, -O0):
<colcpy_trans_upper_and_zero>:
push   %rbp
mov    %rsp,%rbp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1243 <colcpy_trans_upper_and_zero+0x143>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jge    11c9 <colcpy_trans_upper_and_zero+0xc9>
mov    -0x48(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x58(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x40(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x58(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x48(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1167 <colcpy_trans_upper_and_zero+0x67>
cmpl   $0x0,0x10(%rbp)
je     11e5 <colcpy_trans_upper_and_zero+0xe5>
movsd  0xe25(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    11f2 <colcpy_trans_upper_and_zero+0xf2>
mov    -0x58(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
mov    -0x48(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x50(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    113c <colcpy_trans_upper_and_zero+0x3c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<colcpy_trans_upper_and_zero>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %r9d,%r9d
jle    1244 <colcpy_trans_upper_and_zero+0x144>
mov    0x30(%rsp),%r10d
movslq %esi,%r8
movslq %ecx,%r11
shl    $0x3,%r11
lea    0x0(,%r8,8),%r12
shl    $0x5,%r8
xor    %r15d,%r15d
movsd  0xec9(%rip),%xmm0
mov    %rdi,%r14
jmp    115b <colcpy_trans_upper_and_zero+0x5b>
nopl   0x0(%rax)
movsd  %xmm1,(%rbx)
add    %r11,%rdx
add    %r12,%rdi
add    $0x8,%r14
add    $0x1,%r15d
cmp    %r9d,%r15d
je     1244 <colcpy_trans_upper_and_zero+0x144>
mov    %rdi,%rbx
mov    %rdx,%rax
test   %r15d,%r15d
je     122f <colcpy_trans_upper_and_zero+0x12f>
lea    -0x1(%r15),%ecx
mov    %rdx,%rax
mov    %rdi,%rbx
mov    %r14,%rsi
cmp    $0x3,%ecx
jb     1202 <colcpy_trans_upper_and_zero+0x102>
mov    %r15d,%eax
and    $0xfffffffc,%eax
mov    %r14,%rcx
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %rcx,%rsi
movq   $0x0,(%rdi,%rbx,1)
movsd  (%rdx,%rbx,1),%xmm1
movsd  %xmm1,(%rcx)
movq   $0x0,0x8(%rdi,%rbx,1)
movsd  0x8(%rdx,%rbx,1),%xmm1
add    %r12,%rcx
movsd  %xmm1,(%rsi,%r12,1)
movq   $0x0,0x10(%rdi,%rbx,1)
movsd  0x10(%rdx,%rbx,1),%xmm1
movsd  %xmm1,(%r12,%rcx,1)
add    %r12,%rcx
movq   $0x0,0x18(%rdi,%rbx,1)
movsd  0x18(%rdx,%rbx,1),%xmm1
movsd  %xmm1,(%r12,%rcx,1)
add    %r12,%rcx
add    $0x20,%rbx
add    %r12,%rcx
add    $0xfffffffc,%eax
jne    1190 <colcpy_trans_upper_and_zero+0x90>
add    %r8,%rsi
lea    (%rdx,%rbx,1),%rax
add    %rdi,%rbx
test   $0x3,%r15b
je     122f <colcpy_trans_upper_and_zero+0x12f>
mov    %r15d,%ebp
and    $0x3,%ebp
xchg   %ax,%ax
movq   $0x0,(%rbx)
movsd  (%rax),%xmm1
movsd  %xmm1,(%rsi)
add    $0x8,%rax
add    $0x8,%rbx
add    %r12,%rsi
add    $0xffffffff,%ebp
jne    1210 <colcpy_trans_upper_and_zero+0x110>
movaps %xmm0,%xmm1
test   %r10d,%r10d
jne    1140 <colcpy_trans_upper_and_zero+0x40>
movsd  (%rax),%xmm1
jmp    1140 <colcpy_trans_upper_and_zero+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @colcpy_trans_upper_and_zero(double* nocapture writeonly %0, i32 %1, double* nocapture %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = icmp sgt i32 %5, 0
br i1 %8, label %9, label %78
9: ; preds = %7
%10 = sext i32 %1 to i64
%11 = icmp eq i32 %6, 0
%12 = sext i32 %3 to i64
br label %13
13: ; preds = %9, %71
%14 = phi i32 [ 0, %9 ], [ %76, %71 ]
%15 = phi double* [ %2, %9 ], [ %73, %71 ]
%16 = phi double* [ %0, %9 ], [ %75, %71 ]
%17 = phi double* [ %0, %9 ], [ %74, %71 ]
%18 = icmp eq i32 %14, 0
br i1 %18, label %66, label %19
19: ; preds = %13
%20 = add nsw i32 %14, -1
%21 = and i32 %14, 3
%22 = icmp ult i32 %20, 3
br i1 %22, label %48, label %23
23: ; preds = %19
%24 = and i32 %14, 2147483644
br label %25
25: ; preds = %25, %23
%26 = phi double* [ %15, %23 ], [ %43, %25 ]
%27 = phi double* [ %17, %23 ], [ %44, %25 ]
%28 = phi double* [ %16, %23 ], [ %45, %25 ]
%29 = phi i32 [ 0, %23 ], [ %46, %25 ]
store double 0.000000e+00, double* %27
%30 = load double, double* %26
store double %30, double* %28
%31 = getelementptr inbounds double, double* %26, i64 1
%32 = getelementptr inbounds double, double* %27, i64 1
%33 = getelementptr inbounds double, double* %28, i64 %10
store double 0.000000e+00, double* %32
%34 = load double, double* %31
store double %34, double* %33
%35 = getelementptr inbounds double, double* %26, i64 2
%36 = getelementptr inbounds double, double* %27, i64 2
%37 = getelementptr inbounds double, double* %33, i64 %10
store double 0.000000e+00, double* %36
%38 = load double, double* %35
store double %38, double* %37
%39 = getelementptr inbounds double, double* %26, i64 3
%40 = getelementptr inbounds double, double* %27, i64 3
%41 = getelementptr inbounds double, double* %37, i64 %10
store double 0.000000e+00, double* %40
%42 = load double, double* %39
store double %42, double* %41
%43 = getelementptr inbounds double, double* %26, i64 4
%44 = getelementptr inbounds double, double* %27, i64 4
%45 = getelementptr inbounds double, double* %41, i64 %10
%46 = add i32 %29, 4
%47 = icmp eq i32 %46, %24
br i1 %47, label %48, label %25
48: ; preds = %25, %19
%49 = phi double* [ undef, %19 ], [ %43, %25 ]
%50 = phi double* [ undef, %19 ], [ %44, %25 ]
%51 = phi double* [ %15, %19 ], [ %43, %25 ]
%52 = phi double* [ %17, %19 ], [ %44, %25 ]
%53 = phi double* [ %16, %19 ], [ %45, %25 ]
%54 = icmp eq i32 %21, 0
br i1 %54, label %66, label %55
55: ; preds = %48, %55
%56 = phi double* [ %61, %55 ], [ %51, %48 ]
%57 = phi double* [ %62, %55 ], [ %52, %48 ]
%58 = phi double* [ %63, %55 ], [ %53, %48 ]
%59 = phi i32 [ %64, %55 ], [ 0, %48 ]
store double 0.000000e+00, double* %57
%60 = load double, double* %56
store double %60, double* %58
%61 = getelementptr inbounds double, double* %56, i64 1
%62 = getelementptr inbounds double, double* %57, i64 1
%63 = getelementptr inbounds double, double* %58, i64 %10
%64 = add i32 %59, 1
%65 = icmp eq i32 %64, %21
br i1 %65, label %66, label %55
66: ; preds = %48, %55, %13
%67 = phi double* [ %17, %13 ], [ %50, %48 ], [ %62, %55 ]
%68 = phi double* [ %15, %13 ], [ %49, %48 ], [ %61, %55 ]
br i1 %11, label %69, label %71
69: ; preds = %66
%70 = load double, double* %68
br label %71
71: ; preds = %66, %69
%72 = phi double [ %70, %69 ], [ 1.000000e+00, %66 ]
store double %72, double* %67
%73 = getelementptr inbounds double, double* %15, i64 %12
%74 = getelementptr inbounds double, double* %17, i64 %10
%75 = getelementptr inbounds double, double* %16, i64 1
%76 = add nuw nsw i32 %14, 1
%77 = icmp eq i32 %76, %5
br i1 %77, label %78, label %13
78: ; preds = %71, %7
ret void
}