void init_matrix(double *a, double *b, double *c, int n) {
  int i, j, k;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      for (k = 0; k < n; k++) {
        *(a + i * n + j) = 1.0;
        *(b + i * n + j) = 2.0;
        *(c + i * n + j) = 0.0;
      }
    }
  }
}


x86 assembly (clang, -O0):
<init_matrix>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ed <init_matrix+0xed>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11da <init_matrix+0xda>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c7 <init_matrix+0xc7>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
movsd  0xe9b(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
movsd  0xe6d(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x24(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1140 <init_matrix+0x40>
jmp    11cc <init_matrix+0xcc>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112d <init_matrix+0x2d>
jmp    11df <init_matrix+0xdf>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    111a <init_matrix+0x1a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %ecx,%ecx
jle    11bc <init_matrix+0xbc>
mov    %ecx,%r10d
mov    %ecx,%r8d
and    $0xfffffffe,%r8d
xor    %r9d,%r9d
movabs $0x3ff0000000000000,%r11
movabs $0x4000000000000000,%r14
jmp    1149 <init_matrix+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r9
cmp    %r10,%r9
je     11bc <init_matrix+0xbc>
mov    %r9,%rax
imul   %r10,%rax
lea    (%rdi,%rax,8),%r15
lea    (%rsi,%rax,8),%r12
lea    (%rdx,%rax,8),%rbx
xor    %eax,%eax
jmp    1169 <init_matrix+0x69>
add    $0x1,%rax
cmp    %r10,%rax
je     1140 <init_matrix+0x40>
cmp    $0x1,%ecx
je     11a5 <init_matrix+0xa5>
mov    %r8d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r11,(%r15,%rax,8)
mov    %r14,(%r12,%rax,8)
movq   $0x0,(%rbx,%rax,8)
mov    %r11,(%r15,%rax,8)
mov    %r14,(%r12,%rax,8)
movq   $0x0,(%rbx,%rax,8)
add    $0xfffffffe,%ebp
jne    1180 <init_matrix+0x80>
test   $0x1,%cl
je     1160 <init_matrix+0x60>
mov    %r11,(%r15,%rax,8)
mov    %r14,(%r12,%rax,8)
movq   $0x0,(%rbx,%rax,8)
jmp    1160 <init_matrix+0x60>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @init_matrix(double* nocapture writeonly %0, double* nocapture writeonly %1, double* nocapture writeonly %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %36
6: ; preds = %4
%7 = zext i32 %3 to i64
%8 = zext i32 %3 to i64
%9 = and i32 %3, 1
%10 = icmp eq i32 %3, 1
%11 = and i32 %3, -2
%12 = icmp eq i32 %9, 0
br label %13
13: ; preds = %33, %6
%14 = phi i64 [ 0, %6 ], [ %34, %33 ]
%15 = mul nsw i64 %14, %7
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = getelementptr inbounds double, double* %1, i64 %15
%18 = getelementptr inbounds double, double* %2, i64 %15
br label %19
19: ; preds = %30, %13
%20 = phi i64 [ 0, %13 ], [ %31, %30 ]
%21 = getelementptr inbounds double, double* %16, i64 %20
%22 = getelementptr inbounds double, double* %17, i64 %20
%23 = getelementptr inbounds double, double* %18, i64 %20
br i1 %10, label %28, label %24
24: ; preds = %19, %24
%25 = phi i32 [ %26, %24 ], [ 0, %19 ]
store double 1.000000e+00, double* %21
store double 2.000000e+00, double* %22
store double 0.000000e+00, double* %23
store double 1.000000e+00, double* %21
store double 2.000000e+00, double* %22
store double 0.000000e+00, double* %23
%26 = add i32 %25, 2
%27 = icmp eq i32 %26, %11
br i1 %27, label %28, label %24
28: ; preds = %24, %19
br i1 %12, label %30, label %29
29: ; preds = %28
store double 1.000000e+00, double* %21
store double 2.000000e+00, double* %22
store double 0.000000e+00, double* %23
br label %30
30: ; preds = %28, %29
%31 = add nuw nsw i64 %20, 1
%32 = icmp eq i64 %31, %8
br i1 %32, label %33, label %19
33: ; preds = %30
%34 = add nuw nsw i64 %14, 1
%35 = icmp eq i64 %34, %8
br i1 %35, label %36, label %13
36: ; preds = %33, %4
ret void
}