; LLVM IR from opensim-org/opensim-core :: OpenSim/Common/Lmdif.ll (Z6fdjac2PFviiPdS_PiPvEiiS_S_S_iS0_dS_S1_)

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

@JACOBIAN = external dso_local global i32, align 4

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6fdjac2PFviiPdS_PiPvEiiS_S_S_iS0_dS_S1_(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i32 noundef %6, ptr noundef %7, double noundef %8, ptr noundef %9, ptr noundef %10) #1 {
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca double, align 8
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  %25 = alloca i32, align 4
  %26 = alloca double, align 8
  %27 = alloca double, align 8
  %28 = alloca double, align 8
  %29 = alloca i32, align 4
  store ptr %0, ptr %12, align 8, !tbaa !5
  store i32 %1, ptr %13, align 4, !tbaa !9
  store i32 %2, ptr %14, align 4, !tbaa !9
  store ptr %3, ptr %15, align 8, !tbaa !5
  store ptr %4, ptr %16, align 8, !tbaa !5
  store ptr %5, ptr %17, align 8, !tbaa !5
  store i32 %6, ptr %18, align 4, !tbaa !9
  store ptr %7, ptr %19, align 8, !tbaa !5
  store double %8, ptr %20, align 8, !tbaa !11
  store ptr %9, ptr %21, align 8, !tbaa !5
  store ptr %10, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %28) #2
  store i32 1, ptr @JACOBIAN, align 4, !tbaa !9
  store double 1.000000e-05, ptr %26, align 8, !tbaa !11
  store i32 0, ptr %25, align 4, !tbaa !9
  store i32 0, ptr %24, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %93, %11
  %31 = load i32, ptr %24, align 4, !tbaa !9
  %32 = load i32, ptr %14, align 4, !tbaa !9
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %96

34:                                               ; preds = %30
  %35 = load ptr, ptr %15, align 8, !tbaa !5
  %36 = load i32, ptr %24, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  store double %39, ptr %28, align 8, !tbaa !11
  %40 = load double, ptr %26, align 8, !tbaa !11
  store double %40, ptr %27, align 8, !tbaa !11
  %41 = load double, ptr %28, align 8, !tbaa !11
  %42 = load double, ptr %27, align 8, !tbaa !11
  %43 = fadd double %41, %42
  %44 = load ptr, ptr %15, align 8, !tbaa !5
  %45 = load i32, ptr %24, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %44, i64 %46
  store double %43, ptr %47, align 8, !tbaa !11
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = load i32, ptr %14, align 4, !tbaa !9
  %51 = load ptr, ptr %15, align 8, !tbaa !5
  %52 = load ptr, ptr %21, align 8, !tbaa !5
  %53 = load ptr, ptr %19, align 8, !tbaa !5
  %54 = load ptr, ptr %22, align 8, !tbaa !5
  call void %48(i32 noundef %49, i32 noundef %50, ptr noundef %51, ptr noundef %52, ptr noundef %53, ptr noundef %54)
  %55 = load double, ptr %28, align 8, !tbaa !11
  %56 = load ptr, ptr %15, align 8, !tbaa !5
  %57 = load i32, ptr %24, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %56, i64 %58
  store double %55, ptr %59, align 8, !tbaa !11
  %60 = load ptr, ptr %19, align 8, !tbaa !5
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = icmp slt i32 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %34
  store i32 1, ptr %29, align 4
  br label %97

64:                                               ; preds = %34
  store i32 0, ptr %23, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %89, %64
  %66 = load i32, ptr %23, align 4, !tbaa !9
  %67 = load i32, ptr %13, align 4, !tbaa !9
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %69, label %92

69:                                               ; preds = %65
  %70 = load ptr, ptr %21, align 8, !tbaa !5
  %71 = load i32, ptr %23, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds double, ptr %70, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !11
  %75 = load ptr, ptr %16, align 8, !tbaa !5
  %76 = load i32, ptr %23, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds double, ptr %75, i64 %77
  %79 = load double, ptr %78, align 8, !tbaa !11
  %80 = fsub double %74, %79
  %81 = load double, ptr %27, align 8, !tbaa !11
  %82 = fdiv double %80, %81
  %83 = load ptr, ptr %17, align 8, !tbaa !5
  %84 = load i32, ptr %25, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds double, ptr %83, i64 %85
  store double %82, ptr %86, align 8, !tbaa !11
  %87 = load i32, ptr %25, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %25, align 4, !tbaa !9
  br label %89

89:                                               ; preds = %69
  %90 = load i32, ptr %23, align 4, !tbaa !9
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %23, align 4, !tbaa !9
  br label %65, !llvm.loop !13

92:                                               ; preds = %65
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %24, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %24, align 4, !tbaa !9
  br label %30, !llvm.loop !15

96:                                               ; preds = %30
  store i32 0, ptr @JACOBIAN, align 4, !tbaa !9
  store i32 0, ptr %29, align 4
  br label %97

97:                                               ; preds = %96, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #2
  %98 = load i32, ptr %29, align 4
  switch i32 %98, label %100 [
    i32 0, label %99
    i32 1, label %99
  ]

99:                                               ; preds = %97, %97
  ret void

100:                                              ; preds = %97
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@JACOBIAN = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6fdjac2PFviiPdS_PiPvEiiS_S_S_iS0_dS_S1_(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr nocapture noundef readonly %4, ptr nocapture noundef writeonly %5, i32 noundef %6, ptr noundef %7, double noundef %8, ptr noundef %9, ptr noundef %10) local_unnamed_addr #0 {
  %12 = ptrtoint ptr %4 to i64
  %13 = ptrtoint ptr %9 to i64
  %14 = ptrtoint ptr %5 to i64
  store i32 1, ptr @JACOBIAN, align 4, !tbaa !5
  %15 = icmp sgt i32 %2, 0
  br i1 %15, label %.lr.ph39, label %._crit_edge40

.lr.ph39:                                         ; preds = %11
  %16 = icmp sgt i32 %1, 0
  %wide.trip.count56 = zext nneg i32 %2 to i64
  br i1 %16, label %.lr.ph39.split.us.preheader, label %.lr.ph39.split

.lr.ph39.split.us.preheader:                      ; preds = %.lr.ph39
  %wide.trip.count51 = zext nneg i32 %1 to i64
  %17 = sub i64 %14, %13
  %18 = sub i64 %14, %12
  %min.iters.check = icmp eq i32 %1, 1
  %n.vec = and i64 %wide.trip.count51, 2147483646
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count51
  %xtraiter = and i64 %wide.trip.count51, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %19 = add nsw i64 %wide.trip.count51, -1
  %invariant.gep = getelementptr i8, ptr %5, i64 8
  br label %.lr.ph39.split.us

.lr.ph39.split.us:                                ; preds = %.lr.ph39.split.us.preheader, %._crit_edge.us
  %indvars.iv53 = phi i64 [ 0, %.lr.ph39.split.us.preheader ], [ %indvars.iv.next54, %._crit_edge.us ]
  %.03236.us = phi i64 [ 0, %.lr.ph39.split.us.preheader ], [ %indvars.iv.next47.lcssa, %._crit_edge.us ]
  %20 = getelementptr inbounds double, ptr %3, i64 %indvars.iv53
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fadd double %21, 1.000000e-05
  store double %22, ptr %20, align 8, !tbaa !9
  tail call void %0(i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %9, ptr noundef %7, ptr noundef %10)
  store double %21, ptr %20, align 8, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %.loopexit, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.lr.ph39.split.us
  %sext = shl i64 %.03236.us, 32
  %25 = ashr exact i64 %sext, 32
  br i1 %min.iters.check, label %.preheader.us.preheader65, label %vector.memcheck

vector.memcheck:                                  ; preds = %.preheader.us.preheader
  %26 = ashr exact i64 %sext, 29
  %27 = add i64 %17, %26
  %diff.check = icmp ult i64 %27, 16
  %28 = add i64 %18, %26
  %diff.check62 = icmp ult i64 %28, 16
  %conflict.rdx = or i1 %diff.check, %diff.check62
  br i1 %conflict.rdx, label %.preheader.us.preheader65, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %ind.end = add nsw i64 %25, %n.vec
  %29 = getelementptr double, ptr %5, i64 %25
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %30 = getelementptr inbounds double, ptr %9, i64 %index
  %wide.load = load <2 x double>, ptr %30, align 8, !tbaa !9
  %31 = getelementptr inbounds double, ptr %4, i64 %index
  %wide.load64 = load <2 x double>, ptr %31, align 8, !tbaa !9
  %32 = fsub <2 x double> %wide.load, %wide.load64
  %33 = fdiv <2 x double> %32, <double 1.000000e-05, double 1.000000e-05>
  %34 = getelementptr double, ptr %29, i64 %index
  store <2 x double> %33, ptr %34, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 2
  %35 = icmp eq i64 %index.next, %n.vec
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %.preheader.us.preheader65

.preheader.us.preheader65:                        ; preds = %middle.block, %vector.memcheck, %.preheader.us.preheader
  %indvars.iv46.ph = phi i64 [ %25, %vector.memcheck ], [ %25, %.preheader.us.preheader ], [ %ind.end, %middle.block ]
  %indvars.iv44.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.preheader.us.preheader ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %.preheader.us.prol.loopexit, label %.preheader.us.prol

.preheader.us.prol:                               ; preds = %.preheader.us.preheader65
  %36 = getelementptr inbounds double, ptr %9, i64 %indvars.iv44.ph
  %37 = load double, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds double, ptr %4, i64 %indvars.iv44.ph
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = fsub double %37, %39
  %41 = fdiv double %40, 1.000000e-05
  %42 = getelementptr inbounds double, ptr %5, i64 %indvars.iv46.ph
  store double %41, ptr %42, align 8, !tbaa !9
  %indvars.iv.next47.prol = add nsw i64 %indvars.iv46.ph, 1
  %indvars.iv.next45.prol = or disjoint i64 %indvars.iv44.ph, 1
  br label %.preheader.us.prol.loopexit

.preheader.us.prol.loopexit:                      ; preds = %.preheader.us.prol, %.preheader.us.preheader65
  %indvars.iv.next47.lcssa66.unr = phi i64 [ poison, %.preheader.us.preheader65 ], [ %indvars.iv.next47.prol, %.preheader.us.prol ]
  %indvars.iv46.unr = phi i64 [ %indvars.iv46.ph, %.preheader.us.preheader65 ], [ %indvars.iv.next47.prol, %.preheader.us.prol ]
  %indvars.iv44.unr = phi i64 [ %indvars.iv44.ph, %.preheader.us.preheader65 ], [ %indvars.iv.next45.prol, %.preheader.us.prol ]
  %43 = icmp eq i64 %indvars.iv44.ph, %19
  br i1 %43, label %._crit_edge.us, label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.prol.loopexit, %.preheader.us
  %indvars.iv46 = phi i64 [ %indvars.iv.next47.1, %.preheader.us ], [ %indvars.iv46.unr, %.preheader.us.prol.loopexit ]
  %indvars.iv44 = phi i64 [ %indvars.iv.next45.1, %.preheader.us ], [ %indvars.iv44.unr, %.preheader.us.prol.loopexit ]
  %44 = getelementptr inbounds double, ptr %9, i64 %indvars.iv44
  %45 = load double, ptr %44, align 8, !tbaa !9
  %46 = getelementptr inbounds double, ptr %4, i64 %indvars.iv44
  %47 = load double, ptr %46, align 8, !tbaa !9
  %48 = fsub double %45, %47
  %49 = fdiv double %48, 1.000000e-05
  %50 = getelementptr inbounds double, ptr %5, i64 %indvars.iv46
  store double %49, ptr %50, align 8, !tbaa !9
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %51 = getelementptr inbounds double, ptr %9, i64 %indvars.iv.next45
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = getelementptr inbounds double, ptr %4, i64 %indvars.iv.next45
  %54 = load double, ptr %53, align 8, !tbaa !9
  %55 = fsub double %52, %54
  %56 = fdiv double %55, 1.000000e-05
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv46
  store double %56, ptr %gep, align 8, !tbaa !9
  %indvars.iv.next47.1 = add nsw i64 %indvars.iv46, 2
  %indvars.iv.next45.1 = add nuw nsw i64 %indvars.iv44, 2
  %exitcond52.not.1 = icmp eq i64 %indvars.iv.next45.1, %wide.trip.count51
  br i1 %exitcond52.not.1, label %._crit_edge.us, label %.preheader.us, !llvm.loop !15

._crit_edge.us:                                   ; preds = %.preheader.us.prol.loopexit, %.preheader.us, %middle.block
  %indvars.iv.next47.lcssa = phi i64 [ %ind.end, %middle.block ], [ %indvars.iv.next47.lcssa66.unr, %.preheader.us.prol.loopexit ], [ %indvars.iv.next47.1, %.preheader.us ]
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %exitcond57.not = icmp eq i64 %indvars.iv.next54, %wide.trip.count56
  br i1 %exitcond57.not, label %._crit_edge40, label %.lr.ph39.split.us, !llvm.loop !16

.lr.ph39.split:                                   ; preds = %.lr.ph39, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader ], [ 0, %.lr.ph39 ]
  %57 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  %58 = load double, ptr %57, align 8, !tbaa !9
  %59 = fadd double %58, 1.000000e-05
  store double %59, ptr %57, align 8, !tbaa !9
  tail call void %0(i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %9, ptr noundef %7, ptr noundef %10)
  store double %58, ptr %57, align 8, !tbaa !9
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = icmp slt i32 %60, 0
  br i1 %61, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.lr.ph39.split
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count56
  br i1 %exitcond.not, label %._crit_edge40, label %.lr.ph39.split, !llvm.loop !16

._crit_edge40:                                    ; preds = %.preheader, %._crit_edge.us, %11
  store i32 0, ptr @JACOBIAN, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph39.split, %.lr.ph39.split.us, %._crit_edge40
  ret void
}

attributes #0 = { mustprogress 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" }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !13}
!16 = distinct !{!16, !12}


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