#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 mat3_getIndex(int, int);
size_t mat4_getIndex(int, int);
int /*<<< orphan*/ mat4d_identity(double *);
void mat4d_from_mat3d(double dest[16], const double src[9]) {
  mat4d_identity(dest);
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      dest[mat4_getIndex(i, j)] = src[mat3_getIndex(i, j)];
}


x86 assembly (clang, -O0):
<mat4d_from_mat3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <mat4d_identity@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11d4 <mat4d_from_mat3d+0xa4>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11c1 <mat4d_from_mat3d+0x91>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <mat3_getIndex@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <mat4_getIndex@plt>
movsd  -0x28(%rbp),%xmm0
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1161 <mat4d_from_mat3d+0x31>
jmp    11c6 <mat4d_from_mat3d+0x96>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1150 <mat4d_from_mat3d+0x20>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat4d_from_mat3d>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <mat4d_identity@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <mat3_getIndex@plt>
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
xor    %edi,%edi
xor    %esi,%esi
call   1040 <mat4_getIndex@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <mat3_getIndex@plt>
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <mat4_getIndex@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
xor    %edi,%edi
mov    $0x2,%esi
call   1050 <mat3_getIndex@plt>
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
xor    %edi,%edi
mov    $0x2,%esi
call   1040 <mat4_getIndex@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <mat3_getIndex@plt>
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
mov    $0x1,%edi
xor    %esi,%esi
call   1040 <mat4_getIndex@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
mov    $0x1,%edi
mov    $0x1,%esi
call   1050 <mat3_getIndex@plt>
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
mov    $0x1,%edi
mov    $0x1,%esi
call   1040 <mat4_getIndex@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
mov    $0x1,%edi
mov    $0x2,%esi
call   1050 <mat3_getIndex@plt>
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
mov    $0x1,%edi
mov    $0x2,%esi
call   1040 <mat4_getIndex@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
mov    $0x2,%edi
xor    %esi,%esi
call   1050 <mat3_getIndex@plt>
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
mov    $0x2,%edi
xor    %esi,%esi
call   1040 <mat4_getIndex@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
mov    $0x2,%edi
mov    $0x1,%esi
call   1050 <mat3_getIndex@plt>
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
mov    $0x2,%edi
mov    $0x1,%esi
call   1040 <mat4_getIndex@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
mov    $0x2,%edi
mov    $0x2,%esi
call   1050 <mat3_getIndex@plt>
movsd  (%r14,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
mov    $0x2,%edi
mov    $0x2,%esi
call   1040 <mat4_getIndex@plt>
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @mat4d_from_mat3d(double* %0, double* nocapture %1) {
%3 = tail call i32 @mat4d_identity(double* %0)
%4 = tail call i64 @mat3_getIndex(i32 0, i32 0)
%5 = getelementptr inbounds double, double* %1, i64 %4
%6 = load double, double* %5
%7 = tail call i64 @mat4_getIndex(i32 0, i32 0)
%8 = getelementptr inbounds double, double* %0, i64 %7
store double %6, double* %8
%9 = tail call i64 @mat3_getIndex(i32 0, i32 1)
%10 = getelementptr inbounds double, double* %1, i64 %9
%11 = load double, double* %10
%12 = tail call i64 @mat4_getIndex(i32 0, i32 1)
%13 = getelementptr inbounds double, double* %0, i64 %12
store double %11, double* %13
%14 = tail call i64 @mat3_getIndex(i32 0, i32 2)
%15 = getelementptr inbounds double, double* %1, i64 %14
%16 = load double, double* %15
%17 = tail call i64 @mat4_getIndex(i32 0, i32 2)
%18 = getelementptr inbounds double, double* %0, i64 %17
store double %16, double* %18
%19 = tail call i64 @mat3_getIndex(i32 1, i32 0)
%20 = getelementptr inbounds double, double* %1, i64 %19
%21 = load double, double* %20
%22 = tail call i64 @mat4_getIndex(i32 1, i32 0)
%23 = getelementptr inbounds double, double* %0, i64 %22
store double %21, double* %23
%24 = tail call i64 @mat3_getIndex(i32 1, i32 1)
%25 = getelementptr inbounds double, double* %1, i64 %24
%26 = load double, double* %25
%27 = tail call i64 @mat4_getIndex(i32 1, i32 1)
%28 = getelementptr inbounds double, double* %0, i64 %27
store double %26, double* %28
%29 = tail call i64 @mat3_getIndex(i32 1, i32 2)
%30 = getelementptr inbounds double, double* %1, i64 %29
%31 = load double, double* %30
%32 = tail call i64 @mat4_getIndex(i32 1, i32 2)
%33 = getelementptr inbounds double, double* %0, i64 %32
store double %31, double* %33
%34 = tail call i64 @mat3_getIndex(i32 2, i32 0)
%35 = getelementptr inbounds double, double* %1, i64 %34
%36 = load double, double* %35
%37 = tail call i64 @mat4_getIndex(i32 2, i32 0)
%38 = getelementptr inbounds double, double* %0, i64 %37
store double %36, double* %38
%39 = tail call i64 @mat3_getIndex(i32 2, i32 1)
%40 = getelementptr inbounds double, double* %1, i64 %39
%41 = load double, double* %40
%42 = tail call i64 @mat4_getIndex(i32 2, i32 1)
%43 = getelementptr inbounds double, double* %0, i64 %42
store double %41, double* %43
%44 = tail call i64 @mat3_getIndex(i32 2, i32 2)
%45 = getelementptr inbounds double, double* %1, i64 %44
%46 = load double, double* %45
%47 = tail call i64 @mat4_getIndex(i32 2, i32 2)
%48 = getelementptr inbounds double, double* %0, i64 %47
store double %46, double* %48
ret void
}