; LLVM IR from VT-ICAM/cfem :: cfem (cf_affine_transformation)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.cf_ref_arrays_s = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, double }
%struct.cf_local_element_s = type { [3 x double], [3 x double], [4 x double], [2 x double], double, double, ptr }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @cf_affine_transformation(ptr noundef %0, ptr noundef %1, ptr noundef nonnull align 8 %2, ptr noundef nonnull align 8 %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.cf_ref_arrays_s, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.cf_ref_arrays_s, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = zext i32 %18 to i64
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.cf_local_element_s, ptr %20, i32 0, i32 2
  %22 = getelementptr inbounds [4 x double], ptr %21, i64 0, i64 0
  store ptr %22, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.cf_local_element_s, ptr %23, i32 0, i32 3
  %25 = getelementptr inbounds [2 x double], ptr %24, i64 0, i64 0
  store ptr %25, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %26

26:                                               ; preds = %93, %4
  %27 = load i32, ptr %9, align 4, !tbaa !13
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.cf_ref_arrays_s, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !9
  %31 = icmp slt i32 %27, %30
  br i1 %31, label %32, label %96

32:                                               ; preds = %26
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = getelementptr inbounds double, ptr %33, i64 0
  %35 = load double, ptr %34, align 8, !tbaa !14
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.cf_ref_arrays_s, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  %39 = load i32, ptr %9, align 4, !tbaa !13
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %38, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !14
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds double, ptr %43, i64 1
  %45 = load double, ptr %44, align 8, !tbaa !14
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.cf_ref_arrays_s, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = load i32, ptr %9, align 4, !tbaa !13
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %48, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !14
  %53 = fmul double %45, %52
  %54 = call double @llvm.fmuladd.f64(double %35, double %42, double %53)
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = getelementptr inbounds double, ptr %55, i64 0
  %57 = load double, ptr %56, align 8, !tbaa !14
  %58 = fadd double %54, %57
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i32, ptr %9, align 4, !tbaa !13
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds double, ptr %59, i64 %61
  store double %58, ptr %62, align 8, !tbaa !14
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds double, ptr %63, i64 2
  %65 = load double, ptr %64, align 8, !tbaa !14
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.cf_ref_arrays_s, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !15
  %69 = load i32, ptr %9, align 4, !tbaa !13
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds double, ptr %68, i64 %70
  %72 = load double, ptr %71, align 8, !tbaa !14
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = getelementptr inbounds double, ptr %73, i64 3
  %75 = load double, ptr %74, align 8, !tbaa !14
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.cf_ref_arrays_s, ptr %76, i32 0, i32 3
  %78 = load ptr, ptr %77, align 8, !tbaa !16
  %79 = load i32, ptr %9, align 4, !tbaa !13
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds double, ptr %78, i64 %80
  %82 = load double, ptr %81, align 8, !tbaa !14
  %83 = fmul double %75, %82
  %84 = call double @llvm.fmuladd.f64(double %65, double %72, double %83)
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = getelementptr inbounds double, ptr %85, i64 1
  %87 = load double, ptr %86, align 8, !tbaa !14
  %88 = fadd double %84, %87
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = load i32, ptr %9, align 4, !tbaa !13
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds double, ptr %89, i64 %91
  store double %88, ptr %92, align 8, !tbaa !14
  br label %93

93:                                               ; preds = %32
  %94 = load i32, ptr %9, align 4, !tbaa !13
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %9, align 4, !tbaa !13
  br label %26, !llvm.loop !17

96:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !12, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !6, i64 8}
!16 = !{!10, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @cf_affine_transformation(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef nonnull writeonly align 8 %2, ptr nocapture noundef nonnull writeonly align 8 %3) local_unnamed_addr #0 {
  %5 = getelementptr i8, ptr %1, i64 48
  %6 = getelementptr inbounds i8, ptr %1, i64 80
  %7 = load i32, ptr %0, align 8, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %1, i64 56
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %1, i64 64
  %15 = getelementptr inbounds i8, ptr %1, i64 72
  %16 = getelementptr inbounds i8, ptr %1, i64 88
  %wide.trip.count = zext nneg i32 %7 to i64
  %min.iters.check = icmp ult i32 %7, 10
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %17 = shl nuw nsw i64 %wide.trip.count, 3
  %scevgep = getelementptr i8, ptr %2, i64 %17
  %scevgep26 = getelementptr i8, ptr %3, i64 %17
  %scevgep27 = getelementptr i8, ptr %1, i64 96
  %scevgep28 = getelementptr i8, ptr %10, i64 %17
  %scevgep29 = getelementptr i8, ptr %13, i64 %17
  %18 = insertelement <4 x ptr> poison, ptr %scevgep26, i64 0
  %19 = insertelement <4 x ptr> %18, ptr %scevgep27, i64 1
  %20 = insertelement <4 x ptr> %19, ptr %scevgep28, i64 2
  %21 = insertelement <4 x ptr> %20, ptr %scevgep29, i64 3
  %22 = insertelement <4 x ptr> poison, ptr %2, i64 0
  %23 = shufflevector <4 x ptr> %22, <4 x ptr> poison, <4 x i32> zeroinitializer
  %24 = icmp ugt <4 x ptr> %21, %23
  %25 = insertelement <4 x ptr> poison, ptr %scevgep, i64 0
  %26 = shufflevector <4 x ptr> %25, <4 x ptr> poison, <4 x i32> zeroinitializer
  %27 = insertelement <4 x ptr> poison, ptr %3, i64 0
  %28 = insertelement <4 x ptr> %27, ptr %5, i64 1
  %29 = insertelement <4 x ptr> %28, ptr %10, i64 2
  %30 = insertelement <4 x ptr> %29, ptr %13, i64 3
  %31 = icmp ugt <4 x ptr> %26, %30
  %32 = and <4 x i1> %24, %31
  %bound041 = icmp ugt ptr %scevgep27, %3
  %bound142 = icmp ult ptr %5, %scevgep26
  %found.conflict43 = and i1 %bound041, %bound142
  %bound045 = icmp ugt ptr %scevgep28, %3
  %bound146 = icmp ult ptr %10, %scevgep26
  %found.conflict47 = and i1 %bound045, %bound146
  %bound049 = icmp ugt ptr %scevgep29, %3
  %bound150 = icmp ult ptr %13, %scevgep26
  %found.conflict51 = and i1 %bound049, %bound150
  %33 = bitcast <4 x i1> %32 to i4
  %34 = icmp ne i4 %33, 0
  %op.rdx = or i1 %34, %found.conflict43
  %op.rdx66 = or i1 %found.conflict47, %found.conflict51
  %op.rdx67 = or i1 %op.rdx, %op.rdx66
  br i1 %op.rdx67, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 2147483646
  %35 = load double, ptr %5, align 8, !tbaa !14, !alias.scope !15
  %broadcast.splatinsert54 = insertelement <2 x double> poison, double %35, i64 0
  %broadcast.splat55 = shufflevector <2 x double> %broadcast.splatinsert54, <2 x double> poison, <2 x i32> zeroinitializer
  %36 = load double, ptr %11, align 8, !tbaa !14, !alias.scope !15
  %broadcast.splatinsert = insertelement <2 x double> poison, double %36, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %37 = load double, ptr %6, align 8, !tbaa !14, !alias.scope !15
  %broadcast.splatinsert56 = insertelement <2 x double> poison, double %37, i64 0
  %broadcast.splat57 = shufflevector <2 x double> %broadcast.splatinsert56, <2 x double> poison, <2 x i32> zeroinitializer
  %38 = load double, ptr %14, align 8, !tbaa !14, !alias.scope !15
  %broadcast.splatinsert62 = insertelement <2 x double> poison, double %38, i64 0
  %broadcast.splat63 = shufflevector <2 x double> %broadcast.splatinsert62, <2 x double> poison, <2 x i32> zeroinitializer
  %39 = load double, ptr %15, align 8, !tbaa !14, !alias.scope !15
  %broadcast.splatinsert60 = insertelement <2 x double> poison, double %39, i64 0
  %broadcast.splat61 = shufflevector <2 x double> %broadcast.splatinsert60, <2 x double> poison, <2 x i32> zeroinitializer
  %40 = load double, ptr %16, align 8, !tbaa !14, !alias.scope !15
  %broadcast.splatinsert64 = insertelement <2 x double> poison, double %40, i64 0
  %broadcast.splat65 = shufflevector <2 x double> %broadcast.splatinsert64, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %41 = getelementptr inbounds double, ptr %10, i64 %index
  %wide.load = load <2 x double>, ptr %41, align 8, !tbaa !14, !alias.scope !18
  %42 = getelementptr inbounds double, ptr %13, i64 %index
  %wide.load53 = load <2 x double>, ptr %42, align 8, !tbaa !14, !alias.scope !20
  %43 = fmul <2 x double> %broadcast.splat, %wide.load53
  %44 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat55, <2 x double> %wide.load, <2 x double> %43)
  %45 = fadd <2 x double> %broadcast.splat57, %44
  %46 = getelementptr inbounds double, ptr %2, i64 %index
  store <2 x double> %45, ptr %46, align 8, !tbaa !14, !alias.scope !22, !noalias !24
  %wide.load58 = load <2 x double>, ptr %41, align 8, !tbaa !14, !alias.scope !18
  %wide.load59 = load <2 x double>, ptr %42, align 8, !tbaa !14, !alias.scope !20
  %47 = fmul <2 x double> %broadcast.splat61, %wide.load59
  %48 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat63, <2 x double> %wide.load58, <2 x double> %47)
  %49 = fadd <2 x double> %broadcast.splat65, %48
  %50 = getelementptr inbounds double, ptr %3, i64 %index
  store <2 x double> %49, ptr %50, align 8, !tbaa !14, !alias.scope !26, !noalias !27
  %index.next = add nuw i64 %index, 2
  %51 = icmp eq i64 %index.next, %n.vec
  br i1 %51, label %middle.block, label %vector.body, !llvm.loop !28

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %52 = load double, ptr %5, align 8, !tbaa !14
  %53 = getelementptr inbounds double, ptr %10, i64 %indvars.iv
  %54 = load double, ptr %53, align 8, !tbaa !14
  %55 = load double, ptr %11, align 8, !tbaa !14
  %56 = getelementptr inbounds double, ptr %13, i64 %indvars.iv
  %57 = load double, ptr %56, align 8, !tbaa !14
  %58 = fmul double %55, %57
  %59 = tail call double @llvm.fmuladd.f64(double %52, double %54, double %58)
  %60 = load double, ptr %6, align 8, !tbaa !14
  %61 = fadd double %60, %59
  %62 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  store double %61, ptr %62, align 8, !tbaa !14
  %63 = load double, ptr %14, align 8, !tbaa !14
  %64 = load double, ptr %53, align 8, !tbaa !14
  %65 = load double, ptr %15, align 8, !tbaa !14
  %66 = load double, ptr %56, align 8, !tbaa !14
  %67 = fmul double %65, %66
  %68 = tail call double @llvm.fmuladd.f64(double %63, double %64, double %67)
  %69 = load double, ptr %16, align 8, !tbaa !14
  %70 = fadd double %69, %68
  %71 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  store double %70, ptr %71, align 8, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !32

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !11, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !10, i64 16}
!14 = !{!11, !11, i64 0}
!15 = !{!16}
!16 = distinct !{!16, !17}
!17 = distinct !{!17, !"LVerDomain"}
!18 = !{!19}
!19 = distinct !{!19, !17}
!20 = !{!21}
!21 = distinct !{!21, !17}
!22 = !{!23}
!23 = distinct !{!23, !17}
!24 = !{!25, !16, !19, !21}
!25 = distinct !{!25, !17}
!26 = !{!25}
!27 = !{!16, !19, !21}
!28 = distinct !{!28, !29, !30, !31}
!29 = !{!"llvm.loop.mustprogress"}
!30 = !{!"llvm.loop.isvectorized", i32 1}
!31 = !{!"llvm.loop.unroll.runtime.disable"}
!32 = distinct !{!32, !29, !30}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass