#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 */
int /*<<< orphan*/ printf(char *, ...);
void test_proc_c_v2(int n, double arr[3][2]) {
  int i, j;
  printf("Hello from \"test_proc_c_v2(C)\", "
         "invoked from \"demo_fort_v2(Fort)\"!\n");
  printf("n = %d\n", n);
  for (j = 0; j < 3; j++) {
    for (i = 0; i < 2; i++) {
      printf("arr[%d,%d,%d] = %8.2f\n", j, i, arr[j][i]);
    }
  }
}


x86 assembly (clang, -O0):
<test_proc_c_v2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xf0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11ad <test_proc_c_v2+0x9d>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    119a <test_proc_c_v2+0x8a>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xec7(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <test_proc_c_v2+0x46>
jmp    119f <test_proc_c_v2+0x8f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1145 <test_proc_c_v2+0x35>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_proc_c_v2>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
lea    0xec4(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  (%rbx),%xmm0
lea    0xeb8(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x8(%rbx),%xmm0
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x10(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%esi
xor    %edx,%edx
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x18(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x20(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x2,%esi
xor    %edx,%edx
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0x28(%rbx),%xmm0
mov    %r14,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    $0x1,%al
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [68 x i8] c"Hello from \22test_proc_c_v2(C)\22, invoked from \22demo_fort_v2(Fort)\22!\0A\00"
@.str.1 = [8 x i8] c"n = %d\0A\00"
@.str.2 = [23 x i8] c"arr[%d,%d,%d] = %8.2f\0A\00"
define void @test_proc_c_v2(i32 %0, [2 x double]* %1) {
%3 = alloca i32
%4 = alloca [2 x double]*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store [2 x double]* %1, [2 x double]** %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %8)
store i32 0, i32* %6
br label %10
10: ; preds = %33, %2
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %36
13: ; preds = %10
store i32 0, i32* %5
br label %14
14: ; preds = %29, %13
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = load i32, i32* %6
%19 = load i32, i32* %5
%20 = load [2 x double]*, [2 x double]** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [2 x double], [2 x double]* %20, i64 %22
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [2 x double], [2 x double]* %23, i64 0, i64 %25
%27 = load double, double* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %19, double %27)
br label %29
29: ; preds = %17
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %14
32: ; preds = %14
br label %33
33: ; preds = %32
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %10
36: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"n = %d\0A\00"
@.str.2 = [23 x i8] c"arr[%d,%d,%d] = %8.2f\0A\00"
@str = [67 x i8] c"Hello from \22test_proc_c_v2(C)\22, invoked from \22demo_fort_v2(Fort)\22!\00"
define void @test_proc_c_v2(i32 %0, [2 x double]* nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%5 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 0, i64 0
%6 = load double, double* %5
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0, double %6)
%8 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 0, i64 1
%9 = load double, double* %8
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 1, double %9)
%11 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 1, i64 0
%12 = load double, double* %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 0, double %12)
%14 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 1, i64 1
%15 = load double, double* %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 1, double %15)
%17 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 2, i64 0
%18 = load double, double* %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 0, double %18)
%20 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 2, i64 1
%21 = load double, double* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 1, double %21)
ret void
}