#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 */

/* Variables and functions */
size_t ORDER(int, int, int const, int const);
void multiply_by_diagonal(const int rows, const int cols,
                          double *restrict diagonal, double *restrict matrix) {
  int i, j;
  for (i = 0; i < rows; i++)
    for (j = 0; j < cols; j++)
      matrix[ORDER(i, j, rows, cols)] *= diagonal[j];
}


x86 assembly (clang, -O0):
<multiply_by_diagonal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ae <multiply_by_diagonal+0x9e>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119b <multiply_by_diagonal+0x8b>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
call   1030 <ORDER@plt>
movsd  -0x30(%rbp),%xmm0
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1140 <multiply_by_diagonal+0x30>
jmp    11a0 <multiply_by_diagonal+0x90>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <multiply_by_diagonal+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply_by_diagonal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,0xc(%rsp)
test   %edi,%edi
jle    1197 <multiply_by_diagonal+0x87>
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %edi,%r12d
mov    0xc(%rsp),%ebp
xor    %r13d,%r13d
jmp    1149 <multiply_by_diagonal+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
cmp    %r12d,%r13d
je     1197 <multiply_by_diagonal+0x87>
cmpl   $0x0,0xc(%rsp)
jle    1140 <multiply_by_diagonal+0x30>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%r14,%r15,8),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r13d,%edi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %ebp,%ecx
call   1030 <ORDER@plt>
movsd  0x10(%rsp),%xmm0
mulsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x1,%r15
cmp    %r15,%rbp
jne    1160 <multiply_by_diagonal+0x50>
jmp    1140 <multiply_by_diagonal+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @multiply_by_diagonal(i32 %0, i32 %1, double* noalias %2, double* noalias %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store double* %2, double** %7
store double* %3, double** %8
store i32 0, i32* %9
br label %11
11: ; preds = %39, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %42
15: ; preds = %11
store i32 0, i32* %10
br label %16
16: ; preds = %35, %15
%17 = load i32, i32* %10
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = load double*, double** %7
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
%25 = load double, double* %24
%26 = load double*, double** %8
%27 = load i32, i32* %9
%28 = load i32, i32* %10
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = call i64 @ORDER(i32 %27, i32 %28, i32 %29, i32 %30)
%32 = getelementptr inbounds double, double* %26, i64 %31
%33 = load double, double* %32
%34 = fmul double %33, %25
store double %34, double* %32
br label %35
35: ; preds = %20
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %16
38: ; preds = %16
br label %39
39: ; preds = %38
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %11
42: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @multiply_by_diagonal(i32 %0, i32 %1, double* noalias nocapture %2, double* noalias nocapture %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %25
6: ; preds = %4
%7 = icmp sgt i32 %1, 0
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %6, %22
%10 = phi i32 [ 0, %6 ], [ %23, %22 ]
br i1 %7, label %11, label %22
11: ; preds = %9, %11
%12 = phi i64 [ %20, %11 ], [ 0, %9 ]
%13 = getelementptr inbounds double, double* %2, i64 %12
%14 = load double, double* %13
%15 = trunc i64 %12 to i32
%16 = tail call i64 @ORDER(i32 %10, i32 %15, i32 %0, i32 %1)
%17 = getelementptr inbounds double, double* %3, i64 %16
%18 = load double, double* %17
%19 = fmul double %14, %18
store double %19, double* %17
%20 = add nuw nsw i64 %12, 1
%21 = icmp eq i64 %20, %8
br i1 %21, label %22, label %11
22: ; preds = %11, %9
%23 = add nuw nsw i32 %10, 1
%24 = icmp eq i32 %23, %0
br i1 %24, label %25, label %9
25: ; preds = %22, %4
ret void
}