#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 */
size_t ORDER(int, int, int, int);
void ap_affine_transformation(double *restrict B, double *restrict b,
                              double *restrict ref_x, double *restrict ref_y,
                              int length, double *restrict physical_x,
                              double *restrict physical_y) {
  int i;
  for (i = 0; i < length; i++) {
    physical_x[i] = B[ORDER(0, 0, 2, 2)] * ref_x[i] +
                    B[ORDER(0, 1, 2, 2)] * ref_y[i] + b[0];
    physical_y[i] = B[ORDER(1, 0, 2, 2)] * ref_x[i] +
                    B[ORDER(1, 1, 2, 2)] * ref_y[i] + b[1];
  }
}


x86 assembly (clang, -O0):
<ap_affine_transformation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1288 <ap_affine_transformation+0x178>
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
xor    %esi,%esi
mov    $0x2,%ecx
mov    %esi,%edi
mov    %ecx,%edx
call   1030 <ORDER@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x70(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x2,%ecx
mov    %ecx,%edx
call   1030 <ORDER@plt>
movsd  -0x70(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
addsd  (%rax),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x2,%ecx
mov    %ecx,%edx
call   1030 <ORDER@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x1,%esi
mov    $0x2,%ecx
mov    %esi,%edi
mov    %ecx,%edx
call   1030 <ORDER@plt>
movsd  -0x50(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
addsd  0x8(%rax),%xmm0
mov    0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    113e <ap_affine_transformation+0x2e>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ap_affine_transformation>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x10(%rsp)
test   %r8d,%r8d
jle    121f <ap_affine_transformation+0x10f>
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbx
mov    %r8d,%ebp
xor    %r14d,%r14d
xchg   %ax,%ax
xor    %edi,%edi
xor    %esi,%esi
mov    $0x2,%edx
mov    $0x2,%ecx
call   1030 <ORDER@plt>
movsd  (%r12,%r14,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x2,%ecx
call   1030 <ORDER@plt>
movsd  (%r15,%r14,8),%xmm1
movsd  %xmm1,0x20(%rsp)
movsd  (%rbx,%rax,8),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x18(%rsp),%xmm0
addsd  0x0(%r13),%xmm0
mov    0x10(%rsp),%rax
movsd  %xmm0,(%rax,%r14,8)
mov    $0x1,%edi
xor    %esi,%esi
mov    $0x2,%edx
mov    $0x2,%ecx
call   1030 <ORDER@plt>
movsd  0x8(%rsp),%xmm0
mulsd  (%rbx,%rax,8),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%edi
mov    $0x1,%esi
mov    $0x2,%edx
mov    $0x2,%ecx
call   1030 <ORDER@plt>
movsd  0x20(%rsp),%xmm0
mulsd  (%rbx,%rax,8),%xmm0
addsd  0x8(%rsp),%xmm0
addsd  0x8(%r13),%xmm0
mov    0x60(%rsp),%rax
movsd  %xmm0,(%rax,%r14,8)
add    $0x1,%r14
cmp    %r14,%rbp
jne    1140 <ap_affine_transformation+0x30>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @ap_affine_transformation(double* noalias nocapture %0, double* noalias nocapture %1, double* noalias nocapture %2, double* noalias nocapture %3, i32 %4, double* noalias nocapture writeonly %5, double* noalias nocapture writeonly %6) {
%8 = icmp sgt i32 %4, 0
br i1 %8, label %9, label %42
9: ; preds = %7
%10 = getelementptr inbounds double, double* %1, i64 1
%11 = zext i32 %4 to i64
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %40, %12 ]
%14 = tail call i64 @ORDER(i32 0, i32 0, i32 2, i32 2)
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = load double, double* %15
%17 = getelementptr inbounds double, double* %2, i64 %13
%18 = load double, double* %17
%19 = tail call i64 @ORDER(i32 0, i32 1, i32 2, i32 2)
%20 = getelementptr inbounds double, double* %0, i64 %19
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %3, i64 %13
%23 = load double, double* %22
%24 = fmul double %21, %23
%25 = tail call double @llvm.fmuladd.f64(double %16, double %18, double %24)
%26 = load double, double* %1
%27 = fadd double %26, %25
%28 = getelementptr inbounds double, double* %5, i64 %13
store double %27, double* %28
%29 = tail call i64 @ORDER(i32 1, i32 0, i32 2, i32 2)
%30 = getelementptr inbounds double, double* %0, i64 %29
%31 = load double, double* %30
%32 = tail call i64 @ORDER(i32 1, i32 1, i32 2, i32 2)
%33 = getelementptr inbounds double, double* %0, i64 %32
%34 = load double, double* %33
%35 = fmul double %23, %34
%36 = tail call double @llvm.fmuladd.f64(double %31, double %18, double %35)
%37 = load double, double* %10
%38 = fadd double %37, %36
%39 = getelementptr inbounds double, double* %6, i64 %13
store double %38, double* %39
%40 = add nuw nsw i64 %13, 1
%41 = icmp eq i64 %40, %11
br i1 %41, label %42, label %12
42: ; preds = %12, %7
ret void
}