; LLVM IR from alexzheng42/sDMD :: analysis (RMSD)

; 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.AtomStr = type { ptr, ptr }
%struct.PropertyStr = type { [8 x i8], [2 x [16 x i8]], [8 x i8], i32, i32, i32, double, double, [3 x double], %struct.AtomSeqStr, ptr, ptr }
%struct.AtomSeqStr = type { i32, i32, i32 }

@nRow = external hidden global i32, align 4
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@path = external global [1024 x i8], align 16
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [12 x i8], align 1
@nPP = external global i32, align 4
@.str.27 = external hidden unnamed_addr constant [5 x i8], align 1
@offSet = external hidden global i32, align 4
@thisAtomNum = external hidden global i32, align 4
@.str.28 = external hidden unnamed_addr constant [30 x i8], align 1
@atom = external global ptr, align 8
@.str.29 = external hidden unnamed_addr constant [20 x i8], align 1
@boxCurtDim = external global [4 x double], align 16

; 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
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #1

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

declare i32 @fclose(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @SaveMatrix(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [1024 x i8], align 16
  %7 = alloca ptr, align 8
  %8 = 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) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1024, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %9, ptr noundef @.str.3, ptr noundef @path, ptr noundef %10) #4
  %12 = getelementptr inbounds [1024 x i8], ptr %6, i64 0, i64 0
  %13 = call noalias ptr @fopen(ptr noundef %12, ptr noundef @.str.4)
  store ptr %13, ptr %7, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load i32, ptr @nPP, align 4, !tbaa !9
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str.26, i32 noundef %15) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load i32, ptr @nRow, align 4, !tbaa !9
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef @.str.27, i32 noundef %18) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %20 = load i32, ptr @offSet, align 4, !tbaa !9
  %21 = add nsw i32 1, %20
  store i32 %21, ptr %8, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %90, %2
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = load i32, ptr @thisAtomNum, align 4, !tbaa !9
  %25 = load i32, ptr @offSet, align 4, !tbaa !9
  %26 = add nsw i32 %24, %25
  %27 = icmp sle i32 %23, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %93

29:                                               ; preds = %22
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = call i32 @CheckBackbone(i32 noundef %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  br label %90

34:                                               ; preds = %29
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr @atom, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %struct.AtomStr, ptr %36, i64 %38
  %40 = getelementptr inbounds %struct.AtomStr, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.PropertyStr, ptr %41, i32 0, i32 9
  %43 = getelementptr inbounds %struct.AtomSeqStr, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !13
  %45 = load ptr, ptr @atom, align 8, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.AtomStr, ptr %45, i64 %47
  %49 = getelementptr inbounds %struct.AtomStr, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.PropertyStr, ptr %50, i32 0, i32 2
  %52 = getelementptr inbounds [8 x i8], ptr %51, i64 0, i64 0
  %53 = load ptr, ptr @atom, align 8, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds %struct.AtomStr, ptr %53, i64 %55
  %57 = getelementptr inbounds %struct.AtomStr, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = getelementptr inbounds %struct.PropertyStr, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds [8 x i8], ptr %59, i64 0, i64 0
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %63, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = getelementptr inbounds double, ptr %67, i64 0
  %69 = load double, ptr %68, align 8, !tbaa !17
  %70 = fdiv double %69, 1.000000e+01
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds ptr, ptr %71, i64 %73
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  %76 = getelementptr inbounds double, ptr %75, i64 1
  %77 = load double, ptr %76, align 8, !tbaa !17
  %78 = fdiv double %77, 1.000000e+01
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds ptr, ptr %79, i64 %81
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = getelementptr inbounds double, ptr %83, i64 2
  %85 = load double, ptr %84, align 8, !tbaa !17
  %86 = fdiv double %85, 1.000000e+01
  %87 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.28, i32 noundef %44, ptr noundef %52, ptr noundef %60, i32 noundef %62, double noundef %70, double noundef %78, double noundef %86) #4
  %88 = load i32, ptr %5, align 4, !tbaa !9
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %5, align 4, !tbaa !9
  br label %90

90:                                               ; preds = %34, %33
  %91 = load i32, ptr %8, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %8, align 4, !tbaa !9
  br label %22, !llvm.loop !18

93:                                               ; preds = %28
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load double, ptr getelementptr inbounds ([4 x double], ptr @boxCurtDim, i64 0, i64 1), align 8, !tbaa !17
  %96 = fdiv double %95, 1.000000e+01
  %97 = load double, ptr getelementptr inbounds ([4 x double], ptr @boxCurtDim, i64 0, i64 2), align 16, !tbaa !17
  %98 = fdiv double %97, 1.000000e+01
  %99 = load double, ptr getelementptr inbounds ([4 x double], ptr @boxCurtDim, i64 0, i64 3), align 8, !tbaa !17
  %100 = fdiv double %99, 1.000000e+01
  %101 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %94, ptr noundef @.str.29, double noundef %96, double noundef %98, double noundef %100) #4
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = call i32 @fclose(ptr noundef %102)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1024, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden i32 @CheckBackbone(i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { "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 #3 = { 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 #4 = { 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 0}
!12 = !{!"AtomStr", !6, i64 0, !6, i64 8}
!13 = !{!14, !10, i64 112}
!14 = !{!"PropertyStr", !7, i64 0, !7, i64 8, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !15, i64 64, !15, i64 72, !7, i64 80, !16, i64 104, !6, i64 120, !6, i64 128}
!15 = !{!"double", !7, i64 0}
!16 = !{!"AtomSeqStr", !10, i64 0, !10, i64 4, !10, i64 8}
!17 = !{!15, !15, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.AtomStr = type { ptr, ptr }

@nRow = external hidden local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@path = external global [1024 x i8], align 16
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [12 x i8], align 1
@nPP = external local_unnamed_addr global i32, align 4
@.str.27 = external hidden unnamed_addr constant [5 x i8], align 1
@offSet = external hidden local_unnamed_addr global i32, align 4
@thisAtomNum = external hidden local_unnamed_addr global i32, align 4
@.str.28 = external hidden unnamed_addr constant [30 x i8], align 1
@atom = external local_unnamed_addr global ptr, align 8
@.str.29 = external hidden unnamed_addr constant [20 x i8], align 1
@boxCurtDim = external local_unnamed_addr global [4 x double], align 16

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @SaveMatrix(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca [1024 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #3
  %4 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull @path, ptr noundef %1) #3
  %5 = call noalias ptr @fopen(ptr noundef nonnull %3, ptr noundef nonnull @.str.4)
  %6 = load i32, ptr @nPP, align 4, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.26, i32 noundef %6) #3
  %8 = load i32, ptr @nRow, align 4, !tbaa !5
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.27, i32 noundef %8) #3
  %10 = load i32, ptr @thisAtomNum, align 4, !tbaa !5
  %.not.not21 = icmp sgt i32 %10, 0
  br i1 %.not.not21, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %11 = load i32, ptr @offSet, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %43, %2
  %13 = load double, ptr getelementptr inbounds (i8, ptr @boxCurtDim, i64 8), align 8, !tbaa !9
  %14 = fdiv double %13, 1.000000e+01
  %15 = load double, ptr getelementptr inbounds (i8, ptr @boxCurtDim, i64 16), align 16, !tbaa !9
  %16 = fdiv double %15, 1.000000e+01
  %17 = load double, ptr getelementptr inbounds (i8, ptr @boxCurtDim, i64 24), align 8, !tbaa !9
  %18 = fdiv double %17, 1.000000e+01
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.29, double noundef %14, double noundef %16, double noundef %18) #3
  %20 = tail call i32 @fclose(ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #3
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %43
  %indvars.iv = phi i64 [ %12, %.lr.ph.preheader ], [ %indvars.iv.next, %43 ]
  %.01922 = phi i32 [ 0, %.lr.ph.preheader ], [ %.1, %43 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %21 = trunc nsw i64 %indvars.iv.next to i32
  %22 = tail call i32 @CheckBackbone(i32 noundef %21)
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %43, label %23

23:                                               ; preds = %.lr.ph
  %24 = load ptr, ptr @atom, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.AtomStr, ptr %24, i64 %indvars.iv.next
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %26, i64 112
  %28 = load i32, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds i8, ptr %26, i64 40
  %30 = add nsw i32 %.01922, 1
  %31 = sext i32 %.01922 to i64
  %32 = getelementptr inbounds ptr, ptr %0, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = fdiv double %34, 1.000000e+01
  %36 = getelementptr inbounds i8, ptr %33, i64 8
  %37 = load double, ptr %36, align 8, !tbaa !9
  %38 = fdiv double %37, 1.000000e+01
  %39 = getelementptr inbounds i8, ptr %33, i64 16
  %40 = load double, ptr %39, align 8, !tbaa !9
  %41 = fdiv double %40, 1.000000e+01
  %42 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.28, i32 noundef %28, ptr noundef nonnull %29, ptr noundef %26, i32 noundef %30, double noundef %35, double noundef %38, double noundef %41) #3
  br label %43

43:                                               ; preds = %.lr.ph, %23
  %.1 = phi i32 [ %30, %23 ], [ %.01922, %.lr.ph ]
  %44 = load i32, ptr @thisAtomNum, align 4, !tbaa !5
  %45 = load i32, ptr @offSet, align 4, !tbaa !5
  %46 = add nsw i32 %45, %44
  %47 = sext i32 %46 to i64
  %.not.not = icmp slt i64 %indvars.iv.next, %47
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !18
}

; Function Attrs: nounwind uwtable
declare hidden i32 @CheckBackbone(i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nounwind "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 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"AtomStr", !12, i64 0, !12, i64 8}
!15 = !{!16, !6, i64 112}
!16 = !{!"PropertyStr", !7, i64 0, !7, i64 8, !7, i64 40, !6, i64 48, !6, i64 52, !6, i64 56, !10, i64 64, !10, i64 72, !7, i64 80, !17, i64 104, !12, i64 120, !12, i64 128}
!17 = !{!"AtomSeqStr", !6, i64 0, !6, i64 4, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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