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

; 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.complexity_analysis = type { double, double, ptr, i32, ptr }
%struct.timing_point = type { i32, double }

@.str.13 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @analyze_algorithm(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) #0

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

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local void @free_analysis(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @get_complexity_class(double noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @compare_implementations(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca double, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, ptr noundef %17)
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = load i32, ptr %11, align 4, !tbaa !9
  %22 = load i32, ptr %12, align 4, !tbaa !9
  %23 = call ptr @analyze_algorithm(ptr noundef @.str.14, ptr noundef %19, i32 noundef %20, i32 noundef %21, i32 noundef %22)
  store ptr %23, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = call ptr @analyze_algorithm(ptr noundef @.str.15, ptr noundef %24, i32 noundef %25, i32 noundef %26, i32 noundef %27)
  store ptr %28, ptr %14, align 8, !tbaa !5
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.16)
  %30 = load ptr, ptr %13, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.complexity_analysis, ptr %30, i32 0, i32 0
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = call ptr @get_complexity_class(double noundef %32)
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.17, ptr noundef %33)
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.complexity_analysis, ptr %35, i32 0, i32 0
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.complexity_analysis, ptr %38, i32 0, i32 1
  %40 = load double, ptr %39, align 8, !tbaa !14
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.18, double noundef %37, double noundef %40)
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.19)
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.complexity_analysis, ptr %43, i32 0, i32 0
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = call ptr @get_complexity_class(double noundef %45)
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.17, ptr noundef %46)
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.complexity_analysis, ptr %48, i32 0, i32 0
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.complexity_analysis, ptr %51, i32 0, i32 1
  %53 = load double, ptr %52, align 8, !tbaa !14
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.18, double noundef %50, double noundef %53)
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.20)
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.21)
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %90, %6
  %58 = load i32, ptr %15, align 4, !tbaa !9
  %59 = load i32, ptr %12, align 4, !tbaa !9
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %93

62:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.complexity_analysis, ptr %63, i32 0, i32 4
  %65 = load ptr, ptr %64, align 8, !tbaa !15
  %66 = load i32, ptr %15, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds %struct.timing_point, ptr %65, i64 %67
  %69 = getelementptr inbounds %struct.timing_point, ptr %68, i32 0, i32 1
  %70 = load double, ptr %69, align 8, !tbaa !16
  %71 = load ptr, ptr %14, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.complexity_analysis, ptr %71, i32 0, i32 4
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = load i32, ptr %15, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds %struct.timing_point, ptr %73, i64 %75
  %77 = getelementptr inbounds %struct.timing_point, ptr %76, i32 0, i32 1
  %78 = load double, ptr %77, align 8, !tbaa !16
  %79 = fdiv double %70, %78
  store double %79, ptr %16, align 8, !tbaa !18
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.complexity_analysis, ptr %80, i32 0, i32 4
  %82 = load ptr, ptr %81, align 8, !tbaa !15
  %83 = load i32, ptr %15, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds %struct.timing_point, ptr %82, i64 %84
  %86 = getelementptr inbounds %struct.timing_point, ptr %85, i32 0, i32 0
  %87 = load i32, ptr %86, align 8, !tbaa !19
  %88 = load double, ptr %16, align 8, !tbaa !18
  %89 = call i32 (ptr, ...) @printf(ptr noundef @.str.22, i32 noundef %87, double noundef %88)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %90

90:                                               ; preds = %62
  %91 = load i32, ptr %15, align 4, !tbaa !9
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %15, align 4, !tbaa !9
  br label %57, !llvm.loop !20

93:                                               ; preds = %61
  %94 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free_analysis(ptr noundef %94)
  %95 = load ptr, ptr %14, align 8, !tbaa !5
  call void @free_analysis(ptr noundef %95)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret void
}

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


; 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.timing_point = type { i32, double }

@.str.13 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @analyze_algorithm(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @free_analysis(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @get_complexity_class(double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @compare_implementations(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, ptr noundef %0)
  %8 = tail call ptr @analyze_algorithm(ptr noundef nonnull @.str.14, ptr noundef %1, i32 noundef %3, i32 noundef %4, i32 noundef %5)
  %9 = tail call ptr @analyze_algorithm(ptr noundef nonnull @.str.15, ptr noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5)
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16)
  %11 = load double, ptr %8, align 8, !tbaa !5
  %12 = tail call ptr @get_complexity_class(double noundef %11)
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17, ptr noundef %12)
  %14 = load double, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %8, i64 8
  %16 = load double, ptr %15, align 8, !tbaa !12
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.18, double noundef %14, double noundef %16)
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.19)
  %19 = load double, ptr %9, align 8, !tbaa !5
  %20 = tail call ptr @get_complexity_class(double noundef %19)
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17, ptr noundef %20)
  %22 = load double, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %9, i64 8
  %24 = load double, ptr %23, align 8, !tbaa !12
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.18, double noundef %22, double noundef %24)
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.20)
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21)
  %28 = icmp sgt i32 %5, 0
  br i1 %28, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %29 = getelementptr inbounds i8, ptr %8, i64 32
  %30 = getelementptr inbounds i8, ptr %9, i64 32
  %wide.trip.count = zext nneg i32 %5 to i64
  br label %31

._crit_edge:                                      ; preds = %31, %6
  tail call void @free_analysis(ptr noundef nonnull %8)
  tail call void @free_analysis(ptr noundef nonnull %9)
  ret void

31:                                               ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %32 = load ptr, ptr %29, align 8, !tbaa !13
  %33 = getelementptr inbounds %struct.timing_point, ptr %32, i64 %indvars.iv
  %34 = getelementptr inbounds i8, ptr %33, i64 8
  %35 = load double, ptr %34, align 8, !tbaa !14
  %36 = load ptr, ptr %30, align 8, !tbaa !13
  %37 = getelementptr inbounds %struct.timing_point, ptr %36, i64 %indvars.iv, i32 1
  %38 = load double, ptr %37, align 8, !tbaa !14
  %39 = fdiv double %35, %38
  %40 = load i32, ptr %33, align 8, !tbaa !16
  %41 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22, i32 noundef %40, double noundef %39)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %31, !llvm.loop !17
}

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 = { 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" }

!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, !7, i64 8, !10, i64 16, !11, i64 24, !10, i64 32}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !10, i64 32}
!14 = !{!15, !7, i64 8}
!15 = !{!"", !11, i64 0, !7, i64 8}
!16 = !{!15, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass