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

; 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 { i32, i8, i64, ptr }

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @initialize_lapack() #0

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @convert_layout(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @lapack_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, i32 noundef %7) #0 {
  %9 = alloca i1, align 1
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i8, align 1
  %16 = alloca i8, align 1
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca i8, align 1
  %22 = alloca i8, align 1
  %23 = alloca i8, align 1
  %24 = alloca i32, align 4
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  %27 = alloca i32, align 4
  %28 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store ptr %2, ptr %12, align 8, !tbaa !5
  store i64 %3, ptr %13, align 8, !tbaa !9
  store i64 %4, ptr %14, align 8, !tbaa !9
  %29 = zext i1 %5 to i8
  store i8 %29, ptr %15, align 1, !tbaa !11
  %30 = zext i1 %6 to i8
  store i8 %30, ptr %16, align 1, !tbaa !11
  store i32 %7, ptr %17, align 4, !tbaa !13
  %31 = call zeroext i1 @initialize_lapack()
  br i1 %31, label %32, label %47

32:                                               ; preds = %8
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %47

35:                                               ; preds = %32
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %47

38:                                               ; preds = %35
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %47

41:                                               ; preds = %38
  %42 = load i64, ptr %13, align 8, !tbaa !9
  %43 = icmp eq i64 %42, 0
  br i1 %43, label %47, label %44

44:                                               ; preds = %41
  %45 = load i64, ptr %14, align 8, !tbaa !9
  %46 = icmp eq i64 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44, %41, %38, %35, %32, %8
  store i32 -1, ptr @lapack_state, align 8, !tbaa !15
  store i1 false, ptr %9, align 1
  br label %113

48:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  %49 = load i64, ptr %13, align 8, !tbaa !9
  %50 = load i64, ptr %13, align 8, !tbaa !9
  %51 = mul i64 %49, %50
  %52 = mul i64 %51, 8
  %53 = call noalias ptr @malloc(i64 noundef %52) #6
  store ptr %53, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %54 = load i64, ptr %13, align 8, !tbaa !9
  %55 = load i64, ptr %14, align 8, !tbaa !9
  %56 = mul i64 %54, %55
  %57 = mul i64 %56, 8
  %58 = call noalias ptr @malloc(i64 noundef %57) #6
  store ptr %58, ptr %19, align 8, !tbaa !5
  %59 = load ptr, ptr %18, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %64

61:                                               ; preds = %48
  %62 = load ptr, ptr %19, align 8, !tbaa !5
  %63 = icmp ne ptr %62, null
  br i1 %63, label %67, label %64

64:                                               ; preds = %61, %48
  %65 = load ptr, ptr %18, align 8, !tbaa !5
  call void @free(ptr noundef %65) #5
  %66 = load ptr, ptr %19, align 8, !tbaa !5
  call void @free(ptr noundef %66) #5
  store i32 -2, ptr @lapack_state, align 8, !tbaa !15
  store i1 false, ptr %9, align 1
  store i32 1, ptr %20, align 4
  br label %112

67:                                               ; preds = %61
  %68 = load ptr, ptr %18, align 8, !tbaa !5
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = load i64, ptr %13, align 8, !tbaa !9
  %71 = load i64, ptr %13, align 8, !tbaa !9
  %72 = load i32, ptr %17, align 4, !tbaa !13
  call void @convert_layout(ptr noundef %68, ptr noundef %69, i64 noundef %70, i64 noundef %71, i32 noundef %72, i32 noundef 102)
  %73 = load ptr, ptr %19, align 8, !tbaa !5
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = load i64, ptr %13, align 8, !tbaa !9
  %76 = load i64, ptr %14, align 8, !tbaa !9
  %77 = load i32, ptr %17, align 4, !tbaa !13
  call void @convert_layout(ptr noundef %73, ptr noundef %74, i64 noundef %75, i64 noundef %76, i32 noundef %77, i32 noundef 102)
  call void @llvm.lifetime.start.p0(i64 1, ptr %21) #5
  %78 = load i8, ptr %15, align 1, !tbaa !11, !range !17, !noundef !18
  %79 = trunc i8 %78 to i1
  %80 = zext i1 %79 to i64
  %81 = select i1 %79, i32 85, i32 76
  %82 = trunc i32 %81 to i8
  store i8 %82, ptr %21, align 1, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 1, ptr %22) #5
  store i8 78, ptr %22, align 1, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 1, ptr %23) #5
  %83 = load i8, ptr %16, align 1, !tbaa !11, !range !17, !noundef !18
  %84 = trunc i8 %83 to i1
  %85 = zext i1 %84 to i64
  %86 = select i1 %84, i32 85, i32 78
  %87 = trunc i32 %86 to i8
  store i8 %87, ptr %23, align 1, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #5
  %88 = load i64, ptr %13, align 8, !tbaa !9
  %89 = trunc i64 %88 to i32
  store i32 %89, ptr %24, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #5
  %90 = load i64, ptr %14, align 8, !tbaa !9
  %91 = trunc i64 %90 to i32
  store i32 %91, ptr %25, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #5
  %92 = load i32, ptr %24, align 4, !tbaa !13
  store i32 %92, ptr %26, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %27) #5
  %93 = load i32, ptr %24, align 4, !tbaa !13
  store i32 %93, ptr %27, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %28) #5
  %94 = load ptr, ptr %18, align 8, !tbaa !5
  %95 = load ptr, ptr %19, align 8, !tbaa !5
  call void @ctrtrs_(ptr noundef %21, ptr noundef %22, ptr noundef %23, ptr noundef %24, ptr noundef %25, ptr noundef %94, ptr noundef %26, ptr noundef %95, ptr noundef %27, ptr noundef %28)
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = load ptr, ptr %19, align 8, !tbaa !5
  %98 = load i64, ptr %13, align 8, !tbaa !9
  %99 = load i64, ptr %14, align 8, !tbaa !9
  %100 = load i32, ptr %17, align 4, !tbaa !13
  call void @convert_layout(ptr noundef %96, ptr noundef %97, i64 noundef %98, i64 noundef %99, i32 noundef 102, i32 noundef %100)
  %101 = load ptr, ptr %19, align 8, !tbaa !5
  call void @free(ptr noundef %101) #5
  %102 = load ptr, ptr %18, align 8, !tbaa !5
  call void @free(ptr noundef %102) #5
  %103 = load i32, ptr %28, align 4, !tbaa !13
  %104 = icmp ne i32 %103, 0
  br i1 %104, label %105, label %110

105:                                              ; preds = %67
  %106 = load i32, ptr %28, align 4, !tbaa !13
  %107 = icmp sgt i32 %106, 0
  %108 = zext i1 %107 to i64
  %109 = select i1 %107, i32 -3, i32 -1
  store i32 %109, ptr @lapack_state, align 8, !tbaa !15
  store i1 false, ptr %9, align 1
  store i32 1, ptr %20, align 4
  br label %111

110:                                              ; preds = %67
  store i32 0, ptr @lapack_state, align 8, !tbaa !15
  store i1 true, ptr %9, align 1
  store i32 1, ptr %20, align 4
  br label %111

111:                                              ; preds = %110, %105
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %21) #5
  br label %112

112:                                              ; preds = %111, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  br label %113

113:                                              ; preds = %112, %47
  %114 = load i1, ptr %9, align 1
  ret i1 %114
}

declare void @ctrtrs_(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { "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 = !{!"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, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"", !14, i64 0, !12, i64 4, !10, i64 8, !6, i64 16}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!7, !7, i64 0}


; 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 { i32, i8, i64, ptr }

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @initialize_lapack() local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @convert_layout(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @lapack_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, i32 noundef %7) local_unnamed_addr #0 {
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = tail call zeroext i1 @initialize_lapack()
  %18 = icmp ne ptr %0, null
  %or.cond = and i1 %18, %17
  %19 = icmp ne ptr %1, null
  %or.cond3 = and i1 %19, %or.cond
  %20 = icmp ne ptr %2, null
  %or.cond5 = and i1 %20, %or.cond3
  %or.cond5.not = xor i1 %or.cond5, true
  %21 = icmp eq i64 %3, 0
  %or.cond7 = or i1 %21, %or.cond5.not
  %22 = icmp eq i64 %4, 0
  %or.cond9 = or i1 %22, %or.cond7
  br i1 %or.cond9, label %23, label %24

23:                                               ; preds = %8
  store i32 -1, ptr @lapack_state, align 8, !tbaa !5
  br label %41

24:                                               ; preds = %8
  %25 = shl i64 %3, 3
  %26 = mul i64 %25, %3
  %27 = tail call noalias ptr @malloc(i64 noundef %26) #5
  %28 = mul i64 %25, %4
  %29 = tail call noalias ptr @malloc(i64 noundef %28) #5
  %30 = icmp ne ptr %27, null
  %31 = icmp ne ptr %29, null
  %or.cond11 = and i1 %30, %31
  br i1 %or.cond11, label %33, label %32

32:                                               ; preds = %24
  tail call void @free(ptr noundef %27) #6
  tail call void @free(ptr noundef %29) #6
  store i32 -2, ptr @lapack_state, align 8, !tbaa !5
  br label %41

33:                                               ; preds = %24
  tail call void @convert_layout(ptr noundef nonnull %27, ptr noundef %0, i64 noundef %3, i64 noundef %3, i32 noundef %7, i32 noundef 102)
  tail call void @convert_layout(ptr noundef nonnull %29, ptr noundef nonnull %1, i64 noundef %3, i64 noundef %4, i32 noundef %7, i32 noundef 102)
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %9) #6
  %34 = select i1 %5, i8 85, i8 76
  store i8 %34, ptr %9, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %10) #6
  store i8 78, ptr %10, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %11) #6
  %35 = select i1 %6, i8 85, i8 78
  store i8 %35, ptr %11, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %12) #6
  %36 = trunc i64 %3 to i32
  store i32 %36, ptr %12, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %13) #6
  %37 = trunc i64 %4 to i32
  store i32 %37, ptr %13, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %14) #6
  store i32 %36, ptr %14, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %15) #6
  store i32 %36, ptr %15, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %16) #6
  call void @ctrtrs_(ptr noundef nonnull %9, ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef nonnull %12, ptr noundef nonnull %13, ptr noundef nonnull %27, ptr noundef nonnull %14, ptr noundef nonnull %29, ptr noundef nonnull %15, ptr noundef nonnull %16) #6
  call void @convert_layout(ptr noundef nonnull %2, ptr noundef nonnull %29, i64 noundef %3, i64 noundef %4, i32 noundef 102, i32 noundef %7)
  call void @free(ptr noundef nonnull %29) #6
  call void @free(ptr noundef nonnull %27) #6
  %38 = load i32, ptr %16, align 4, !tbaa !14
  %.not = icmp eq i32 %38, 0
  %39 = icmp sgt i32 %38, 0
  %40 = select i1 %39, i32 -3, i32 -1
  %storemerge = select i1 %.not, i32 0, i32 %40
  store i32 %storemerge, ptr @lapack_state, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %16) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %12) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %11) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %10) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %9) #6
  br label %41

41:                                               ; preds = %32, %33, %23
  %.2 = phi i1 [ false, %23 ], [ %.not, %33 ], [ false, %32 ]
  ret i1 %.2
}

declare void @ctrtrs_(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { "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 allocsize(0) }
attributes #6 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 4, !11, i64 8, !12, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!7, !7, i64 0}


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