; 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 }

; Function Attrs: nounwind uwtable
define dso_local ptr @analyze_algorithm(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %18 = call noalias ptr @malloc(i64 noundef 40) #5
  store ptr %18, ptr %11, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call noalias ptr @strdup(ptr noundef %19) #4
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.complexity_analysis, ptr %21, i32 0, i32 2
  store ptr %20, ptr %22, align 8, !tbaa !11
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.complexity_analysis, ptr %24, i32 0, i32 3
  store i32 %23, ptr %25, align 8, !tbaa !14
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = mul i64 %27, 16
  %29 = call noalias ptr @malloc(i64 noundef %28) #5
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.complexity_analysis, ptr %30, i32 0, i32 4
  store ptr %29, ptr %31, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = sitofp i32 %32 to double
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = sitofp i32 %34 to double
  %36 = fdiv double %33, %35
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = sub nsw i32 %37, 1
  %39 = sitofp i32 %38 to double
  %40 = fdiv double 1.000000e+00, %39
  %41 = call double @pow(double noundef %36, double noundef %40) #4
  store double %41, ptr %12, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %86, %5
  %43 = load i32, ptr %13, align 4, !tbaa !9
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = icmp slt i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %89

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = sitofp i32 %48 to double
  %50 = load double, ptr %12, align 8, !tbaa !16
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = sitofp i32 %51 to double
  %53 = call double @pow(double noundef %50, double noundef %52) #4
  %54 = fmul double %49, %53
  %55 = fptosi double %54 to i32
  store i32 %55, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %56 = load i32, ptr %14, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = mul i64 %57, 4
  %59 = call noalias ptr @malloc(i64 noundef %58) #5
  store ptr %59, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %60 = call i64 @clock() #4
  store i64 %60, ptr %16, align 8, !tbaa !17
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %15, align 8, !tbaa !5
  %63 = load i32, ptr %14, align 4, !tbaa !9
  call void %61(ptr noundef %62, i32 noundef %63)
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %64 = call i64 @clock() #4
  store i64 %64, ptr %17, align 8, !tbaa !17
  %65 = load i32, ptr %14, align 4, !tbaa !9
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.complexity_analysis, ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !15
  %69 = load i32, ptr %13, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds %struct.timing_point, ptr %68, i64 %70
  %72 = getelementptr inbounds %struct.timing_point, ptr %71, i32 0, i32 0
  store i32 %65, ptr %72, align 8, !tbaa !19
  %73 = load i64, ptr %17, align 8, !tbaa !17
  %74 = load i64, ptr %16, align 8, !tbaa !17
  %75 = sub nsw i64 %73, %74
  %76 = sitofp i64 %75 to double
  %77 = fdiv double %76, 1.000000e+06
  %78 = load ptr, ptr %11, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.complexity_analysis, ptr %78, i32 0, i32 4
  %80 = load ptr, ptr %79, align 8, !tbaa !15
  %81 = load i32, ptr %13, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds %struct.timing_point, ptr %80, i64 %82
  %84 = getelementptr inbounds %struct.timing_point, ptr %83, i32 0, i32 1
  store double %77, ptr %84, align 8, !tbaa !21
  %85 = load ptr, ptr %15, align 8, !tbaa !5
  call void @free(ptr noundef %85) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %86

86:                                               ; preds = %47
  %87 = load i32, ptr %13, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %13, align 4, !tbaa !9
  br label %42, !llvm.loop !22

89:                                               ; preds = %46
  %90 = load ptr, ptr %11, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.complexity_analysis, ptr %90, i32 0, i32 4
  %92 = load ptr, ptr %91, align 8, !tbaa !15
  %93 = load i32, ptr %10, align 4, !tbaa !9
  %94 = load ptr, ptr %11, align 8, !tbaa !5
  call void @calculate_complexity(ptr noundef %92, i32 noundef %93, ptr noundef %94)
  %95 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret ptr %95
}

; 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 noalias ptr @strdup(ptr noundef) #3

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #3

; Function Attrs: nounwind
declare i64 @clock() #3

; Function Attrs: nounwind
declare void @free(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
declare hidden void @calculate_complexity(ptr noundef, i32 noundef, ptr noundef) #0

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 = { nounwind }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"", !13, i64 0, !13, i64 8, !6, i64 16, !10, i64 24, !6, i64 32}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !10, i64 24}
!15 = !{!12, !6, i64 32}
!16 = !{!13, !13, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!20, !10, i64 0}
!20 = !{!"", !10, i64 0, !13, i64 8}
!21 = !{!20, !13, i64 8}
!22 = distinct !{!22, !23}
!23 = !{!"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 }

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @analyze_algorithm(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #6
  %7 = tail call noalias ptr @strdup(ptr noundef %0) #7
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %7, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 24
  store i32 %4, ptr %9, align 8, !tbaa !12
  %10 = sext i32 %4 to i64
  %11 = shl nsw i64 %10, 4
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #6
  %13 = getelementptr inbounds i8, ptr %6, i64 32
  store ptr %12, ptr %13, align 8, !tbaa !13
  %14 = sitofp i32 %3 to double
  %15 = sitofp i32 %2 to double
  %16 = fdiv double %14, %15
  %17 = add nsw i32 %4, -1
  %18 = sitofp i32 %17 to double
  %19 = fdiv double 1.000000e+00, %18
  %20 = tail call double @pow(double noundef %16, double noundef %19) #7
  %21 = icmp sgt i32 %4, 0
  br i1 %21, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %5
  tail call void @calculate_complexity(ptr noundef %12, i32 noundef %4, ptr noundef nonnull %6)
  ret ptr %6

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %22 = trunc nuw nsw i64 %indvars.iv to i32
  %23 = uitofp nneg i32 %22 to double
  %24 = tail call double @pow(double noundef %20, double noundef %23) #7
  %25 = fmul double %24, %15
  %26 = fptosi double %25 to i32
  %27 = sext i32 %26 to i64
  %28 = shl nsw i64 %27, 2
  %29 = tail call noalias ptr @malloc(i64 noundef %28) #6
  %30 = tail call i64 @clock() #7
  tail call void %1(ptr noundef %29, i32 noundef %26) #7
  %31 = tail call i64 @clock() #7
  %32 = getelementptr inbounds %struct.timing_point, ptr %12, i64 %indvars.iv
  store i32 %26, ptr %32, align 8, !tbaa !14
  %33 = sub nsw i64 %31, %30
  %34 = sitofp i64 %33 to double
  %35 = fdiv double %34, 1.000000e+06
  %36 = getelementptr inbounds %struct.timing_point, ptr %12, i64 %indvars.iv, i32 1
  store double %35, ptr %36, align 8, !tbaa !16
  tail call void @free(ptr noundef %29) #7
  %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 %.lr.ph, !llvm.loop !17
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #4

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

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

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 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 #2 = { mustprogress nofree nounwind willreturn 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 #3 = { mustprogress nofree nounwind willreturn memory(write) "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 "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 = { 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 #6 = { nounwind allocsize(0) }
attributes #7 = { 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, !10, i64 16}
!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, !11, i64 24}
!13 = !{!6, !10, i64 32}
!14 = !{!15, !11, i64 0}
!15 = !{!"", !11, i64 0, !7, i64 8}
!16 = !{!15, !7, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass