; 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_u_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 %7, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %84, %3
  %17 = load i32, ptr %7, 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 %7, 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 %7, 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 %7, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %8, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %61, %19
  %32 = load i32, ptr %8, 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 %7, 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 %5, align 8, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = mul nsw i32 %43, %44
  %46 = add nsw i32 %42, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %41, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = load ptr, ptr %9, align 8, !tbaa !9
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !11
  %55 = fneg double %49
  %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 %7, 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 %8, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %8, 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 %7, 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 %7, align 4, !tbaa !5
  %72 = load i32, ptr %7, 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 %7, 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 %7, align 4, !tbaa !5
  %86 = add nsw i32 %85, -1
  store i32 %86, ptr %7, 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_u_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
  %15 = trunc nuw nsw i64 %indvars.iv.next43 to i32
  br i1 %14, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %.lr.ph, %10
  %29 = phi double [ %12, %10 ], [ %26, %.lr.ph ]
  %30 = mul i32 %8, %15
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %1, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fdiv double %29, %33
  store double %34, ptr %13, align 8, !tbaa !5
  %35 = icmp sgt i64 %indvars.iv42, 1
  br i1 %35, 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,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass