; LLVM IR from PyCee/NUS_library :: src/physics (NUS_kinematic_property)

; 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.NUS_kinematic_property = type { ptr, %struct.NUS_vector, i32 }
%struct.NUS_vector = type { double, double, double }
%struct.NUS_kinematic_factor = type { %struct.NUS_vector, i32 }

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

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nounwind uwtable
declare hidden i32 @nus_kinematic_property_get_factor_index(ptr noundef byval(%struct.NUS_kinematic_property) align 8, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @nus_kinematic_property_remove(ptr noundef %0, i32 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %8, i32 0, i32 2
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %20

12:                                               ; preds = %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %13, i32 0, i32 2
  store i32 0, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  call void @free(ptr noundef %17) #5
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %18, i32 0, i32 0
  store ptr null, ptr %19, align 8, !tbaa !15
  br label %20

20:                                               ; preds = %12, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = call i32 @nus_kinematic_property_get_factor_index(ptr noundef byval(%struct.NUS_kinematic_property) align 8 %21, i32 noundef %22)
  store i32 %23, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = zext i32 %26 to i64
  %28 = mul i64 32, %27
  %29 = call noalias ptr @malloc(i64 noundef %28) #6
  store ptr %29, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %45, %20
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = icmp ult i32 %31, %32
  br i1 %33, label %34, label %48

34:                                               ; preds = %30
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %35, i64 %37
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %41, i64 %43
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %38, ptr align 8 %44, i64 32, i1 false), !tbaa.struct !16
  br label %45

45:                                               ; preds = %34
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = add i32 %46, 1
  store i32 %47, ptr %7, align 4, !tbaa !9
  br label %30, !llvm.loop !18

48:                                               ; preds = %30
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = add i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %69, %48
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !11
  %56 = icmp ult i32 %52, %55
  br i1 %56, label %57, label %72

57:                                               ; preds = %51
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = sub i32 %59, 1
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %58, i64 %61
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !15
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %65, i64 %67
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %62, ptr align 8 %68, i64 32, i1 false), !tbaa.struct !16
  br label %69

69:                                               ; preds = %57
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = add i32 %70, 1
  store i32 %71, ptr %7, align 4, !tbaa !9
  br label %51, !llvm.loop !20

72:                                               ; preds = %51
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !15
  call void @free(ptr noundef %75) #5
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %77, i32 0, i32 0
  store ptr %76, ptr %78, align 8, !tbaa !15
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %79, i32 0, i32 2
  %81 = load i32, ptr %80, align 8, !tbaa !11
  %82 = add i32 %81, -1
  store i32 %82, ptr %80, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret void
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 allocsize(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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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, !10, i64 32}
!12 = !{!"NUS_kinematic_property", !6, i64 0, !13, i64 8, !10, i64 32}
!13 = !{!"NUS_vector", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !6, i64 0}
!16 = !{i64 0, i64 8, !17, i64 8, i64 8, !17, i64 16, i64 8, !17, i64 24, i64 4, !9}
!17 = !{!14, !14, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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.NUS_kinematic_property = type { ptr, %struct.NUS_vector, i32 }
%struct.NUS_vector = type { double, double, double }
%struct.NUS_kinematic_factor = type { %struct.NUS_vector, i32 }

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @nus_kinematic_property_get_factor_index(ptr noundef byval(%struct.NUS_kinematic_property) align 8, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @nus_kinematic_property_remove(ptr noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  store i32 0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %0, align 8, !tbaa !13
  tail call void @free(ptr noundef %7) #4
  store ptr null, ptr %0, align 8, !tbaa !13
  br label %8

8:                                                ; preds = %6, %2
  %9 = tail call i32 @nus_kinematic_property_get_factor_index(ptr noundef nonnull byval(%struct.NUS_kinematic_property) align 8 %0, i32 noundef %1)
  %10 = load i32, ptr %3, align 8, !tbaa !5
  %11 = zext i32 %10 to i64
  %12 = shl nuw nsw i64 %11, 5
  %13 = tail call noalias ptr @malloc(i64 noundef %12) #5
  %.not = icmp eq i32 %9, 0
  %.pre.pre = load ptr, ptr %0, align 8, !tbaa !13
  br i1 %.not, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %wide.trip.count = zext i32 %9 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %14 = icmp eq i32 %9, 1
  br i1 %14, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %26

.preheader.loopexit.unr-lcssa:                    ; preds = %26, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %26 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.preheader.loopexit.epilog-lcssa

.preheader.loopexit.epilog-lcssa:                 ; preds = %.preheader.loopexit.unr-lcssa
  %15 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %13, i64 %indvars.iv.unr
  %16 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %.pre.pre, i64 %indvars.iv.unr
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %15, ptr noundef nonnull align 8 dereferenceable(32) %16, i64 32, i1 false), !tbaa.struct !14
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit.epilog-lcssa, %.preheader.loopexit.unr-lcssa, %8
  %.126 = add i32 %9, 1
  %17 = icmp ult i32 %.126, %10
  br i1 %17, label %.lr.ph29, label %._crit_edge

.lr.ph29:                                         ; preds = %.preheader
  %18 = zext i32 %.126 to i64
  %19 = add i32 %10, -2
  %20 = sub i32 %9, %10
  %21 = and i32 %20, 1
  %lcmp.mod36.not.not = icmp eq i32 %21, 0
  br i1 %lcmp.mod36.not.not, label %.prol.loopexit.unr-lcssa, label %.prol.loopexit

.prol.loopexit.unr-lcssa:                         ; preds = %.lr.ph29
  %22 = zext i32 %9 to i64
  %23 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %13, i64 %22
  %24 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %.pre.pre, i64 %18
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %23, ptr noundef nonnull align 8 dereferenceable(32) %24, i64 32, i1 false), !tbaa.struct !14
  %indvars.iv.next32.prol = add nuw nsw i64 %18, 1
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph29
  %indvars.iv31.unr = phi i64 [ %18, %.lr.ph29 ], [ %indvars.iv.next32.prol, %.prol.loopexit.unr-lcssa ]
  %.1.in27.unr = phi i32 [ %9, %.lr.ph29 ], [ %.126, %.prol.loopexit.unr-lcssa ]
  %25 = icmp eq i32 %19, %9
  br i1 %25, label %._crit_edge, label %.lr.ph29.new

26:                                               ; preds = %26, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %26 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %26 ]
  %27 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %13, i64 %indvars.iv
  %28 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %.pre.pre, i64 %indvars.iv
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %27, ptr noundef nonnull align 8 dereferenceable(32) %28, i64 32, i1 false), !tbaa.struct !14
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %29 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %13, i64 %indvars.iv.next
  %30 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %.pre.pre, i64 %indvars.iv.next
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %29, ptr noundef nonnull align 8 dereferenceable(32) %30, i64 32, i1 false), !tbaa.struct !14
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.loopexit.unr-lcssa, label %26, !llvm.loop !17

.lr.ph29.new:                                     ; preds = %.prol.loopexit, %.lr.ph29.new
  %indvars.iv31 = phi i64 [ %indvars.iv.next32.1, %.lr.ph29.new ], [ %indvars.iv31.unr, %.prol.loopexit ]
  %.1.in27 = phi i32 [ %37, %.lr.ph29.new ], [ %.1.in27.unr, %.prol.loopexit ]
  %31 = zext i32 %.1.in27 to i64
  %32 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %13, i64 %31
  %33 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %.pre.pre, i64 %indvars.iv31
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %32, ptr noundef nonnull align 8 dereferenceable(32) %33, i64 32, i1 false), !tbaa.struct !14
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %34 = and i64 %indvars.iv31, 4294967295
  %35 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %13, i64 %34
  %36 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %.pre.pre, i64 %indvars.iv.next32
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %35, ptr noundef nonnull align 8 dereferenceable(32) %36, i64 32, i1 false), !tbaa.struct !14
  %indvars.iv.next32.1 = add nuw nsw i64 %indvars.iv31, 2
  %37 = trunc nuw i64 %indvars.iv.next32 to i32
  %lftr.wideiv.1 = trunc i64 %indvars.iv.next32.1 to i32
  %exitcond34.not.1 = icmp eq i32 %10, %lftr.wideiv.1
  br i1 %exitcond34.not.1, label %._crit_edge, label %.lr.ph29.new, !llvm.loop !19

._crit_edge:                                      ; preds = %.prol.loopexit, %.lr.ph29.new, %.preheader
  tail call void @free(ptr noundef %.pre.pre) #4
  store ptr %13, ptr %0, align 8, !tbaa !13
  %38 = load i32, ptr %3, align 8, !tbaa !5
  %39 = add i32 %38, -1
  store i32 %39, ptr %3, align 8, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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, !12, i64 32}
!6 = !{!"NUS_kinematic_property", !7, i64 0, !10, i64 8, !12, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"NUS_vector", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"double", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{i64 0, i64 8, !15, i64 8, i64 8, !15, i64 16, i64 8, !15, i64 24, i64 4, !16}
!15 = !{!11, !11, i64 0}
!16 = !{!12, !12, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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