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

; 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.ComplexFloat = type { float, float }
%struct.validation_result_t = type { i8, i32, [1024 x i8] }
%struct.quantum_geometric_connection_t = type { i32, i64, ptr, ptr, i8, i32 }

@.str.2 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @complex_float_subtract(<2 x float>, <2 x float>) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @complex_float_abs(<2 x float>) #2

; Function Attrs: nounwind
declare i32 @snprintf(ptr noundef, i64 noundef, ptr noundef, ...) #3

; 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 i32 @geometric_validate_connection(ptr noundef %0, i32 noundef %1, ptr noundef %2) #4 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca %struct.ComplexFloat, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  br label %132

16:                                               ; preds = %3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store i32 -1, ptr %4, align 4
  br label %132

20:                                               ; preds = %16
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.validation_result_t, ptr %21, i32 0, i32 0
  store i8 1, ptr %22, align 4, !tbaa !11
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.validation_result_t, ptr %23, i32 0, i32 1
  store i32 0, ptr %24, align 4, !tbaa !14
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.validation_result_t, ptr %25, i32 0, i32 2
  %27 = getelementptr inbounds [1024 x i8], ptr %26, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 4 %27, i8 0, i64 1024, i1 false)
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = and i32 %28, 4
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %131

31:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !15
  br label %32

32:                                               ; preds = %125, %31
  %33 = load i64, ptr %8, align 8, !tbaa !15
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.quantum_geometric_connection_t, ptr %34, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !17
  %37 = icmp ult i64 %33, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %32
  store i32 2, ptr %9, align 4
  br label %128

39:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !15
  br label %40

40:                                               ; preds = %119, %39
  %41 = load i64, ptr %10, align 8, !tbaa !15
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.quantum_geometric_connection_t, ptr %42, i32 0, i32 1
  %44 = load i64, ptr %43, align 8, !tbaa !17
  %45 = icmp ult i64 %41, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %40
  store i32 5, ptr %9, align 4
  br label %122

47:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !15
  br label %48

48:                                               ; preds = %113, %47
  %49 = load i64, ptr %11, align 8, !tbaa !15
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.quantum_geometric_connection_t, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !17
  %53 = icmp ult i64 %49, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %48
  store i32 8, ptr %9, align 4
  br label %116

55:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.quantum_geometric_connection_t, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !19
  %59 = load i64, ptr %8, align 8, !tbaa !15
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.quantum_geometric_connection_t, ptr %60, i32 0, i32 1
  %62 = load i64, ptr %61, align 8, !tbaa !17
  %63 = mul i64 %59, %62
  %64 = load i64, ptr %10, align 8, !tbaa !15
  %65 = add i64 %63, %64
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.quantum_geometric_connection_t, ptr %66, i32 0, i32 1
  %68 = load i64, ptr %67, align 8, !tbaa !17
  %69 = mul i64 %65, %68
  %70 = load i64, ptr %11, align 8, !tbaa !15
  %71 = add i64 %69, %70
  %72 = getelementptr inbounds %struct.ComplexFloat, ptr %58, i64 %71
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.quantum_geometric_connection_t, ptr %73, i32 0, i32 2
  %75 = load ptr, ptr %74, align 8, !tbaa !19
  %76 = load i64, ptr %8, align 8, !tbaa !15
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.quantum_geometric_connection_t, ptr %77, i32 0, i32 1
  %79 = load i64, ptr %78, align 8, !tbaa !17
  %80 = mul i64 %76, %79
  %81 = load i64, ptr %11, align 8, !tbaa !15
  %82 = add i64 %80, %81
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.quantum_geometric_connection_t, ptr %83, i32 0, i32 1
  %85 = load i64, ptr %84, align 8, !tbaa !17
  %86 = mul i64 %82, %85
  %87 = load i64, ptr %10, align 8, !tbaa !15
  %88 = add i64 %86, %87
  %89 = getelementptr inbounds %struct.ComplexFloat, ptr %75, i64 %88
  %90 = load <2 x float>, ptr %72, align 4
  %91 = load <2 x float>, ptr %89, align 4
  %92 = call <2 x float> @complex_float_subtract(<2 x float> %90, <2 x float> %91)
  store <2 x float> %92, ptr %12, align 4
  %93 = load <2 x float>, ptr %12, align 4
  %94 = call float @complex_float_abs(<2 x float> %93)
  %95 = fpext float %94 to double
  %96 = fcmp ogt double %95, 0x3EB0C6F7A0B5ED8D
  br i1 %96, label %97, label %109

97:                                               ; preds = %55
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.validation_result_t, ptr %98, i32 0, i32 0
  store i8 0, ptr %99, align 4, !tbaa !11
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.validation_result_t, ptr %100, i32 0, i32 1
  store i32 -5, ptr %101, align 4, !tbaa !14
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.validation_result_t, ptr %102, i32 0, i32 2
  %104 = getelementptr inbounds [1024 x i8], ptr %103, i64 0, i64 0
  %105 = load i64, ptr %8, align 8, !tbaa !15
  %106 = load i64, ptr %10, align 8, !tbaa !15
  %107 = load i64, ptr %11, align 8, !tbaa !15
  %108 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %104, i64 noundef 1024, ptr noundef @.str.2, i64 noundef %105, i64 noundef %106, i64 noundef %107) #5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %110

109:                                              ; preds = %55
  store i32 0, ptr %9, align 4
  br label %110

110:                                              ; preds = %109, %97
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %111 = load i32, ptr %9, align 4
  switch i32 %111, label %116 [
    i32 0, label %112
  ]

112:                                              ; preds = %110
  br label %113

113:                                              ; preds = %112
  %114 = load i64, ptr %11, align 8, !tbaa !15
  %115 = add i64 %114, 1
  store i64 %115, ptr %11, align 8, !tbaa !15
  br label %48, !llvm.loop !20

116:                                              ; preds = %110, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  %117 = load i32, ptr %9, align 4
  switch i32 %117, label %122 [
    i32 8, label %118
  ]

118:                                              ; preds = %116
  br label %119

119:                                              ; preds = %118
  %120 = load i64, ptr %10, align 8, !tbaa !15
  %121 = add i64 %120, 1
  store i64 %121, ptr %10, align 8, !tbaa !15
  br label %40, !llvm.loop !22

122:                                              ; preds = %116, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %123 = load i32, ptr %9, align 4
  switch i32 %123, label %128 [
    i32 5, label %124
  ]

124:                                              ; preds = %122
  br label %125

125:                                              ; preds = %124
  %126 = load i64, ptr %8, align 8, !tbaa !15
  %127 = add i64 %126, 1
  store i64 %127, ptr %8, align 8, !tbaa !15
  br label %32, !llvm.loop !23

128:                                              ; preds = %122, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %129 = load i32, ptr %9, align 4
  switch i32 %129, label %134 [
    i32 2, label %130
    i32 1, label %132
  ]

130:                                              ; preds = %128
  br label %131

131:                                              ; preds = %130, %20
  store i32 0, ptr %4, align 4
  br label %132

132:                                              ; preds = %131, %128, %19, %15
  %133 = load i32, ptr %4, align 4
  ret i32 %133

134:                                              ; preds = %128
  unreachable
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint nounwind uwtable "min-legal-vector-width"="64" "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 = { nounwind uwtable "min-legal-vector-width"="64" "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 }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !10, i64 4, !7, i64 8}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!18, !16, i64 8}
!18 = !{!"quantum_geometric_connection_t", !10, i64 0, !16, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !10, i64 36}
!19 = !{!18, !6, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}
!23 = distinct !{!23, !21}


; 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.ComplexFloat = type { float, float }

@.str.2 = external hidden unnamed_addr constant [53 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @complex_float_subtract(<2 x float>, <2 x float>) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @complex_float_abs(<2 x float>) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @snprintf(ptr noalias nocapture noundef writeonly, i64 noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @geometric_validate_connection(ptr noundef readonly %0, i32 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #3 {
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %2, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %.loopexit, label %6

6:                                                ; preds = %3
  store i8 1, ptr %2, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %2, i64 4
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = and i32 %1, 4
  %.not = icmp eq i32 %9, 0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1028) %7, i8 0, i64 1028, i1 false)
  br i1 %.not, label %.loopexit, label %.preheader55

.preheader55:                                     ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %.not65 = icmp eq i64 %11, 0
  br i1 %.not65, label %.loopexit, label %.preheader54.preheader

.preheader54.preheader:                           ; preds = %.preheader55
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  br label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader54.preheader, %._crit_edge62
  %13 = phi i64 [ %33, %._crit_edge62 ], [ %11, %.preheader54.preheader ]
  %.04563 = phi i64 [ %38, %._crit_edge62 ], [ 0, %.preheader54.preheader ]
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %._crit_edge, %.preheader.preheader
  %14 = phi i64 [ %33, %._crit_edge ], [ %13, %.preheader.preheader ]
  %.04061 = phi i64 [ %34, %._crit_edge ], [ 0, %.preheader.preheader ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.critedge
  %15 = phi i64 [ %33, %.critedge ], [ %14, %.lr.ph.preheader ]
  %.03960 = phi i64 [ %32, %.critedge ], [ 0, %.lr.ph.preheader ]
  %16 = load ptr, ptr %12, align 8, !tbaa !15
  %17 = mul i64 %15, %.04563
  %18 = add i64 %17, %.04061
  %19 = mul i64 %18, %15
  %20 = getelementptr %struct.ComplexFloat, ptr %16, i64 %19
  %21 = getelementptr %struct.ComplexFloat, ptr %20, i64 %.03960
  %22 = add i64 %17, %.03960
  %23 = mul i64 %22, %15
  %24 = getelementptr %struct.ComplexFloat, ptr %16, i64 %23
  %25 = getelementptr %struct.ComplexFloat, ptr %24, i64 %.04061
  %26 = load <2 x float>, ptr %21, align 4
  %27 = load <2 x float>, ptr %25, align 4
  %28 = tail call <2 x float> @complex_float_subtract(<2 x float> %26, <2 x float> %27)
  %29 = tail call float @complex_float_abs(<2 x float> %28)
  %30 = fpext float %29 to double
  %31 = fcmp ule double %30, 0x3EB0C6F7A0B5ED8D
  br i1 %31, label %.critedge, label %36

.critedge:                                        ; preds = %.lr.ph
  %32 = add nuw i64 %.03960, 1
  %33 = load i64, ptr %10, align 8, !tbaa !11
  %.not49 = icmp ult i64 %32, %33
  br i1 %.not49, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.critedge
  %34 = add nuw i64 %.04061, 1
  %35 = icmp ult i64 %34, %33
  br i1 %35, label %.lr.ph.preheader, label %._crit_edge62, !llvm.loop !18

36:                                               ; preds = %.lr.ph
  store i8 0, ptr %2, align 4, !tbaa !5
  store i32 -5, ptr %7, align 4, !tbaa !20
  %37 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %8, i64 noundef 1024, ptr noundef nonnull @.str.2, i64 noundef %.04563, i64 noundef %.04061, i64 noundef %.03960) #4
  br label %.loopexit

._crit_edge62:                                    ; preds = %._crit_edge
  %38 = add nuw i64 %.04563, 1
  %39 = icmp ult i64 %38, %33
  br i1 %39, label %.preheader.preheader, label %.loopexit, !llvm.loop !21

.loopexit:                                        ; preds = %._crit_edge62, %.preheader55, %36, %6, %3
  %.7 = phi i32 [ -1, %3 ], [ 0, %6 ], [ 0, %36 ], [ 0, %.preheader55 ], [ 0, %._crit_edge62 ]
  ret i32 %.7
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { inlinehint nounwind uwtable "min-legal-vector-width"="64" "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 "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"="64" "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 }

!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, !8, i64 8}
!7 = !{!"_Bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"quantum_geometric_connection_t", !10, i64 0, !13, i64 8, !14, i64 16, !14, i64 24, !7, i64 32, !10, i64 36}
!13 = !{!"long", !8, i64 0}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!12, !14, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17, !19}
!19 = !{!"llvm.loop.unswitch.partial.disable"}
!20 = !{!6, !10, i64 4}
!21 = distinct !{!21, !17, !19}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass