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

; 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.MaximizeContext = type { ptr, ptr, i64 }

@is_initialized = external hidden global i8, align 1
@maximize_ctx = external hidden global %struct.MaximizeContext, align 8

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @geometric_core_minimize(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @geometric_core_maximize(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, i64 noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i64 %4, ptr %12, align 8, !tbaa !9
  store i64 %5, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %6
  store i32 -1, ptr %7, align 4
  br label %44

18:                                               ; preds = %6
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i32 -1, ptr %7, align 4
  br label %44

22:                                               ; preds = %18
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %22
  store i32 -1, ptr %7, align 4
  br label %44

26:                                               ; preds = %22
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i32 -1, ptr %7, align 4
  br label %44

30:                                               ; preds = %26
  %31 = load i8, ptr @is_initialized, align 1, !tbaa !11, !range !13, !noundef !14
  %32 = trunc i8 %31 to i1
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  store i32 -4, ptr %7, align 4
  br label %44

34:                                               ; preds = %30
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %35, ptr @maximize_ctx, align 8, !tbaa !15
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %36, ptr getelementptr inbounds (%struct.MaximizeContext, ptr @maximize_ctx, i32 0, i32 1), align 8, !tbaa !17
  %37 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %37, ptr getelementptr inbounds (%struct.MaximizeContext, ptr @maximize_ctx, i32 0, i32 2), align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = load i64, ptr %12, align 8, !tbaa !9
  %41 = load i64, ptr %13, align 8, !tbaa !9
  %42 = call i32 @geometric_core_minimize(ptr noundef %38, ptr noundef @wrapped_objective, ptr noundef @wrapped_gradient, ptr noundef %39, i64 noundef %40, i64 noundef %41)
  store i32 %42, ptr %14, align 4, !tbaa !19
  %43 = load i32, ptr %14, align 4, !tbaa !19
  store i32 %43, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %44

44:                                               ; preds = %34, %33, %29, %25, %21, %17
  %45 = load i32, ptr %7, align 4
  ret i32 %45
}

; Function Attrs: nounwind uwtable
declare hidden void @wrapped_objective(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @wrapped_gradient(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16}
!17 = !{!16, !6, i64 8}
!18 = !{!16, !10, i64 16}
!19 = !{!20, !20, i64 0}
!20 = !{!"int", !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.MaximizeContext = type { ptr, ptr, i64 }

@is_initialized = external hidden local_unnamed_addr global i8, align 1
@maximize_ctx = external hidden local_unnamed_addr global %struct.MaximizeContext, align 8

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

; Function Attrs: nounwind uwtable
define dso_local i32 @geometric_core_maximize(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, i64 noundef %5) local_unnamed_addr #0 {
  %7 = insertelement <4 x ptr> poison, ptr %0, i64 0
  %8 = insertelement <4 x ptr> %7, ptr %1, i64 1
  %9 = insertelement <4 x ptr> %8, ptr %2, i64 2
  %10 = insertelement <4 x ptr> %9, ptr %3, i64 3
  %11 = icmp eq <4 x ptr> %10, zeroinitializer
  %12 = bitcast <4 x i1> %11 to i4
  %.not = icmp eq i4 %12, 0
  br i1 %.not, label %13, label %18

13:                                               ; preds = %6
  %14 = load i8, ptr @is_initialized, align 1, !tbaa !5, !range !9, !noundef !10
  %15 = trunc nuw i8 %14 to i1
  br i1 %15, label %16, label %18

16:                                               ; preds = %13
  store ptr %2, ptr @maximize_ctx, align 8, !tbaa !11
  store ptr %1, ptr getelementptr inbounds (i8, ptr @maximize_ctx, i64 8), align 8, !tbaa !15
  store i64 %4, ptr getelementptr inbounds (i8, ptr @maximize_ctx, i64 16), align 8, !tbaa !16
  %17 = tail call i32 @geometric_core_minimize(ptr noundef nonnull %0, ptr noundef nonnull @wrapped_objective, ptr noundef nonnull @wrapped_gradient, ptr noundef nonnull %3, i64 noundef %4, i64 noundef %5)
  br label %18

18:                                               ; preds = %13, %6, %16
  %.0 = phi i32 [ %17, %16 ], [ -1, %6 ], [ -4, %13 ]
  ret i32 %.0
}

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

; Function Attrs: nounwind uwtable
declare hidden void @wrapped_gradient(ptr 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" }

!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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8, !14, i64 16}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !13, i64 8}
!16 = !{!12, !14, i64 16}


; Effective O3 passes: GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass