; 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

; Function Attrs: nounwind uwtable
define dso_local void @CPodeFree(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i32 1, ptr %4, align 4
  br label %62

9:                                                ; preds = %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.CPodeMemRec, ptr %12, i32 0, i32 147
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  call void @cpFreeVectors(ptr noundef %17)
  br label %18

18:                                               ; preds = %16, %9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  call void @CPodeQuadFree(ptr noundef %19)
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.CPodeMemRec, ptr %20, i32 0, i32 6
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = icmp eq i32 %22, 2
  br i1 %23, label %24, label %34

24:                                               ; preds = %18
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.CPodeMemRec, ptr %25, i32 0, i32 128
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %34

29:                                               ; preds = %24
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.CPodeMemRec, ptr %30, i32 0, i32 128
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  call void %32(ptr noundef %33)
  br label %34

34:                                               ; preds = %29, %24, %18
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.CPodeMemRec, ptr %35, i32 0, i32 135
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %44

39:                                               ; preds = %34
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.CPodeMemRec, ptr %40, i32 0, i32 135
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  call void %42(ptr noundef %43)
  br label %44

44:                                               ; preds = %39, %34
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.CPodeMemRec, ptr %45, i32 0, i32 150
  %47 = load i32, ptr %46, align 4, !tbaa !17
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %44
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  call void @cpRootFree(ptr noundef %50)
  br label %51

51:                                               ; preds = %49, %44
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.CPodeMemRec, ptr %52, i32 0, i32 149
  %54 = load i32, ptr %53, align 8, !tbaa !18
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %51
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  call void @cpProjFree(ptr noundef %57)
  br label %58

58:                                               ; preds = %56, %51
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  call void @free(ptr noundef %60) #4
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr null, ptr %61, align 8, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %62

62:                                               ; preds = %58, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  %63 = load i32, ptr %4, align 4
  switch i32 %63, label %65 [
    i32 0, label %64
    i32 1, label %64
  ]

64:                                               ; preds = %62, %62
  ret void

65:                                               ; preds = %62
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @cpFreeVectors(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @CPodeQuadFree(ptr noundef) #1

declare void @cpRootFree(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @cpProjFree(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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 = { "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 "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, !12, i64 1584}
!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 = !{!10, !12, i64 44}
!15 = !{!10, !6, i64 1448}
!16 = !{!10, !6, i64 1504}
!17 = !{!10, !12, i64 1596}
!18 = !{!10, !12, i64 1592}


; 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: nounwind uwtable
define dso_local void @CPodeFree(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %30, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %2, i64 1584
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %8, label %7

7:                                                ; preds = %4
  tail call void @cpFreeVectors(ptr noundef nonnull %2)
  br label %8

8:                                                ; preds = %7, %4
  tail call void @CPodeQuadFree(ptr noundef nonnull %2)
  %9 = getelementptr inbounds i8, ptr %2, i64 44
  %10 = load i32, ptr %9, align 4, !tbaa !14
  %11 = icmp eq i32 %10, 2
  br i1 %11, label %12, label %16

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %2, i64 1448
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %.not20 = icmp eq ptr %14, null
  br i1 %.not20, label %16, label %15

15:                                               ; preds = %12
  tail call void %14(ptr noundef nonnull %2) #3
  br label %16

16:                                               ; preds = %15, %12, %8
  %17 = getelementptr inbounds i8, ptr %2, i64 1504
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %.not21 = icmp eq ptr %18, null
  br i1 %.not21, label %20, label %19

19:                                               ; preds = %16
  tail call void %18(ptr noundef nonnull %2) #3
  br label %20

20:                                               ; preds = %19, %16
  %21 = getelementptr inbounds i8, ptr %2, i64 1596
  %22 = load i32, ptr %21, align 4, !tbaa !17
  %.not22 = icmp eq i32 %22, 0
  br i1 %.not22, label %24, label %23

23:                                               ; preds = %20
  tail call void @cpRootFree(ptr noundef nonnull %2) #3
  br label %24

24:                                               ; preds = %23, %20
  %25 = getelementptr inbounds i8, ptr %2, i64 1592
  %26 = load i32, ptr %25, align 8, !tbaa !18
  %.not23 = icmp eq i32 %26, 0
  br i1 %.not23, label %28, label %27

27:                                               ; preds = %24
  tail call void @cpProjFree(ptr noundef nonnull %2)
  br label %28

28:                                               ; preds = %27, %24
  %29 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @free(ptr noundef %29) #3
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %1, %28
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @cpFreeVectors(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @CPodeQuadFree(ptr noundef) local_unnamed_addr #0

declare void @cpRootFree(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @cpProjFree(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { 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 = { "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !12, i64 1584}
!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 = !{!10, !12, i64 44}
!15 = !{!10, !6, i64 1448}
!16 = !{!10, !6, i64 1504}
!17 = !{!10, !12, i64 1596}
!18 = !{!10, !12, i64 1592}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass