; LLVM IR from OpenFAST/openfast :: modules/map/src (lineroutines)

; 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.MAP_OtherStateType = type { ptr, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, i32 }

; 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 i32 @update_outer_loop_residuals(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %55, %5
  %13 = load i32, ptr %11, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %58

16:                                               ; preds = %12
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MAP_OtherStateType, ptr %17, i32 0, i32 21
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds double, ptr %19, i64 %21
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = mul nsw i32 3, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds double, ptr %24, i64 %27
  store double %23, ptr %28, align 8, !tbaa !13
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MAP_OtherStateType, ptr %29, i32 0, i32 23
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %31, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !13
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = mul nsw i32 3, %37
  %39 = add nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %36, i64 %40
  store double %35, ptr %41, align 8, !tbaa !13
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.MAP_OtherStateType, ptr %42, i32 0, i32 25
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !13
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = mul nsw i32 3, %50
  %52 = add nsw i32 %51, 2
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds double, ptr %49, i64 %53
  store double %48, ptr %54, align 8, !tbaa !13
  br label %55

55:                                               ; preds = %16
  %56 = load i32, ptr %11, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %11, align 4, !tbaa !9
  br label %12, !llvm.loop !17

58:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret i32 0
}

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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 168}
!12 = !{!"MAP_OtherStateType", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !6, i64 56, !10, i64 64, !6, i64 72, !10, i64 80, !6, i64 88, !10, i64 96, !6, i64 104, !10, i64 112, !6, i64 120, !10, i64 128, !6, i64 136, !10, i64 144, !6, i64 152, !10, i64 160, !6, i64 168, !10, i64 176, !6, i64 184, !10, i64 192, !6, i64 200, !10, i64 208, !6, i64 216, !10, i64 224, !6, i64 232, !10, i64 240, !6, i64 248, !10, i64 256}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !6, i64 184}
!16 = !{!12, !6, i64 200}
!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 noundef i32 @update_outer_loop_residuals(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef readnone %3, ptr nocapture noundef readnone %4) local_unnamed_addr #0 {
  %6 = icmp sgt i32 %2, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %7 = getelementptr inbounds i8, ptr %1, i64 168
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 184
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %1, i64 200
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %wide.trip.count = zext nneg i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 14
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %13 = mul nuw nsw i64 %wide.trip.count, 24
  %scevgep = getelementptr i8, ptr %0, i64 %13
  %14 = shl nuw nsw i64 %wide.trip.count, 3
  %scevgep16 = getelementptr i8, ptr %8, i64 %14
  %scevgep17 = getelementptr i8, ptr %10, i64 %14
  %scevgep18 = getelementptr i8, ptr %12, i64 %14
  %bound0 = icmp ugt ptr %scevgep16, %0
  %bound1 = icmp ult ptr %8, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  %bound019 = icmp ugt ptr %scevgep17, %0
  %bound120 = icmp ult ptr %10, %scevgep
  %found.conflict21 = and i1 %bound019, %bound120
  %conflict.rdx = or i1 %found.conflict, %found.conflict21
  %bound022 = icmp ugt ptr %scevgep18, %0
  %bound123 = icmp ult ptr %12, %scevgep
  %found.conflict24 = and i1 %bound022, %bound123
  %conflict.rdx25 = or i1 %conflict.rdx, %found.conflict24
  br i1 %conflict.rdx25, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 2147483646
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %15 = getelementptr inbounds double, ptr %8, i64 %index
  %wide.load = load <2 x double>, ptr %15, align 8, !tbaa !13, !alias.scope !15
  %16 = mul i64 %index, 24
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  %18 = getelementptr inbounds double, ptr %10, i64 %index
  %wide.load26 = load <2 x double>, ptr %18, align 8, !tbaa !13, !alias.scope !18
  %19 = getelementptr inbounds double, ptr %12, i64 %index
  %wide.load27 = load <2 x double>, ptr %19, align 8, !tbaa !13, !alias.scope !20
  %20 = shufflevector <2 x double> %wide.load, <2 x double> %wide.load26, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  %21 = shufflevector <2 x double> %wide.load27, <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
  %interleaved.vec = shufflevector <4 x double> %20, <4 x double> %21, <6 x i32> <i32 0, i32 2, i32 4, i32 1, i32 3, i32 5>
  store <6 x double> %interleaved.vec, ptr %17, align 8, !tbaa !13
  %index.next = add nuw i64 %index, 2
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !22

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 ]
  %xtraiter = and i64 %wide.trip.count, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %23 = getelementptr inbounds double, ptr %8, i64 %indvars.iv.ph
  %24 = load double, ptr %23, align 8, !tbaa !13
  %.idx.prol = mul nuw nsw i64 %indvars.iv.ph, 24
  %25 = getelementptr inbounds i8, ptr %0, i64 %.idx.prol
  store double %24, ptr %25, align 8, !tbaa !13
  %26 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.ph
  %27 = load double, ptr %26, align 8, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %25, i64 8
  store double %27, ptr %28, align 8, !tbaa !13
  %29 = getelementptr inbounds double, ptr %12, i64 %indvars.iv.ph
  %30 = load double, ptr %29, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %25, i64 16
  store double %30, ptr %31, align 8, !tbaa !13
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %32 = add nsw i64 %wide.trip.count, -1
  %33 = icmp eq i64 %indvars.iv.ph, %32
  br i1 %33, label %._crit_edge, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %34 = getelementptr inbounds double, ptr %8, i64 %indvars.iv
  %35 = load double, ptr %34, align 8, !tbaa !13
  %.idx = mul i64 %indvars.iv, 24
  %36 = getelementptr inbounds i8, ptr %0, i64 %.idx
  store double %35, ptr %36, align 8, !tbaa !13
  %37 = getelementptr inbounds double, ptr %10, i64 %indvars.iv
  %38 = load double, ptr %37, align 8, !tbaa !13
  %39 = getelementptr inbounds i8, ptr %36, i64 8
  store double %38, ptr %39, align 8, !tbaa !13
  %40 = getelementptr inbounds double, ptr %12, i64 %indvars.iv
  %41 = load double, ptr %40, align 8, !tbaa !13
  %42 = getelementptr inbounds i8, ptr %36, i64 16
  store double %41, ptr %42, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = getelementptr inbounds double, ptr %8, i64 %indvars.iv.next
  %44 = load double, ptr %43, align 8, !tbaa !13
  %.idx.1 = mul i64 %indvars.iv.next, 24
  %45 = getelementptr inbounds i8, ptr %0, i64 %.idx.1
  store double %44, ptr %45, align 8, !tbaa !13
  %46 = getelementptr inbounds double, ptr %10, i64 %indvars.iv.next
  %47 = load double, ptr %46, align 8, !tbaa !13
  %48 = getelementptr inbounds i8, ptr %45, i64 8
  store double %47, ptr %48, align 8, !tbaa !13
  %49 = getelementptr inbounds double, ptr %12, i64 %indvars.iv.next
  %50 = load double, ptr %49, align 8, !tbaa !13
  %51 = getelementptr inbounds i8, ptr %45, i64 16
  store double %50, ptr %51, align 8, !tbaa !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %._crit_edge, label %scalar.ph, !llvm.loop !26

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %5
  ret i32 0
}

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" }

!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 168}
!6 = !{!"MAP_OtherStateType", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !10, i64 48, !7, i64 56, !10, i64 64, !7, i64 72, !10, i64 80, !7, i64 88, !10, i64 96, !7, i64 104, !10, i64 112, !7, i64 120, !10, i64 128, !7, i64 136, !10, i64 144, !7, i64 152, !10, i64 160, !7, i64 168, !10, i64 176, !7, i64 184, !10, i64 192, !7, i64 200, !10, i64 208, !7, i64 216, !10, i64 224, !7, i64 232, !10, i64 240, !7, i64 248, !10, i64 256}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 184}
!12 = !{!6, !7, i64 200}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, 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 = distinct !{!22, !23, !24, !25}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!"llvm.loop.isvectorized", i32 1}
!25 = !{!"llvm.loop.unroll.runtime.disable"}
!26 = distinct !{!26, !23, !24}


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