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


x86 assembly (clang, -O0):
<mat3d_from_mat4d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11bb <mat3d_from_mat4d+0x9b>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11a8 <mat3d_from_mat4d+0x88>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <mat4_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 <mat3_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    1148 <mat3d_from_mat4d+0x28>
jmp    11ad <mat3d_from_mat4d+0x8d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <mat3d_from_mat4d+0x17>
add    $0x30,%rsp
pop    %rbp
ret

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

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

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