#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 scalar_t__ *m;
typedef size_t j;

/* Variables and functions */
double *malloc(int);
double stub1(int, int);
void init_matrix_f(double **A, int m, int n, double (*f)(int, int)) {
  *A = malloc(m * n * sizeof(double));
  int i, j;
  for (j = 0; j < n; j++) {
    for (i = 0; i < m; i++) {
      (*A)[((j) * (m) + (i))] = (*f)(i, j);
    }
  }
}


x86 assembly (clang, -O0):
<init_matrix_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b0 <init_matrix_f+0xa0>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119d <init_matrix_f+0x8d>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   *%rax
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115e <init_matrix_f+0x4e>
jmp    11a2 <init_matrix_f+0x92>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114b <init_matrix_f+0x3b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_matrix_f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %edx,%ebx
mov    %rdi,%r12
mov    %esi,0x4(%rsp)
mov    %esi,%edi
imul   %edx,%edi
shl    $0x3,%edi
call   1030 <malloc@plt>
mov    %rax,(%r12)
test   %ebx,%ebx
jle    119e <init_matrix_f+0x8e>
movslq 0x4(%rsp),%rax
mov    %ebx,%ecx
mov    %rcx,0x8(%rsp)
mov    %eax,%r14d
shl    $0x3,%rax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
xor    %ebx,%ebx
jmp    1170 <init_matrix_f+0x60>
xchg   %ax,%ax
add    $0x1,%rbx
add    0x10(%rsp),%r13
cmp    0x8(%rsp),%rbx
je     119e <init_matrix_f+0x8e>
cmpl   $0x0,0x4(%rsp)
jle    1160 <init_matrix_f+0x50>
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %ebx,%esi
call   *%r15
mov    (%r12),%rax
add    %r13,%rax
movsd  %xmm0,(%rax,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1180 <init_matrix_f+0x70>
jmp    1160 <init_matrix_f+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @init_matrix_f(double** nocapture %0, i32 %1, i32 %2, double (i32, i32)* nocapture %3) {
%5 = shl i32 %1, 3
%6 = mul i32 %5, %2
%7 = tail call double* @malloc(i32 %6)
store double* %7, double** %0
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %31
9: ; preds = %4
%10 = icmp sgt i32 %1, 0
%11 = sext i32 %1 to i64
%12 = zext i32 %2 to i64
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %9, %28
%15 = phi i64 [ 0, %9 ], [ %29, %28 ]
br i1 %10, label %16, label %28
16: ; preds = %14
%17 = mul nsw i64 %15, %11
%18 = trunc i64 %15 to i32
br label %19
19: ; preds = %16, %19
%20 = phi i64 [ 0, %16 ], [ %26, %19 ]
%21 = trunc i64 %20 to i32
%22 = tail call double %3(i32 %21, i32 %18)
%23 = load double*, double** %0
%24 = add nsw i64 %20, %17
%25 = getelementptr inbounds double, double* %23, i64 %24
store double %22, double* %25
%26 = add nuw nsw i64 %20, 1
%27 = icmp eq i64 %26, %13
br i1 %27, label %28, label %19
28: ; preds = %19, %14
%29 = add nuw nsw i64 %15, 1
%30 = icmp eq i64 %29, %12
br i1 %30, label %31, label %14
31: ; preds = %28, %4
ret void
}