#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*/ free(int *);
double getMij(double *, int *, int *, int, int);
int *malloc(int);
int /*<<< orphan*/ setCumulative(int *, int *, int);
void setBlockMatrix(double *matOut, int i0, int i1, int j0, int j1,
                    double *matIn, int dim, int *profile) {
  int *sumProfile = malloc(sizeof(int) * dim);
  setCumulative(sumProfile, profile, dim);
  int i, j;
  int jdim = j1 - j0;
  for (i = i0; i < i1; i++) {
    for (j = j0; j < j1; j++) {
      matOut[(i - i0) * jdim + (j - j0)] =
          getMij(matIn, sumProfile, profile, i, j);
    }
  }
  free(sumProfile);
}


x86 assembly (clang, -O0):
<setBlockMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
movslq 0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x18(%rbp),%rsi
mov    0x10(%rbp),%edx
call   1050 <setCumulative@plt>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    120b <setBlockMatrix+0xcb>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11f8 <setBlockMatrix+0xb8>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x18(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
call   1040 <getMij@plt>
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    -0xc(%rbp),%ecx
imul   -0x34(%rbp),%ecx
mov    -0x30(%rbp),%edx
sub    -0x14(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a8 <setBlockMatrix+0x68>
jmp    11fd <setBlockMatrix+0xbd>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1196 <setBlockMatrix+0x56>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setBlockMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x20(%rsp)
mov    %r8d,%r14d
mov    %ecx,0x8(%rsp)
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,0x30(%rsp)
mov    0x78(%rsp),%rbx
mov    0x70(%rsp),%r12d
lea    0x0(,%r12,4),%edi
call   1060 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1050 <setCumulative@plt>
mov    %r15d,0x14(%rsp)
cmp    %r15d,%ebp
jge    1239 <setBlockMatrix+0xf9>
mov    %r14d,%eax
mov    %r14d,%ecx
sub    0x8(%rsp),%ecx
mov    %ecx,0x10(%rsp)
movl   $0x0,0xc(%rsp)
mov    %rbx,0x28(%rsp)
mov    0x20(%rsp),%r15
mov    0x18(%rsp),%r14
jmp    11e5 <setBlockMatrix+0xa5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
mov    0xc(%rsp),%ecx
add    0x10(%rsp),%ecx
mov    %ecx,0xc(%rsp)
cmp    0x14(%rsp),%ebp
je     1239 <setBlockMatrix+0xf9>
cmp    0x8(%rsp),%eax
jle    11d0 <setBlockMatrix+0x90>
mov    0x8(%rsp),%r12d
mov    0xc(%rsp),%ecx
mov    %ecx,%r13d
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %eax,%ebx
mov    %r12d,%r8d
call   1040 <getMij@plt>
mov    0x30(%rsp),%rdx
mov    %ebx,%eax
mov    0x28(%rsp),%rbx
movslq %r13d,%r13
movsd  %xmm0,(%rdx,%r13,8)
add    $0x1,%r13d
add    $0x1,%r12d
cmp    %r12d,%eax
jne    1200 <setBlockMatrix+0xc0>
jmp    11d0 <setBlockMatrix+0x90>
mov    0x18(%rsp),%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @setBlockMatrix(double* %0, i32 %1, i32 %2, i32 %3, i32 %4, double* %5, i32 %6, i32* %7) {
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store double* %0, double** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store double* %5, double** %14
store i32 %6, i32* %15
store i32* %7, i32** %16
%21 = load i32, i32* %15
%22 = sext i32 %21 to i64
%23 = mul i64 4, %22
%24 = trunc i64 %23 to i32
%25 = call i32* @malloc(i32 %24)
store i32* %25, i32** %17
%26 = load i32*, i32** %17
%27 = load i32*, i32** %16
%28 = load i32, i32* %15
%29 = call i32 @setCumulative(i32* %26, i32* %27, i32 %28)
%30 = load i32, i32* %13
%31 = load i32, i32* %12
%32 = sub nsw i32 %30, %31
store i32 %32, i32* %20
%33 = load i32, i32* %10
store i32 %33, i32* %18
br label %34
34: ; preds = %67, %8
%35 = load i32, i32* %18
%36 = load i32, i32* %11
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %70
38: ; preds = %34
%39 = load i32, i32* %12
store i32 %39, i32* %19
br label %40
40: ; preds = %63, %38
%41 = load i32, i32* %19
%42 = load i32, i32* %13
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %66
44: ; preds = %40
%45 = load double*, double** %14
%46 = load i32*, i32** %17
%47 = load i32*, i32** %16
%48 = load i32, i32* %18
%49 = load i32, i32* %19
%50 = call double @getMij(double* %45, i32* %46, i32* %47, i32 %48, i32 %49)
%51 = load double*, double** %9
%52 = load i32, i32* %18
%53 = load i32, i32* %10
%54 = sub nsw i32 %52, %53
%55 = load i32, i32* %20
%56 = mul nsw i32 %54, %55
%57 = load i32, i32* %19
%58 = load i32, i32* %12
%59 = sub nsw i32 %57, %58
%60 = add nsw i32 %56, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %51, i64 %61
store double %50, double* %62
br label %63
63: ; preds = %44
%64 = load i32, i32* %19
%65 = add nsw i32 %64, 1
store i32 %65, i32* %19
br label %40
66: ; preds = %40
br label %67
67: ; preds = %66
%68 = load i32, i32* %18
%69 = add nsw i32 %68, 1
store i32 %69, i32* %18
br label %34
70: ; preds = %34
%71 = load i32*, i32** %17
%72 = call i32 @free(i32* %71)
ret void
}

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