#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 */
typedef int /*<<< orphan*/ array;

/* Variables and functions */
int /*<<< orphan*/ better_fortran_(double *, double *, double *, int *, int *);
int /*<<< orphan*/ hello_fortran_(double *, int *);
int /*<<< orphan*/ mat_print(double *, int, int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  {
    printf("Hello fortran:\n");
    double array[] = {1, 2, 3, 4};
    int n = sizeof(array) / sizeof(double);
    hello_fortran_(array, &n);
  }
  {
    printf("Some Fortran Math\n");
    double matrix[2][3] = {{1, 3, 5}, {2, 4, 6}};
    double vector[3] = {7, 8, 9};
    double res[2];
    int rows = 3, cols = 2;
    printf(" Matrix\n");
    mat_print(&matrix[0][0], rows, cols);
    printf(" Vector\n");
    mat_print(&vector[0], 1, rows);
    better_fortran_(&matrix[0][0], &vector[0], &res[0], &rows, &cols);
    printf(" (matrix' * vector) + 2\n");
    mat_print(&res[0], 1, cols);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec7(%rip),%rdi
call   1050 <printf@plt>
mov    0xf0b(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xf08(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xf05(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xf02(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x4,-0x34(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x34(%rbp),%rsi
call   1040 <hello_fortran_@plt>
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1060 <memset@plt>
movsd  0xe56(%rip),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xe41(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xe2c(%rip),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xe17(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xe02(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xded(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0xe81(%rip),%rax
mov    %rax,-0x90(%rbp)
mov    0xe7b(%rip),%rax
mov    %rax,-0x88(%rbp)
mov    0xe75(%rip),%rax
mov    %rax,-0x80(%rbp)
movl   $0x3,-0xa4(%rbp)
movl   $0x2,-0xa8(%rbp)
lea    0xdf9(%rip),%rdi
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    -0xa4(%rbp),%esi
mov    -0xa8(%rbp),%edx
call   1030 <mat_print@plt>
lea    0xde1(%rip),%rdi
call   1050 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0xa4(%rbp),%edx
mov    $0x1,%esi
call   1030 <mat_print@plt>
lea    -0x70(%rbp),%rdi
lea    -0x90(%rbp),%rsi
lea    -0xa0(%rbp),%rdx
lea    -0xa4(%rbp),%rcx
lea    -0xa8(%rbp),%r8
call   1070 <better_fortran_@plt>
lea    0xda2(%rip),%rdi
call   1050 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%edx
mov    $0x1,%esi
call   1030 <mat_print@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
lea    0xf18(%rip),%rdi
call   1030 <puts@plt>
movaps 0xee4(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movl   $0x4,0x10(%rsp)
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <hello_fortran_@plt>
lea    0xeec(%rip),%rdi
call   1030 <puts@plt>
movaps 0xe69(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe6d(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe71(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
mov    0xea5(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xe89(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x3,0xc(%rsp)
movl   $0x2,0x8(%rsp)
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    $0x3,%esi
mov    $0x2,%edx
call   1040 <mat_print@plt>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1040 <mat_print@plt>
lea    0x60(%rsp),%r15
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <better_fortran_@plt>
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edx
mov    %r15,%rdi
mov    $0x1,%esi
call   1040 <mat_print@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Hello fortran:\0A\00"
@__const.main.array = [4 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00]
@.str.1 = [19 x i8] c"Some Fortran Math\0A\00"
@__const.main.vector = [3 x double] [double 7.000000e+00, double 8.000000e+00, double 9.000000e+00]
@.str.2 = [9 x i8] c" Matrix\0A\00"
@.str.3 = [9 x i8] c" Vector\0A\00"
@.str.4 = [25 x i8] c" (matrix' * vector) + 2\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [4 x double]
%6 = alloca i32
%7 = alloca [2 x [3 x double]]
%8 = alloca [3 x double]
%9 = alloca [2 x double]
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%12 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%13 = bitcast [4 x double]* %5 to i8*
store i32 4, i32* %6
%14 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%15 = call i32 @hello_fortran_(double* %14, i32* %6)
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%17 = bitcast [2 x [3 x double]]* %7 to i8*
%18 = bitcast i8* %17 to [2 x [3 x double]]*
%19 = getelementptr inbounds [2 x [3 x double]], [2 x [3 x double]]* %18, i32 0, i32 0
%20 = getelementptr inbounds [3 x double], [3 x double]* %19, i32 0, i32 0
store double 1.000000e+00, double* %20
%21 = getelementptr inbounds [3 x double], [3 x double]* %19, i32 0, i32 1
store double 3.000000e+00, double* %21
%22 = getelementptr inbounds [3 x double], [3 x double]* %19, i32 0, i32 2
store double 5.000000e+00, double* %22
%23 = getelementptr inbounds [2 x [3 x double]], [2 x [3 x double]]* %18, i32 0, i32 1
%24 = getelementptr inbounds [3 x double], [3 x double]* %23, i32 0, i32 0
store double 2.000000e+00, double* %24
%25 = getelementptr inbounds [3 x double], [3 x double]* %23, i32 0, i32 1
store double 4.000000e+00, double* %25
%26 = getelementptr inbounds [3 x double], [3 x double]* %23, i32 0, i32 2
store double 6.000000e+00, double* %26
%27 = bitcast [3 x double]* %8 to i8*
store i32 3, i32* %10
store i32 2, i32* %11
%28 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds [2 x [3 x double]], [2 x [3 x double]]* %7, i64 0, i64 0
%30 = getelementptr inbounds [3 x double], [3 x double]* %29, i64 0, i64 0
%31 = load i32, i32* %10
%32 = load i32, i32* %11
%33 = call i32 @mat_print(double* %30, i32 %31, i32 %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%35 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%36 = load i32, i32* %10
%37 = call i32 @mat_print(double* %35, i32 1, i32 %36)
%38 = getelementptr inbounds [2 x [3 x double]], [2 x [3 x double]]* %7, i64 0, i64 0
%39 = getelementptr inbounds [3 x double], [3 x double]* %38, i64 0, i64 0
%40 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%41 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%42 = call i32 @better_fortran_(double* %39, double* %40, double* %41, i32* %10, i32* %11)
%43 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%44 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%45 = load i32, i32* %11
%46 = call i32 @mat_print(double* %44, i32 1, i32 %45)
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = [4 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00]
@__const.main.vector = [3 x double] [double 7.000000e+00, double 8.000000e+00, double 9.000000e+00]
@str = [15 x i8] c"Hello fortran:\00"
@str.5 = [18 x i8] c"Some Fortran Math\00"
@str.6 = [8 x i8] c" Matrix\00"
@str.7 = [8 x i8] c" Vector\00"
@str.8 = [24 x i8] c" (matrix' * vector) + 2\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4 x double]
%4 = alloca i32
%5 = alloca [2 x [3 x double]]
%6 = alloca [3 x double]
%7 = alloca [2 x double]
%8 = alloca i32
%9 = alloca i32
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%11 = bitcast [4 x double]* %3 to i8*
%12 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%13 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 0
%14 = call i32 @hello_fortran_(double* %13, i32* %4)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%16 = bitcast [2 x [3 x double]]* %5 to i8*
%17 = getelementptr inbounds [2 x [3 x double]], [2 x [3 x double]]* %5, i64 0, i64 0, i64 0
%18 = bitcast [2 x [3 x double]]* %5 to <2 x double>*
store <2 x double> <double 1.000000e+00, double 3.000000e+00>, <2 x double>* %18
%19 = getelementptr inbounds [2 x [3 x double]], [2 x [3 x double]]* %5, i64 0, i64 0, i64 2
%20 = bitcast double* %19 to <2 x double>*
store <2 x double> <double 5.000000e+00, double 2.000000e+00>, <2 x double>* %20
%21 = getelementptr inbounds [2 x [3 x double]], [2 x [3 x double]]* %5, i64 0, i64 1, i64 1
%22 = bitcast double* %21 to <2 x double>*
store <2 x double> <double 4.000000e+00, double 6.000000e+00>, <2 x double>* %22
%23 = bitcast [3 x double]* %6 to i8*
%24 = bitcast [2 x double]* %7 to i8*
%25 = bitcast i32* %8 to i8*
store i32 3, i32* %8
%26 = bitcast i32* %9 to i8*
store i32 2, i32* %9
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0))
%28 = call i32 @mat_print(double* %17, i32 3, i32 2)
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.7, i64 0, i64 0))
%30 = getelementptr inbounds [3 x double], [3 x double]* %6, i64 0, i64 0
%31 = call i32 @mat_print(double* %30, i32 1, i32 3)
%32 = getelementptr inbounds [2 x double], [2 x double]* %7, i64 0, i64 0
%33 = call i32 @better_fortran_(double* %17, double* %30, double* %32, i32* %8, i32* %9)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.8, i64 0, i64 0))
%35 = load i32, i32* %9
%36 = call i32 @mat_print(double* %32, i32 1, i32 %35)
ret i32 0
}