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

@.str.4 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [41 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 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_optimization(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 float, 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
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

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

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

17:                                               ; preds = %14
  store i32 -1, ptr %4, align 4
  br label %88

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

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

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

36:                                               ; preds = %30
  store i32 2, ptr %9, align 4
  br label %65

37:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.quantum_geometric_optimization_t, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  %41 = load i64, ptr %8, align 8, !tbaa !15
  %42 = getelementptr inbounds %struct.ComplexFloat, ptr %40, i64 %41
  %43 = load <2 x float>, ptr %42, align 4
  %44 = call float @complex_float_abs(<2 x float> %43)
  store float %44, ptr %10, align 4, !tbaa !21
  %45 = load float, ptr %10, align 4, !tbaa !21
  %46 = fpext float %45 to double
  %47 = fcmp ogt double %46, 1.000000e+06
  br i1 %47, label %48, label %58

48:                                               ; preds = %37
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.validation_result_t, ptr %49, i32 0, i32 0
  store i8 0, ptr %50, align 4, !tbaa !11
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.validation_result_t, ptr %51, i32 0, i32 1
  store i32 -5, ptr %52, align 4, !tbaa !14
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.validation_result_t, ptr %53, i32 0, i32 2
  %55 = getelementptr inbounds [1024 x i8], ptr %54, i64 0, i64 0
  %56 = load i64, ptr %8, align 8, !tbaa !15
  %57 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %55, i64 noundef 1024, ptr noundef @.str.4, i64 noundef %56) #5
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %59

58:                                               ; preds = %37
  store i32 0, ptr %9, align 4
  br label %59

59:                                               ; preds = %58, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %60 = load i32, ptr %9, align 4
  switch i32 %60, label %65 [
    i32 0, label %61
  ]

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61
  %63 = load i64, ptr %8, align 8, !tbaa !15
  %64 = add i64 %63, 1
  store i64 %64, ptr %8, align 8, !tbaa !15
  br label %30, !llvm.loop !22

65:                                               ; preds = %59, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %66 = load i32, ptr %9, align 4
  switch i32 %66, label %90 [
    i32 2, label %67
    i32 1, label %88
  ]

67:                                               ; preds = %65
  br label %68

68:                                               ; preds = %67, %18
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = and i32 %69, 32
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %87

72:                                               ; preds = %68
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.quantum_geometric_optimization_t, ptr %73, i32 0, i32 3
  %75 = load i64, ptr %74, align 8, !tbaa !24
  %76 = icmp ugt i64 %75, 10000
  br i1 %76, label %77, label %86

77:                                               ; preds = %72
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.validation_result_t, ptr %78, i32 0, i32 0
  store i8 0, ptr %79, align 4, !tbaa !11
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.validation_result_t, ptr %80, i32 0, i32 1
  store i32 -5, ptr %81, align 4, !tbaa !14
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.validation_result_t, ptr %82, i32 0, i32 2
  %84 = getelementptr inbounds [1024 x i8], ptr %83, i64 0, i64 0
  %85 = call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef %84, i64 noundef 1024, ptr noundef @.str.5) #5
  store i32 0, ptr %4, align 4
  br label %88

86:                                               ; preds = %72
  br label %87

87:                                               ; preds = %86, %68
  store i32 0, ptr %4, align 4
  br label %88

88:                                               ; preds = %87, %77, %65, %17, %13
  %89 = load i32, ptr %4, align 4
  ret i32 %89

90:                                               ; preds = %65
  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_optimization_t", !10, i64 0, !16, i64 8, !6, i64 16, !16, i64 24, !19, i64 32, !19, i64 36, !13, i64 40, !6, i64 48}
!19 = !{!"float", !7, i64 0}
!20 = !{!18, !6, i64 16}
!21 = !{!19, !19, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!18, !16, i64 24}


; 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.4 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [41 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 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_optimization(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 %31, 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, 16
  %.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 %24, label %.preheader

.preheader:                                       ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %.not37 = icmp eq i64 %11, 0
  br i1 %.not37, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  br label %13

13:                                               ; preds = %.lr.ph, %.critedge
  %.02536 = phi i64 [ 0, %.lr.ph ], [ %20, %.critedge ]
  %14 = load ptr, ptr %12, align 8, !tbaa !16
  %15 = getelementptr inbounds %struct.ComplexFloat, ptr %14, i64 %.02536
  %16 = load <2 x float>, ptr %15, align 4
  %17 = tail call float @complex_float_abs(<2 x float> %16)
  %18 = fcmp ule float %17, 1.000000e+06
  br i1 %18, label %.critedge, label %.thread

.thread:                                          ; preds = %13
  store i8 0, ptr %2, align 4, !tbaa !5
  store i32 -5, ptr %7, align 4, !tbaa !17
  %19 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %8, i64 noundef 1024, ptr noundef nonnull @.str.4, i64 noundef %.02536) #4
  br label %31

.critedge:                                        ; preds = %13
  %20 = add nuw i64 %.02536, 1
  %21 = load i64, ptr %10, align 8, !tbaa !11
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %13, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %.critedge, %.preheader
  %23 = and i32 %1, 32
  %.not28 = icmp eq i32 %23, 0
  br i1 %.not28, label %31, label %25

24:                                               ; preds = %6
  %.old = and i32 %1, 32
  %.not28.old = icmp eq i32 %.old, 0
  br i1 %.not28.old, label %31, label %25

25:                                               ; preds = %._crit_edge, %24
  %26 = getelementptr inbounds i8, ptr %0, i64 24
  %27 = load i64, ptr %26, align 8, !tbaa !20
  %28 = icmp ugt i64 %27, 10000
  br i1 %28, label %29, label %31

29:                                               ; preds = %25
  store i8 0, ptr %2, align 4, !tbaa !5
  store i32 -5, ptr %7, align 4, !tbaa !17
  %30 = tail call i32 (ptr, i64, ptr, ...) @snprintf(ptr noundef nonnull dereferenceable(1) %8, i64 noundef 1024, ptr noundef nonnull @.str.5) #4
  br label %31

31:                                               ; preds = %.thread, %24, %25, %._crit_edge, %3, %29
  %.3 = phi i32 [ 0, %._crit_edge ], [ 0, %29 ], [ -1, %3 ], [ 0, %25 ], [ 0, %24 ], [ 0, %.thread ]
  ret i32 %.3
}

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_optimization_t", !10, i64 0, !13, i64 8, !14, i64 16, !13, i64 24, !15, i64 32, !15, i64 36, !7, i64 40, !14, i64 48}
!13 = !{!"long", !8, i64 0}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = !{!12, !14, i64 16}
!17 = !{!6, !10, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !13, i64 24}


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