; LLVM IR from AasmundResell/CFD-Marker-and-Cell :: Marin_Datalab/src/calAvg.ll (Z16calculateAverageRK5FieldR9Field_Val)

; 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.Field = type { [2704 x double], [2704 x double], [2704 x double] }
%struct.Field_Val = type { [2500 x double], [2500 x double], [2500 x double], [2601 x double] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z16calculateAverageRK5FieldR9Field_Val(ptr noundef nonnull align 8 dereferenceable(64896) %0, ptr noundef nonnull align 8 dereferenceable(80808) %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %103, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 50
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %106

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %99, %12
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 50
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %102

17:                                               ; preds = %13
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Field, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  %23 = mul nsw i32 %22, 52
  %24 = add nsw i32 %20, %23
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [2704 x double], ptr %19, i64 0, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Field, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  %34 = mul nsw i32 %33, 52
  %35 = add nsw i32 %31, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [2704 x double], ptr %29, i64 0, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !11
  %39 = fadd double %27, %38
  %40 = fdiv double %39, 2.000000e+00
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Field_Val, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = mul nsw i32 %44, 50
  %46 = add nsw i32 %43, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2500 x double], ptr %42, i64 0, i64 %47
  store double %40, ptr %48, align 8, !tbaa !11
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Field, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = mul nsw i32 %53, 52
  %55 = add nsw i32 %52, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [2704 x double], ptr %50, i64 0, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !11
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Field, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  %65 = mul nsw i32 %64, 52
  %66 = add nsw i32 %62, %65
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [2704 x double], ptr %60, i64 0, i64 %67
  %69 = load double, ptr %68, align 8, !tbaa !11
  %70 = fadd double %58, %69
  %71 = fdiv double %70, 2.000000e+00
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.Field_Val, ptr %72, i32 0, i32 1
  %74 = load i32, ptr %7, align 4, !tbaa !9
  %75 = load i32, ptr %5, align 4, !tbaa !9
  %76 = mul nsw i32 %75, 50
  %77 = add nsw i32 %74, %76
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [2500 x double], ptr %73, i64 0, i64 %78
  store double %71, ptr %79, align 8, !tbaa !11
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.Field, ptr %80, i32 0, i32 2
  %82 = load i32, ptr %5, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  %84 = load i32, ptr %7, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  %86 = mul nsw i32 %85, 52
  %87 = add nsw i32 %83, %86
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [2704 x double], ptr %81, i64 0, i64 %88
  %90 = load double, ptr %89, align 8, !tbaa !11
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.Field_Val, ptr %91, i32 0, i32 2
  %93 = load i32, ptr %7, align 4, !tbaa !9
  %94 = load i32, ptr %5, align 4, !tbaa !9
  %95 = mul nsw i32 %94, 50
  %96 = add nsw i32 %93, %95
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [2500 x double], ptr %92, i64 0, i64 %97
  store double %90, ptr %98, align 8, !tbaa !11
  br label %99

99:                                               ; preds = %17
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %7, align 4, !tbaa !9
  br label %13, !llvm.loop !13

102:                                              ; preds = %16
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %5, align 4, !tbaa !9
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !15

106:                                              ; preds = %11
  ret void
}

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

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

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z16calculateAverageRK5FieldR9Field_Val(ptr nocapture noundef nonnull readonly align 8 dereferenceable(64896) %0, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(80808) %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 21632
  %4 = getelementptr inbounds i8, ptr %1, i64 20000
  %5 = getelementptr inbounds i8, ptr %0, i64 43264
  %6 = getelementptr inbounds i8, ptr %1, i64 40000
  br label %.preheader

.preheader:                                       ; preds = %2, %9
  %indvars.iv31 = phi i64 [ 0, %2 ], [ %indvars.iv.next32, %9 ]
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %7 = mul nuw nsw i64 %indvars.iv31, 50
  br label %10

8:                                                ; preds = %9
  ret void

9:                                                ; preds = %10
  %exitcond34.not = icmp eq i64 %indvars.iv.next32, 50
  br i1 %exitcond34.not, label %8, label %.preheader, !llvm.loop !5

10:                                               ; preds = %.preheader, %10
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %10 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = mul nuw nsw i64 %indvars.iv.next, 52
  %12 = add nuw nsw i64 %11, %indvars.iv31
  %13 = getelementptr inbounds [2704 x double], ptr %0, i64 0, i64 %12
  %14 = load double, ptr %13, align 8, !tbaa !7
  %15 = add nuw nsw i64 %11, %indvars.iv.next32
  %16 = getelementptr inbounds [2704 x double], ptr %0, i64 0, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !7
  %18 = fadd double %14, %17
  %19 = fmul double %18, 5.000000e-01
  %20 = add nuw nsw i64 %indvars.iv, %7
  %21 = getelementptr inbounds [2500 x double], ptr %1, i64 0, i64 %20
  store double %19, ptr %21, align 8, !tbaa !7
  %22 = mul nuw nsw i64 %indvars.iv, 52
  %23 = add nuw nsw i64 %22, %indvars.iv.next32
  %24 = getelementptr inbounds [2704 x double], ptr %3, i64 0, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !7
  %26 = getelementptr inbounds [2704 x double], ptr %3, i64 0, i64 %15
  %27 = load double, ptr %26, align 8, !tbaa !7
  %28 = fadd double %25, %27
  %29 = fmul double %28, 5.000000e-01
  %30 = getelementptr inbounds [2500 x double], ptr %4, i64 0, i64 %20
  store double %29, ptr %30, align 8, !tbaa !7
  %31 = getelementptr inbounds [2704 x double], ptr %5, i64 0, i64 %15
  %32 = load double, ptr %31, align 8, !tbaa !7
  %33 = getelementptr inbounds [2500 x double], ptr %6, i64 0, i64 %20
  store double %32, ptr %33, align 8, !tbaa !7
  %exitcond.not = icmp eq i64 %indvars.iv.next, 50
  br i1 %exitcond.not, label %9, label %10, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass