; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (r8lib)

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

; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @r8mat_jac(i32 noundef %0, i32 noundef %1, double noundef %2, ptr noundef %3, ptr noundef %4) #4 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca double, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store double %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !11
  store ptr %4, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = load i32, ptr %7, align 4, !tbaa !5
  %20 = mul nsw i32 %18, %19
  %21 = sext i32 %20 to i64
  %22 = mul i64 %21, 8
  %23 = call noalias ptr @malloc(i64 noundef %22) #6
  store ptr %23, ptr %12, align 8, !tbaa !11
  %24 = load ptr, ptr %9, align 8, !tbaa !11
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = load ptr, ptr %10, align 8, !tbaa !11
  %28 = call ptr %24(i32 noundef %25, i32 noundef %26, ptr noundef %27)
  store ptr %28, ptr %17, align 8, !tbaa !11
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %100, %5
  %30 = load i32, ptr %14, align 4, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %103

33:                                               ; preds = %29
  %34 = load ptr, ptr %10, align 8, !tbaa !11
  %35 = load i32, ptr %14, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %34, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !9
  store double %38, ptr %15, align 8, !tbaa !9
  %39 = load double, ptr %8, align 8, !tbaa !9
  %40 = load ptr, ptr %10, align 8, !tbaa !11
  %41 = load i32, ptr %14, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = call double @llvm.fabs.f64(double %44)
  %46 = fadd double 1.000000e+00, %45
  %47 = fmul double %39, %46
  store double %47, ptr %11, align 8, !tbaa !9
  %48 = load ptr, ptr %10, align 8, !tbaa !11
  %49 = load i32, ptr %14, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %48, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = load double, ptr %11, align 8, !tbaa !9
  %54 = fadd double %52, %53
  %55 = load ptr, ptr %10, align 8, !tbaa !11
  %56 = load i32, ptr %14, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %55, i64 %57
  store double %54, ptr %58, align 8, !tbaa !9
  %59 = load ptr, ptr %9, align 8, !tbaa !11
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = load ptr, ptr %10, align 8, !tbaa !11
  %63 = call ptr %59(i32 noundef %60, i32 noundef %61, ptr noundef %62)
  store ptr %63, ptr %16, align 8, !tbaa !11
  %64 = load double, ptr %15, align 8, !tbaa !9
  %65 = load ptr, ptr %10, align 8, !tbaa !11
  %66 = load i32, ptr %14, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %65, i64 %67
  store double %64, ptr %68, align 8, !tbaa !9
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %95, %33
  %70 = load i32, ptr %13, align 4, !tbaa !5
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = icmp slt i32 %70, %71
  br i1 %72, label %73, label %98

73:                                               ; preds = %69
  %74 = load ptr, ptr %16, align 8, !tbaa !11
  %75 = load i32, ptr %13, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds double, ptr %74, i64 %76
  %78 = load double, ptr %77, align 8, !tbaa !9
  %79 = load ptr, ptr %17, align 8, !tbaa !11
  %80 = load i32, ptr %13, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds double, ptr %79, i64 %81
  %83 = load double, ptr %82, align 8, !tbaa !9
  %84 = fsub double %78, %83
  %85 = load double, ptr %11, align 8, !tbaa !9
  %86 = fdiv double %84, %85
  %87 = load ptr, ptr %12, align 8, !tbaa !11
  %88 = load i32, ptr %13, align 4, !tbaa !5
  %89 = load i32, ptr %14, align 4, !tbaa !5
  %90 = load i32, ptr %6, align 4, !tbaa !5
  %91 = mul nsw i32 %89, %90
  %92 = add nsw i32 %88, %91
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds double, ptr %87, i64 %93
  store double %86, ptr %94, align 8, !tbaa !9
  br label %95

95:                                               ; preds = %73
  %96 = load i32, ptr %13, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %13, align 4, !tbaa !5
  br label %69, !llvm.loop !13

98:                                               ; preds = %69
  %99 = load ptr, ptr %16, align 8, !tbaa !11
  call void @free(ptr noundef %99) #5
  br label %100

100:                                              ; preds = %98
  %101 = load i32, ptr %14, align 4, !tbaa !5
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %14, align 4, !tbaa !5
  br label %29, !llvm.loop !15

103:                                              ; preds = %29
  %104 = load ptr, ptr %17, align 8, !tbaa !11
  call void @free(ptr noundef %104) #5
  %105 = load ptr, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret ptr %105
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !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"

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @r8mat_jac(i32 noundef %0, i32 noundef %1, double noundef %2, ptr nocapture noundef readonly %3, ptr noundef %4) local_unnamed_addr #3 {
  %6 = mul nsw i32 %1, %0
  %7 = sext i32 %6 to i64
  %8 = shl nsw i64 %7, 3
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #4
  %10 = tail call ptr %3(i32 noundef %0, i32 noundef %1, ptr noundef %4) #5
  %11 = icmp sgt i32 %1, 0
  br i1 %11, label %.lr.ph46, label %._crit_edge47

.lr.ph46:                                         ; preds = %5
  %12 = icmp sgt i32 %0, 0
  br i1 %12, label %.lr.ph.us.preheader, label %.lr.ph46.split.preheader

.lr.ph46.split.preheader:                         ; preds = %.lr.ph46
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph46.split

.lr.ph.us.preheader:                              ; preds = %.lr.ph46
  %13 = zext nneg i32 %0 to i64
  %wide.trip.count58 = zext nneg i32 %1 to i64
  %min.iters.check = icmp eq i32 %0, 1
  %n.vec = and i64 %13, 2147483646
  %cmp.n = icmp eq i64 %n.vec, %13
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv55 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next56, %._crit_edge.us ]
  %14 = getelementptr inbounds double, ptr %4, i64 %indvars.iv55
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = tail call double @llvm.fabs.f64(double %15)
  %17 = fadd double %16, 1.000000e+00
  %18 = fmul double %17, %2
  %19 = fadd double %15, %18
  store double %19, ptr %14, align 8, !tbaa !5
  %20 = tail call ptr %3(i32 noundef %0, i32 noundef %1, ptr noundef %4) #5
  store double %15, ptr %14, align 8, !tbaa !5
  %21 = mul nuw nsw i64 %indvars.iv55, %13
  %invariant.gep = getelementptr inbounds double, ptr %9, i64 %21
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us
  %broadcast.splatinsert = insertelement <2 x double> poison, double %18, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %22 = getelementptr inbounds double, ptr %20, i64 %index
  %wide.load = load <2 x double>, ptr %22, align 8, !tbaa !5
  %23 = getelementptr inbounds double, ptr %10, i64 %index
  %wide.load62 = load <2 x double>, ptr %23, align 8, !tbaa !5
  %24 = fsub <2 x double> %wide.load, %wide.load62
  %25 = fdiv <2 x double> %24, %broadcast.splat
  %26 = getelementptr inbounds double, ptr %invariant.gep, i64 %index
  store <2 x double> %25, ptr %26, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 2
  %27 = icmp eq i64 %index.next, %n.vec
  br i1 %27, label %middle.block, label %vector.body, !llvm.loop !9

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

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph.us
  %indvars.iv50.ph = phi i64 [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv50 = phi i64 [ %indvars.iv.next51, %scalar.ph ], [ %indvars.iv50.ph, %scalar.ph.preheader ]
  %28 = getelementptr inbounds double, ptr %20, i64 %indvars.iv50
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %10, i64 %indvars.iv50
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = fsub double %29, %31
  %33 = fdiv double %32, %18
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv50
  store double %33, ptr %gep, align 8, !tbaa !5
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %exitcond54.not = icmp eq i64 %indvars.iv.next51, %13
  br i1 %exitcond54.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !13

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  tail call void @free(ptr noundef nonnull %20) #5
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %exitcond59.not = icmp eq i64 %indvars.iv.next56, %wide.trip.count58
  br i1 %exitcond59.not, label %._crit_edge47, label %.lr.ph.us, !llvm.loop !14

.lr.ph46.split:                                   ; preds = %.lr.ph46.split.preheader, %.lr.ph46.split
  %indvars.iv = phi i64 [ 0, %.lr.ph46.split.preheader ], [ %indvars.iv.next, %.lr.ph46.split ]
  %34 = getelementptr inbounds double, ptr %4, i64 %indvars.iv
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = tail call double @llvm.fabs.f64(double %35)
  %37 = fadd double %36, 1.000000e+00
  %38 = fmul double %37, %2
  %39 = fadd double %35, %38
  store double %39, ptr %34, align 8, !tbaa !5
  %40 = tail call ptr %3(i32 noundef %0, i32 noundef %1, ptr noundef %4) #5
  store double %35, ptr %34, align 8, !tbaa !5
  tail call void @free(ptr noundef %40) #5
  %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_edge47, label %.lr.ph46.split, !llvm.loop !14

._crit_edge47:                                    ; preds = %.lr.ph46.split, %._crit_edge.us, %5
  tail call void @free(ptr noundef %10) #5
  ret ptr %9
}

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 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) }
attributes #5 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !10}


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