void mat4_scale(const float m[4][4], float x, float y, float z,
                float out[4][4]) {
  int i;
  float tmp[4][4];
  mat4_copy(m, tmp);
  for (i = 0; i < 4; i++) {
    tmp[0][i] *= x;
    tmp[1][i] *= y;
    tmp[2][i] *= z;
  }
  mat4_copy(tmp, out);
}


x86 assembly (clang, -O0):
<mat4_scale>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x0,%al
call   1030 <mat4_copy@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    119c <mat4_scale+0x8c>
movss  -0xc(%rbp),%xmm0
movslq -0x24(%rbp),%rax
mulss  -0x70(%rbp,%rax,4),%xmm0
movss  %xmm0,-0x70(%rbp,%rax,4)
movss  -0x10(%rbp),%xmm0
movslq -0x24(%rbp),%rax
mulss  -0x60(%rbp,%rax,4),%xmm0
movss  %xmm0,-0x60(%rbp,%rax,4)
movss  -0x14(%rbp),%xmm0
movslq -0x24(%rbp),%rax
mulss  -0x50(%rbp,%rax,4),%xmm0
movss  %xmm0,-0x50(%rbp,%rax,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1145 <mat4_scale+0x35>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1030 <mat4_copy@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat4_scale>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%rbx
movaps %xmm2,0x20(%rsp)
movaps %xmm1,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0x30(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <mat4_copy@plt>
movaps (%rsp),%xmm0
shufps $0x0,%xmm0,%xmm0
mulps  0x30(%rsp),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0x10(%rsp),%xmm0
shufps $0x0,%xmm0,%xmm0
mulps  0x40(%rsp),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0x20(%rsp),%xmm0
shufps $0x0,%xmm0,%xmm0
mulps  0x50(%rsp),%xmm0
movaps %xmm0,0x50(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <mat4_copy@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @mat4_scale([4 x float]* %0, float %1, float %2, float %3, [4 x float]* %4) {
%6 = alloca [4 x [4 x float]]
%7 = bitcast [4 x [4 x float]]* %6 to i8*
%8 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %6, i64 0, i64 0
%9 = call i32 ([4 x float]*, [4 x float]*, ...) bitcast (i32 (...)* @mat4_copy to i32 ([4 x float]*, [4 x float]*, ...)*)([4 x float]* %0, [4 x float]* %8)
%10 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %6, i64 0, i64 1, i64 0
%11 = getelementptr inbounds [4 x [4 x float]], [4 x [4 x float]]* %6, i64 0, i64 2, i64 0
%12 = bitcast [4 x [4 x float]]* %6 to <4 x float>*
%13 = load <4 x float>, <4 x float>* %12
%14 = insertelement <4 x float> poison, float %1, i64 0
%15 = shufflevector <4 x float> %14, <4 x float> poison, <4 x i32> zeroinitializer
%16 = fmul <4 x float> %13, %15
%17 = bitcast [4 x [4 x float]]* %6 to <4 x float>*
store <4 x float> %16, <4 x float>* %17
%18 = bitcast float* %10 to <4 x float>*
%19 = load <4 x float>, <4 x float>* %18
%20 = insertelement <4 x float> poison, float %2, i64 0
%21 = shufflevector <4 x float> %20, <4 x float> poison, <4 x i32> zeroinitializer
%22 = fmul <4 x float> %19, %21
%23 = bitcast float* %10 to <4 x float>*
store <4 x float> %22, <4 x float>* %23
%24 = bitcast float* %11 to <4 x float>*
%25 = load <4 x float>, <4 x float>* %24
%26 = insertelement <4 x float> poison, float %3, i64 0
%27 = shufflevector <4 x float> %26, <4 x float> poison, <4 x i32> zeroinitializer
%28 = fmul <4 x float> %25, %27
%29 = bitcast float* %11 to <4 x float>*
store <4 x float> %28, <4 x float>* %29
%30 = call i32 ([4 x float]*, [4 x float]*, ...) bitcast (i32 (...)* @mat4_copy to i32 ([4 x float]*, [4 x float]*, ...)*)([4 x float]* %8, [4 x float]* %4)
ret void
}