#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*/ CalcFlow(float **, short ***, long, long);
scalar_t__ Get2DMem(long, long, int, int);
double floor(float);
float **ExtractFlow(float **unwrappedphase, short ***flowsptr, long nrow,
                    long ncol) {
  long row, col;
  float **wrappedphase;
  wrappedphase = (float **)Get2DMem(nrow, ncol, sizeof(float *), sizeof(float));
  for (row = 0; row < nrow; row++) {
    for (col = 0; col < ncol; col++) {
      wrappedphase[row][col] =
          unwrappedphase[row][col] -
          6.28318530717958647692 *
              floor(unwrappedphase[row][col] / 6.28318530717958647692);
    }
  }
  CalcFlow(unwrappedphase, flowsptr, nrow, ncol);
  return (wrappedphase);
}


x86 assembly (clang, -O0):
<ExtractFlow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x8,%edx
mov    $0x4,%ecx
call   1030 <Get2DMem@plt>
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1230 <ExtractFlow+0x100>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    121a <ExtractFlow+0xea>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe3a(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <floor@plt>
movsd  -0x40(%rbp),%xmm1
movsd  0xe18(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x30(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1181 <ExtractFlow+0x51>
jmp    121f <ExtractFlow+0xef>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    116b <ExtractFlow+0x3b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <CalcFlow@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExtractFlow>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,0x8(%rsp)
mov    %rdi,%r13
mov    %rdx,%rdi
mov    %rcx,%rsi
mov    $0x8,%edx
mov    $0x4,%ecx
call   1030 <Get2DMem@plt>
mov    %rax,%rbx
test   %r14,%r14
jle    11f5 <ExtractFlow+0xc5>
xor    %ebp,%ebp
movsd  0xe89(%rip),%xmm1
jmp    1189 <ExtractFlow+0x59>
nopl   0x0(%rax)
add    $0x1,%rbp
cmp    %r14,%rbp
je     11f5 <ExtractFlow+0xc5>
test   %r12,%r12
jle    1180 <ExtractFlow+0x50>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbp,8),%rax
movss  (%rax,%r15,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <floor@plt>
movsd  0xe3e(%rip),%xmm2
movsd  0xe2e(%rip),%xmm1
mulsd  %xmm2,%xmm0
addsd  0x10(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    (%rbx,%rbp,8),%rax
movss  %xmm0,(%rax,%r15,4)
add    $0x1,%r15
cmp    %r15,%r12
jne    11a0 <ExtractFlow+0x70>
jmp    1180 <ExtractFlow+0x50>
mov    %r13,%rdi
mov    0x8(%rsp),%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1040 <CalcFlow@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define float** @ExtractFlow(float** %0, i16*** %1, i64 %2, i64 %3) {
%5 = alloca float**
%6 = alloca i16***
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca float**
store float** %0, float*** %5
store i16*** %1, i16**** %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%12 = load i64, i64* %7
%13 = load i64, i64* %8
%14 = call i64 @Get2DMem(i64 %12, i64 %13, i32 8, i32 4)
%15 = inttoptr i64 %14 to float**
store float** %15, float*** %11
store i64 0, i64* %9
br label %16
16: ; preds = %57, %4
%17 = load i64, i64* %9
%18 = load i64, i64* %7
%19 = icmp slt i64 %17, %18
br i1 %19, label %20, label %60
20: ; preds = %16
store i64 0, i64* %10
br label %21
21: ; preds = %53, %20
%22 = load i64, i64* %10
%23 = load i64, i64* %8
%24 = icmp slt i64 %22, %23
br i1 %24, label %25, label %56
25: ; preds = %21
%26 = load float**, float*** %5
%27 = load i64, i64* %9
%28 = getelementptr inbounds float*, float** %26, i64 %27
%29 = load float*, float** %28
%30 = load i64, i64* %10
%31 = getelementptr inbounds float, float* %29, i64 %30
%32 = load float, float* %31
%33 = fpext float %32 to double
%34 = load float**, float*** %5
%35 = load i64, i64* %9
%36 = getelementptr inbounds float*, float** %34, i64 %35
%37 = load float*, float** %36
%38 = load i64, i64* %10
%39 = getelementptr inbounds float, float* %37, i64 %38
%40 = load float, float* %39
%41 = fpext float %40 to double
%42 = fdiv double %41, 0x401921FB54442D18
%43 = fptrunc double %42 to float
%44 = call double @floor(float %43)
%45 = call double @llvm.fmuladd.f64(double 0xC01921FB54442D18, double %44, double %33)
%46 = fptrunc double %45 to float
%47 = load float**, float*** %11
%48 = load i64, i64* %9
%49 = getelementptr inbounds float*, float** %47, i64 %48
%50 = load float*, float** %49
%51 = load i64, i64* %10
%52 = getelementptr inbounds float, float* %50, i64 %51
store float %46, float* %52
br label %53
53: ; preds = %25
%54 = load i64, i64* %10
%55 = add nsw i64 %54, 1
store i64 %55, i64* %10
br label %21
56: ; preds = %21
br label %57
57: ; preds = %56
%58 = load i64, i64* %9
%59 = add nsw i64 %58, 1
store i64 %59, i64* %9
br label %16
60: ; preds = %16
%61 = load float**, float*** %5
%62 = load i16***, i16**** %6
%63 = load i64, i64* %7
%64 = load i64, i64* %8
%65 = call i32 @CalcFlow(float** %61, i16*** %62, i64 %63, i64 %64)
%66 = load float**, float*** %11
ret float** %66
}

LLVM IR (-O2):
define float** @ExtractFlow(float** %0, i16*** %1, i64 %2, i64 %3) {
%5 = tail call i64 @Get2DMem(i64 %2, i64 %3, i32 8, i32 4)
%6 = inttoptr i64 %5 to float**
%7 = icmp sgt i64 %2, 0
br i1 %7, label %8, label %33
8: ; preds = %4
%9 = icmp sgt i64 %3, 0
br label %10
10: ; preds = %8, %30
%11 = phi i64 [ 0, %8 ], [ %31, %30 ]
br i1 %9, label %12, label %30
12: ; preds = %10
%13 = getelementptr inbounds float*, float** %0, i64 %11
%14 = getelementptr inbounds float*, float** %6, i64 %11
br label %15
15: ; preds = %12, %15
%16 = phi i64 [ 0, %12 ], [ %28, %15 ]
%17 = load float*, float** %13
%18 = getelementptr inbounds float, float* %17, i64 %16
%19 = load float, float* %18
%20 = fpext float %19 to double
%21 = fdiv double %20, 0x401921FB54442D18
%22 = fptrunc double %21 to float
%23 = tail call double @floor(float %22)
%24 = tail call double @llvm.fmuladd.f64(double %23, double 0xC01921FB54442D18, double %20)
%25 = fptrunc double %24 to float
%26 = load float*, float** %14
%27 = getelementptr inbounds float, float* %26, i64 %16
store float %25, float* %27
%28 = add nuw nsw i64 %16, 1
%29 = icmp eq i64 %28, %3
br i1 %29, label %30, label %15
30: ; preds = %15, %10
%31 = add nuw nsw i64 %11, 1
%32 = icmp eq i64 %31, %2
br i1 %32, label %33, label %10
33: ; preds = %30, %4
%34 = tail call i32 @CalcFlow(float** %0, i16*** %1, i64 %2, i64 %3)
ret float** %6
}