; LLVM IR from tsotchke/quantum_geometric_tensor :: src/quantum_geometric/core (numerical_backend_cpu)

; 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.anon = type { %struct.numerical_config_t, %struct.numerical_metrics_t, i32, i8, i8 }
%struct.numerical_config_t = type { i32, i64, i8, i8, i8, i64, ptr }
%struct.numerical_metrics_t = type { double, double, double, double, i64 }

@backend_state = external hidden global %struct.anon, align 8

; 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 uwtable
define dso_local zeroext i1 @numerical_solve_triangular(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, i1 noundef zeroext %5, i1 noundef zeroext %6) #1 {
  %8 = alloca i1, align 1
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i8, align 1
  %15 = alloca i8, align 1
  %16 = alloca i8, align 1
  %17 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i64 %3, ptr %12, align 8, !tbaa !9
  store i64 %4, ptr %13, align 8, !tbaa !9
  %18 = zext i1 %5 to i8
  store i8 %18, ptr %14, align 1, !tbaa !11
  %19 = zext i1 %6 to i8
  store i8 %19, ptr %15, align 1, !tbaa !11
  %20 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 3), align 4, !tbaa !13, !range !19, !noundef !20
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %31

22:                                               ; preds = %7
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %31

25:                                               ; preds = %22
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %28, %25, %22, %7
  store i32 1, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 2), align 8, !tbaa !21
  store i1 false, ptr %8, align 1
  br label %53

32:                                               ; preds = %28
  %33 = load i8, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 4), align 1, !tbaa !22, !range !19, !noundef !20
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %52

35:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 1, ptr %16) #3
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load i64, ptr %12, align 8, !tbaa !9
  %40 = load i64, ptr %13, align 8, !tbaa !9
  %41 = load i8, ptr %14, align 1, !tbaa !11, !range !19, !noundef !20
  %42 = trunc i8 %41 to i1
  %43 = load i8, ptr %15, align 1, !tbaa !11, !range !19, !noundef !20
  %44 = trunc i8 %43 to i1
  %45 = call zeroext i1 @lapack_solve_triangular(ptr noundef %36, ptr noundef %37, ptr noundef %38, i64 noundef %39, i64 noundef %40, i1 noundef zeroext %42, i1 noundef zeroext %44, i32 noundef 101)
  %46 = zext i1 %45 to i8
  store i8 %46, ptr %16, align 1, !tbaa !11
  %47 = load i8, ptr %16, align 1, !tbaa !11, !range !19, !noundef !20
  %48 = trunc i8 %47 to i1
  br i1 %48, label %50, label %49

49:                                               ; preds = %35
  store i32 4, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 2), align 8, !tbaa !21
  store i1 false, ptr %8, align 1
  store i32 1, ptr %17, align 4
  br label %51

50:                                               ; preds = %35
  store i1 true, ptr %8, align 1
  store i32 1, ptr %17, align 4
  br label %51

51:                                               ; preds = %50, %49
  call void @llvm.lifetime.end.p0(i64 1, ptr %16) #3
  br label %53

52:                                               ; preds = %32
  store i32 5, ptr getelementptr inbounds (%struct.anon, ptr @backend_state, i32 0, i32 2), align 8, !tbaa !21
  store i1 false, ptr %8, align 1
  br label %53

53:                                               ; preds = %52, %51, %31
  %54 = load i1, ptr %8, align 1
  ret i1 %54
}

declare zeroext i1 @lapack_solve_triangular(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef, i1 noundef zeroext, i1 noundef zeroext, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !12, i64 84}
!14 = !{!"", !15, i64 0, !17, i64 40, !16, i64 80, !12, i64 84, !12, i64 85}
!15 = !{!"", !16, i64 0, !10, i64 8, !12, i64 16, !12, i64 17, !12, i64 18, !10, i64 24, !6, i64 32}
!16 = !{!"int", !7, i64 0}
!17 = !{!"", !18, i64 0, !18, i64 8, !18, i64 16, !18, i64 24, !10, i64 32}
!18 = !{!"double", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!14, !16, i64 80}
!22 = !{!14, !12, i64 85}


; 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.anon = type { %struct.numerical_config_t, %struct.numerical_metrics_t, i32, i8, i8 }
%struct.numerical_config_t = type { i32, i64, i8, i8, i8, i64, ptr }
%struct.numerical_metrics_t = type { double, double, double, double, i64 }

@backend_state = external hidden local_unnamed_addr global %struct.anon, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @numerical_solve_triangular(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, i1 noundef zeroext %5, i1 noundef zeroext %6) local_unnamed_addr #0 {
  %8 = load i8, ptr getelementptr inbounds (i8, ptr @backend_state, i64 84), align 4, !tbaa !5, !range !16, !noundef !17
  %9 = trunc nuw i8 %8 to i1
  %10 = icmp ne ptr %0, null
  %or.cond = and i1 %10, %9
  %11 = icmp ne ptr %1, null
  %or.cond3 = and i1 %11, %or.cond
  %12 = icmp ne ptr %2, null
  %or.cond5 = and i1 %12, %or.cond3
  br i1 %or.cond5, label %13, label %.sink.split

13:                                               ; preds = %7
  %14 = load i8, ptr getelementptr inbounds (i8, ptr @backend_state, i64 85), align 1, !tbaa !18, !range !16, !noundef !17
  %15 = trunc nuw i8 %14 to i1
  br i1 %15, label %16, label %.sink.split

16:                                               ; preds = %13
  %17 = tail call zeroext i1 @lapack_solve_triangular(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull %2, i64 noundef %3, i64 noundef %4, i1 noundef zeroext %5, i1 noundef zeroext %6, i32 noundef 101) #2
  br i1 %17, label %18, label %.sink.split

.sink.split:                                      ; preds = %13, %16, %7
  %.sink = phi i32 [ 1, %7 ], [ 4, %16 ], [ 5, %13 ]
  store i32 %.sink, ptr getelementptr inbounds (i8, ptr @backend_state, i64 80), align 8, !tbaa !19
  br label %18

18:                                               ; preds = %.sink.split, %16
  %.1 = phi i1 [ true, %16 ], [ false, %.sink.split ]
  ret i1 %.1
}

declare zeroext i1 @lapack_solve_triangular(ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef, i1 noundef zeroext, i1 noundef zeroext, i32 noundef) local_unnamed_addr #1

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

!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 84}
!6 = !{!"", !7, i64 0, !14, i64 40, !8, i64 80, !12, i64 84, !12, i64 85}
!7 = !{!"", !8, i64 0, !11, i64 8, !12, i64 16, !12, i64 17, !12, i64 18, !11, i64 24, !13, i64 32}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"_Bool", !9, i64 0}
!13 = !{!"any pointer", !9, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !11, i64 32}
!15 = !{!"double", !9, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!6, !12, i64 85}
!19 = !{!6, !8, i64 80}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass