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

@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [32 x i8], align 1

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

declare void @nus_vector_print(ptr noundef byval(%struct.NUS_vector) align 8) #1

; Function Attrs: nounwind uwtable
define dso_local void @nus_kinematic_property_print(ptr noundef byval(%struct.NUS_kinematic_property) align 8 %0) #2 {
  %2 = alloca i32, align 4
  %3 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %0, i32 0, i32 2
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %4)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !13
  br label %6

6:                                                ; preds = %27, %1
  %7 = load i32, ptr %2, align 4, !tbaa !13
  %8 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %0, i32 0, i32 2
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = icmp ult i32 %7, %9
  br i1 %10, label %11, label %30

11:                                               ; preds = %6
  %12 = load i32, ptr %2, align 4, !tbaa !13
  %13 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %0, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = load i32, ptr %2, align 4, !tbaa !13
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %14, i64 %16
  %18 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %12, i32 noundef %19)
  %21 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %0, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = load i32, ptr %2, align 4, !tbaa !13
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %22, i64 %24
  %26 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %25, i32 0, i32 0
  call void @nus_vector_print(ptr noundef byval(%struct.NUS_vector) align 8 %26)
  br label %27

27:                                               ; preds = %11
  %28 = load i32, ptr %2, align 4, !tbaa !13
  %29 = add i32 %28, 1
  store i32 %29, ptr %2, align 4, !tbaa !13
  br label %6, !llvm.loop !17

30:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #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, !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 = !{!12, !12, i64 0}
!14 = !{!6, !7, i64 0}
!15 = !{!16, !12, i64 24}
!16 = !{!"NUS_kinematic_factor", !10, i64 0, !12, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"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.NUS_vector = type { double, double, double }
%struct.NUS_kinematic_property = type { ptr, %struct.NUS_vector, i32 }
%struct.NUS_kinematic_factor = type { %struct.NUS_vector, i32 }

@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [32 x i8], align 1

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

declare void @nus_vector_print(ptr noundef byval(%struct.NUS_vector) align 8) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @nus_kinematic_property_print(ptr nocapture noundef readonly byval(%struct.NUS_kinematic_property) align 8 %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %3)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !13
  %wide.trip.count = zext i32 %3 to i64
  br label %6

6:                                                ; preds = %.lr.ph, %6
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %6 ]
  %7 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %5, i64 %indvars.iv, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !14
  %9 = trunc nuw i64 %indvars.iv to i32
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %9, i32 noundef %8)
  %11 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %5, i64 %indvars.iv
  tail call void @nus_vector_print(ptr noundef byval(%struct.NUS_vector) align 8 %11) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %6, !llvm.loop !16

._crit_edge:                                      ; preds = %6, %1
  ret void
}

attributes #0 = { 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 #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, !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 = !{!15, !12, i64 24}
!15 = !{!"NUS_kinematic_factor", !10, i64 0, !12, i64 24}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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