; LLVM IR from simbody/simbody :: SimTKmath/Integrators/src/CPodes/sundials/src/cpodes (cpodes)

; 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.CPodeMemRec = type { double, i32, ptr, ptr, ptr, i32, i32, i32, double, double, ptr, ptr, ptr, [13 x ptr], ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, double, double, double, double, double, double, double, double, [14 x double], [6 x double], [13 x double], [13 x double], double, double, double, double, double, double, double, i32, i32, i32, i32, i64, i64, i32, i32, ptr, ptr, ptr, ptr, double, ptr, ptr, ptr, i64, i64, double, i32, i32, i32, ptr, ptr, ptr, ptr, i32, i64, i64, i64, i64, i32, i32, ptr, ptr, i32, i32, double, double, ptr, [13 x ptr], ptr, ptr, ptr, ptr, double, i64, i64, i32, i32, i32, i64, i64, i32, i32, double, i32, i64, i32, i32, i32, i32, double, double, double, i64, i64, i64, i64, i64, i64, i32, double, double, double, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i64, double, double, double, i32, double, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, [6 x [4 x double]], i32, i64, i32, ptr, i32, ptr, ptr, ptr, ptr, double, double, double, ptr, ptr, ptr, double, i32, i32, i64, double, double, i32, i32, ptr, 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

declare void @N_VScale(double noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @cpRescale(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.CPodeMemRec, ptr %5, i32 0, i32 29
  %7 = load double, ptr %6, align 8, !tbaa !9
  store double %7, ptr %4, align 8, !tbaa !14
  store i32 1, ptr %3, align 4, !tbaa !15
  br label %8

8:                                                ; preds = %52, %1
  %9 = load i32, ptr %3, align 4, !tbaa !15
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.CPodeMemRec, ptr %10, i32 0, i32 20
  %12 = load i32, ptr %11, align 8, !tbaa !16
  %13 = icmp sle i32 %9, %12
  br i1 %13, label %14, label %55

14:                                               ; preds = %8
  %15 = load double, ptr %4, align 8, !tbaa !14
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.CPodeMemRec, ptr %16, i32 0, i32 13
  %18 = load i32, ptr %3, align 4, !tbaa !15
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [13 x ptr], ptr %17, i64 0, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.CPodeMemRec, ptr %22, i32 0, i32 13
  %24 = load i32, ptr %3, align 4, !tbaa !15
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [13 x ptr], ptr %23, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  call void @N_VScale(double noundef %15, ptr noundef %21, ptr noundef %27)
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.CPodeMemRec, ptr %28, i32 0, i32 76
  %30 = load i32, ptr %29, align 4, !tbaa !17
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %46

32:                                               ; preds = %14
  %33 = load double, ptr %4, align 8, !tbaa !14
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.CPodeMemRec, ptr %34, i32 0, i32 84
  %36 = load i32, ptr %3, align 4, !tbaa !15
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [13 x ptr], ptr %35, i64 0, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.CPodeMemRec, ptr %40, i32 0, i32 84
  %42 = load i32, ptr %3, align 4, !tbaa !15
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [13 x ptr], ptr %41, i64 0, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  call void @N_VScale(double noundef %33, ptr noundef %39, ptr noundef %45)
  br label %46

46:                                               ; preds = %32, %14
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.CPodeMemRec, ptr %47, i32 0, i32 29
  %49 = load double, ptr %48, align 8, !tbaa !9
  %50 = load double, ptr %4, align 8, !tbaa !14
  %51 = fmul double %50, %49
  store double %51, ptr %4, align 8, !tbaa !14
  br label %52

52:                                               ; preds = %46
  %53 = load i32, ptr %3, align 4, !tbaa !15
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %3, align 4, !tbaa !15
  br label %8, !llvm.loop !18

55:                                               ; preds = %8
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.CPodeMemRec, ptr %56, i32 0, i32 30
  %58 = load double, ptr %57, align 8, !tbaa !20
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.CPodeMemRec, ptr %59, i32 0, i32 29
  %61 = load double, ptr %60, align 8, !tbaa !9
  %62 = fmul double %58, %61
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.CPodeMemRec, ptr %63, i32 0, i32 26
  store double %62, ptr %64, align 8, !tbaa !21
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.CPodeMemRec, ptr %65, i32 0, i32 26
  %67 = load double, ptr %66, align 8, !tbaa !21
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.CPodeMemRec, ptr %68, i32 0, i32 28
  store double %67, ptr %69, align 8, !tbaa !22
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.CPodeMemRec, ptr %70, i32 0, i32 26
  %72 = load double, ptr %71, align 8, !tbaa !21
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.CPodeMemRec, ptr %73, i32 0, i32 30
  store double %72, ptr %74, align 8, !tbaa !20
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.CPodeMemRec, ptr %75, i32 0, i32 156
  store i32 0, ptr %76, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 304}
!10 = !{!"CPodeMemRec", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !12, i64 44, !12, i64 48, !11, i64 56, !11, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !7, i64 96, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !12, i64 248, !12, i64 252, !12, i64 256, !12, i64 260, !12, i64 264, !11, i64 272, !11, i64 280, !11, i64 288, !11, i64 296, !11, i64 304, !11, i64 312, !11, i64 320, !11, i64 328, !7, i64 336, !7, i64 448, !7, i64 496, !7, i64 600, !11, i64 704, !11, i64 712, !11, i64 720, !11, i64 728, !11, i64 736, !11, i64 744, !11, i64 752, !12, i64 760, !12, i64 764, !12, i64 768, !12, i64 772, !13, i64 776, !13, i64 784, !12, i64 792, !12, i64 796, !6, i64 800, !6, i64 808, !6, i64 816, !6, i64 824, !11, i64 832, !6, i64 840, !6, i64 848, !6, i64 856, !13, i64 864, !13, i64 872, !11, i64 880, !12, i64 888, !12, i64 892, !12, i64 896, !6, i64 904, !6, i64 912, !6, i64 920, !6, i64 928, !12, i64 936, !13, i64 944, !13, i64 952, !13, i64 960, !13, i64 968, !12, i64 976, !12, i64 980, !6, i64 984, !6, i64 992, !12, i64 1000, !12, i64 1004, !11, i64 1008, !11, i64 1016, !6, i64 1024, !7, i64 1032, !6, i64 1136, !6, i64 1144, !6, i64 1152, !6, i64 1160, !11, i64 1168, !13, i64 1176, !13, i64 1184, !12, i64 1192, !12, i64 1196, !12, i64 1200, !13, i64 1208, !13, i64 1216, !12, i64 1224, !12, i64 1228, !11, i64 1232, !12, i64 1240, !13, i64 1248, !12, i64 1256, !12, i64 1260, !12, i64 1264, !12, i64 1268, !11, i64 1272, !11, i64 1280, !11, i64 1288, !13, i64 1296, !13, i64 1304, !13, i64 1312, !13, i64 1320, !13, i64 1328, !13, i64 1336, !12, i64 1344, !11, i64 1352, !11, i64 1360, !11, i64 1368, !13, i64 1376, !13, i64 1384, !13, i64 1392, !13, i64 1400, !13, i64 1408, !13, i64 1416, !6, i64 1424, !6, i64 1432, !6, i64 1440, !6, i64 1448, !6, i64 1456, !12, i64 1464, !6, i64 1472, !6, i64 1480, !6, i64 1488, !6, i64 1496, !6, i64 1504, !6, i64 1512, !12, i64 1520, !12, i64 1524, !13, i64 1528, !11, i64 1536, !11, i64 1544, !11, i64 1552, !12, i64 1560, !11, i64 1568, !12, i64 1576, !12, i64 1580, !12, i64 1584, !12, i64 1588, !12, i64 1592, !12, i64 1596, !6, i64 1600, !6, i64 1608, !6, i64 1616, !12, i64 1624, !7, i64 1632, !12, i64 1824, !13, i64 1832, !12, i64 1840, !6, i64 1848, !12, i64 1856, !6, i64 1864, !6, i64 1872, !6, i64 1880, !6, i64 1888, !11, i64 1896, !11, i64 1904, !11, i64 1912, !6, i64 1920, !6, i64 1928, !6, i64 1936, !11, i64 1944, !12, i64 1952, !12, i64 1956, !13, i64 1960, !11, i64 1968, !11, i64 1976, !12, i64 1984, !12, i64 1988, !6, i64 1992, !6, i64 2000}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 248}
!17 = !{!10, !12, i64 980}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !11, i64 312}
!21 = !{!10, !11, i64 280}
!22 = !{!10, !11, i64 296}
!23 = !{!10, !12, i64 1824}


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

declare void @N_VScale(double noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @cpRescale(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 304
  %3 = getelementptr inbounds i8, ptr %0, i64 248
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not26 = icmp slt i32 %4, 1
  %.pre = load double, ptr %2, align 8, !tbaa !13
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  %6 = getelementptr inbounds i8, ptr %0, i64 980
  %7 = getelementptr inbounds i8, ptr %0, i64 1032
  br label %8

8:                                                ; preds = %.lr.ph, %15
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %15 ]
  %.028 = phi double [ %.pre, %.lr.ph ], [ %17, %15 ]
  %9 = getelementptr inbounds [13 x ptr], ptr %5, i64 0, i64 %indvars.iv
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  tail call void @N_VScale(double noundef %.028, ptr noundef %10, ptr noundef %10) #2
  %11 = load i32, ptr %6, align 4, !tbaa !15
  %.not25 = icmp eq i32 %11, 0
  br i1 %.not25, label %15, label %12

12:                                               ; preds = %8
  %13 = getelementptr inbounds [13 x ptr], ptr %7, i64 0, i64 %indvars.iv
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  tail call void @N_VScale(double noundef %.028, ptr noundef %14, ptr noundef %14) #2
  br label %15

15:                                               ; preds = %12, %8
  %16 = load double, ptr %2, align 8, !tbaa !13
  %17 = fmul double %.028, %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr %3, align 8, !tbaa !5
  %19 = sext i32 %18 to i64
  %.not.not = icmp slt i64 %indvars.iv, %19
  br i1 %.not.not, label %8, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %15, %1
  %20 = phi double [ %.pre, %1 ], [ %16, %15 ]
  %21 = getelementptr inbounds i8, ptr %0, i64 312
  %22 = load double, ptr %21, align 8, !tbaa !18
  %23 = fmul double %22, %20
  %24 = getelementptr inbounds i8, ptr %0, i64 280
  store double %23, ptr %24, align 8, !tbaa !19
  %25 = getelementptr inbounds i8, ptr %0, i64 296
  store double %23, ptr %25, align 8, !tbaa !20
  store double %23, ptr %21, align 8, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %0, i64 1824
  store i32 0, ptr %26, align 8, !tbaa !21
  ret void
}

attributes #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 = { 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, !10, i64 248}
!6 = !{!"CPodeMemRec", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !7, i64 56, !7, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !8, i64 96, !11, i64 200, !11, i64 208, !11, i64 216, !11, i64 224, !11, i64 232, !11, i64 240, !10, i64 248, !10, i64 252, !10, i64 256, !10, i64 260, !10, i64 264, !7, i64 272, !7, i64 280, !7, i64 288, !7, i64 296, !7, i64 304, !7, i64 312, !7, i64 320, !7, i64 328, !8, i64 336, !8, i64 448, !8, i64 496, !8, i64 600, !7, i64 704, !7, i64 712, !7, i64 720, !7, i64 728, !7, i64 736, !7, i64 744, !7, i64 752, !10, i64 760, !10, i64 764, !10, i64 768, !10, i64 772, !12, i64 776, !12, i64 784, !10, i64 792, !10, i64 796, !11, i64 800, !11, i64 808, !11, i64 816, !11, i64 824, !7, i64 832, !11, i64 840, !11, i64 848, !11, i64 856, !12, i64 864, !12, i64 872, !7, i64 880, !10, i64 888, !10, i64 892, !10, i64 896, !11, i64 904, !11, i64 912, !11, i64 920, !11, i64 928, !10, i64 936, !12, i64 944, !12, i64 952, !12, i64 960, !12, i64 968, !10, i64 976, !10, i64 980, !11, i64 984, !11, i64 992, !10, i64 1000, !10, i64 1004, !7, i64 1008, !7, i64 1016, !11, i64 1024, !8, i64 1032, !11, i64 1136, !11, i64 1144, !11, i64 1152, !11, i64 1160, !7, i64 1168, !12, i64 1176, !12, i64 1184, !10, i64 1192, !10, i64 1196, !10, i64 1200, !12, i64 1208, !12, i64 1216, !10, i64 1224, !10, i64 1228, !7, i64 1232, !10, i64 1240, !12, i64 1248, !10, i64 1256, !10, i64 1260, !10, i64 1264, !10, i64 1268, !7, i64 1272, !7, i64 1280, !7, i64 1288, !12, i64 1296, !12, i64 1304, !12, i64 1312, !12, i64 1320, !12, i64 1328, !12, i64 1336, !10, i64 1344, !7, i64 1352, !7, i64 1360, !7, i64 1368, !12, i64 1376, !12, i64 1384, !12, i64 1392, !12, i64 1400, !12, i64 1408, !12, i64 1416, !11, i64 1424, !11, i64 1432, !11, i64 1440, !11, i64 1448, !11, i64 1456, !10, i64 1464, !11, i64 1472, !11, i64 1480, !11, i64 1488, !11, i64 1496, !11, i64 1504, !11, i64 1512, !10, i64 1520, !10, i64 1524, !12, i64 1528, !7, i64 1536, !7, i64 1544, !7, i64 1552, !10, i64 1560, !7, i64 1568, !10, i64 1576, !10, i64 1580, !10, i64 1584, !10, i64 1588, !10, i64 1592, !10, i64 1596, !11, i64 1600, !11, i64 1608, !11, i64 1616, !10, i64 1624, !8, i64 1632, !10, i64 1824, !12, i64 1832, !10, i64 1840, !11, i64 1848, !10, i64 1856, !11, i64 1864, !11, i64 1872, !11, i64 1880, !11, i64 1888, !7, i64 1896, !7, i64 1904, !7, i64 1912, !11, i64 1920, !11, i64 1928, !11, i64 1936, !7, i64 1944, !10, i64 1952, !10, i64 1956, !12, i64 1960, !7, i64 1968, !7, i64 1976, !10, i64 1984, !10, i64 1988, !11, i64 1992, !11, i64 2000}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !7, i64 304}
!14 = !{!11, !11, i64 0}
!15 = !{!6, !10, i64 980}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !7, i64 312}
!19 = !{!6, !7, i64 280}
!20 = !{!6, !7, i64 296}
!21 = !{!6, !10, i64 1824}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass