; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @r8mat_lt_solve(i32 noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = mul i64 %11, 8
  %13 = call noalias ptr @malloc(i64 noundef %12) #5
  store ptr %13, ptr %9, align 8, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  store i32 %15, ptr %8, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %84, %3
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = icmp sle i32 0, %17
  br i1 %18, label %19, label %87

19:                                               ; preds = %16
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds double, ptr %20, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %9, align 8, !tbaa !9
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds double, ptr %25, i64 %27
  store double %24, ptr %28, align 8, !tbaa !11
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %7, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %61, %19
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %64

35:                                               ; preds = %31
  %36 = load ptr, ptr %9, align 8, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %36, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = load ptr, ptr %9, align 8, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds double, ptr %41, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = mul nsw i32 %48, %49
  %51 = add nsw i32 %47, %50
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %46, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !11
  %55 = fneg double %45
  %56 = call double @llvm.fmuladd.f64(double %55, double %54, double %40)
  %57 = load ptr, ptr %9, align 8, !tbaa !9
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %57, i64 %59
  store double %56, ptr %60, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %35
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %7, align 4, !tbaa !5
  br label %31, !llvm.loop !13

64:                                               ; preds = %31
  %65 = load ptr, ptr %9, align 8, !tbaa !9
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %65, i64 %67
  %69 = load double, ptr %68, align 8, !tbaa !11
  %70 = load ptr, ptr %5, align 8, !tbaa !9
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = mul nsw i32 %72, %73
  %75 = add nsw i32 %71, %74
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds double, ptr %70, i64 %76
  %78 = load double, ptr %77, align 8, !tbaa !11
  %79 = fdiv double %69, %78
  %80 = load ptr, ptr %9, align 8, !tbaa !9
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds double, ptr %80, i64 %82
  store double %79, ptr %83, align 8, !tbaa !11
  br label %84

84:                                               ; preds = %64
  %85 = load i32, ptr %8, align 4, !tbaa !5
  %86 = add nsw i32 %85, -1
  store i32 %86, ptr %8, align 4, !tbaa !5
  br label %16, !llvm.loop !15

87:                                               ; preds = %16
  %88 = load ptr, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret ptr %88
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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 }
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, !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 = !{!"any pointer", !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"

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

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

; Function Attrs: nofree nounwind memory(readwrite, argmem: read) uwtable
define dso_local noalias noundef ptr @r8mat_lt_solve(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #2 {
  %4 = sext i32 %0 to i64
  %5 = shl nsw i64 %4, 3
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #3
  %7 = icmp sgt i32 %0, 0
  br i1 %7, label %.lr.ph37, label %._crit_edge38

.lr.ph37:                                         ; preds = %3
  %8 = add nuw i32 %0, 1
  %9 = zext nneg i32 %0 to i64
  br label %10

10:                                               ; preds = %.lr.ph37, %._crit_edge
  %indvars.iv42 = phi i64 [ %4, %.lr.ph37 ], [ %indvars.iv.next43, %._crit_edge ]
  %indvars.iv = phi i64 [ %9, %.lr.ph37 ], [ %indvars.iv.next, %._crit_edge ]
  %indvars.iv.next43 = add nsw i64 %indvars.iv42, -1
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %11 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next43
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next43
  store double %12, ptr %13, align 8, !tbaa !5
  %14 = icmp slt i64 %indvars.iv42, %4
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %10
  %15 = trunc i64 %indvars.iv.next43 to i32
  %16 = mul i32 %15, %0
  %17 = zext i32 %16 to i64
  %invariant.gep = getelementptr double, ptr %1, i64 %17
  br label %18

18:                                               ; preds = %.lr.ph, %18
  %indvars.iv39 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next40, %18 ]
  %19 = phi double [ %12, %.lr.ph ], [ %24, %18 ]
  %20 = getelementptr inbounds double, ptr %6, i64 %indvars.iv39
  %21 = load double, ptr %20, align 8, !tbaa !5
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv39
  %22 = load double, ptr %gep, align 8, !tbaa !5
  %23 = fneg double %21
  %24 = tail call double @llvm.fmuladd.f64(double %23, double %22, double %19)
  store double %24, ptr %13, align 8, !tbaa !5
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %25 = trunc nuw i64 %indvars.iv.next40 to i32
  %26 = icmp slt i32 %25, %0
  br i1 %26, label %18, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %18, %10
  %27 = phi double [ %12, %10 ], [ %24, %18 ]
  %28 = trunc nuw nsw i64 %indvars.iv.next43 to i32
  %29 = mul i32 %8, %28
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %1, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = fdiv double %27, %32
  store double %33, ptr %13, align 8, !tbaa !5
  %34 = icmp sgt i64 %indvars.iv42, 1
  br i1 %34, label %10, label %._crit_edge38, !llvm.loop !11

._crit_edge38:                                    ; preds = %._crit_edge, %3
  ret ptr %6
}

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


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