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

; 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.geometric_encoding_config_t = type { float, i32, ptr }
%struct.quantum_system_t = type { i64, i64, i32, i32, ptr, ptr, ptr, ptr }
%struct.quantum_protection_t = type { i64, i64, i32, ptr, ptr, ptr, ptr }

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @validate_system_state(ptr noundef) #2

; 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 hidden void @cleanup_protection_system(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @quantum_protect_config(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call i32 @validate_system_state(ptr noundef %17)
  store i32 %18, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %16
  %22 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %22, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %87

23:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %24, ptr %8, align 8, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.geometric_encoding_config_t, ptr %25, i32 0, i32 0
  %27 = load float, ptr %26, align 8, !tbaa !11
  %28 = fcmp olt float %27, 0.000000e+00
  br i1 %28, label %34, label %29

29:                                               ; preds = %23
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.geometric_encoding_config_t, ptr %30, i32 0, i32 0
  %32 = load float, ptr %31, align 8, !tbaa !11
  %33 = fcmp ogt float %32, 1.000000e+00
  br i1 %33, label %34, label %35

34:                                               ; preds = %29, %23
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %86

35:                                               ; preds = %29
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.geometric_encoding_config_t, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = and i32 %38, 2
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %85

41:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %42 = call noalias ptr @malloc(i64 noundef 56) #4
  store ptr %42, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 -2, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %82

46:                                               ; preds = %41
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.quantum_system_t, ptr %47, i32 0, i32 0
  %49 = load i64, ptr %48, align 8, !tbaa !15
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.quantum_protection_t, ptr %50, i32 0, i32 0
  store i64 %49, ptr %51, align 8, !tbaa !18
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.quantum_protection_t, ptr %52, i32 0, i32 1
  store i64 3, ptr %53, align 8, !tbaa !20
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.quantum_protection_t, ptr %54, i32 0, i32 3
  store ptr null, ptr %55, align 8, !tbaa !21
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.quantum_protection_t, ptr %56, i32 0, i32 4
  store ptr null, ptr %57, align 8, !tbaa !22
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.quantum_protection_t, ptr %58, i32 0, i32 5
  store ptr null, ptr %59, align 8, !tbaa !23
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.quantum_system_t, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !24
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %74

64:                                               ; preds = %46
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.quantum_system_t, ptr %65, i32 0, i32 2
  %67 = load i32, ptr %66, align 8, !tbaa !25
  %68 = and i32 %67, 2
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %74

70:                                               ; preds = %64
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.quantum_system_t, ptr %71, i32 0, i32 4
  %73 = load ptr, ptr %72, align 8, !tbaa !24
  call void @cleanup_protection_system(ptr noundef %73)
  br label %74

74:                                               ; preds = %70, %64, %46
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.quantum_system_t, ptr %76, i32 0, i32 4
  store ptr %75, ptr %77, align 8, !tbaa !24
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.quantum_system_t, ptr %78, i32 0, i32 2
  %80 = load i32, ptr %79, align 8, !tbaa !25
  %81 = or i32 %80, 2
  store i32 %81, ptr %79, align 8, !tbaa !25
  store i32 0, ptr %7, align 4
  br label %82

82:                                               ; preds = %74, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %83 = load i32, ptr %7, align 4
  switch i32 %83, label %86 [
    i32 0, label %84
  ]

84:                                               ; preds = %82
  br label %85

85:                                               ; preds = %84, %35
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %86

86:                                               ; preds = %85, %82, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %87

87:                                               ; preds = %86, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %88

88:                                               ; preds = %87, %15
  %89 = load i32, ptr %3, align 4
  ret i32 %89
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nounwind }
attributes #4 = { 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, !13, i64 0}
!12 = !{!"geometric_encoding_config_t", !13, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!16, !17, i64 0}
!16 = !{!"quantum_system_t", !17, i64 0, !17, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !17, i64 0}
!19 = !{!"", !17, i64 0, !17, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!20 = !{!19, !17, i64 8}
!21 = !{!19, !6, i64 24}
!22 = !{!19, !6, i64 32}
!23 = !{!19, !6, i64 40}
!24 = !{!16, !6, i64 24}
!25 = !{!16, !10, i64 16}


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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @validate_system_state(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @quantum_protect_config(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = icmp ne ptr %0, null
  %4 = icmp ne ptr %1, null
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %5, label %.critedge

5:                                                ; preds = %2
  %6 = tail call i32 @validate_system_state(ptr noundef nonnull %1)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %.critedge

7:                                                ; preds = %5
  %8 = load float, ptr %0, align 8, !tbaa !5
  %9 = fcmp olt float %8, 0.000000e+00
  %10 = fcmp ogt float %8, 1.000000e+00
  %or.cond34 = or i1 %9, %10
  br i1 %or.cond34, label %.critedge, label %11

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = and i32 %13, 2
  %.not30 = icmp eq i32 %14, 0
  br i1 %.not30, label %.critedge, label %15

15:                                               ; preds = %11
  %16 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #3
  %.not31.not = icmp eq ptr %16, null
  br i1 %.not31.not, label %.critedge, label %17

17:                                               ; preds = %15
  %18 = load i64, ptr %1, align 8, !tbaa !13
  store i64 %18, ptr %16, align 8, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %16, i64 8
  store i64 3, ptr %19, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %16, i64 24
  %21 = getelementptr inbounds i8, ptr %1, i64 24
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %20, i8 0, i64 24, i1 false)
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %.not32 = icmp eq ptr %22, null
  br i1 %.not32, label %28, label %23

23:                                               ; preds = %17
  %24 = getelementptr inbounds i8, ptr %1, i64 16
  %25 = load i32, ptr %24, align 8, !tbaa !20
  %26 = and i32 %25, 2
  %.not33 = icmp eq i32 %26, 0
  br i1 %.not33, label %28, label %27

27:                                               ; preds = %23
  tail call void @cleanup_protection_system(ptr noundef nonnull %22)
  br label %28

28:                                               ; preds = %27, %23, %17
  store ptr %16, ptr %21, align 8, !tbaa !19
  %29 = getelementptr inbounds i8, ptr %1, i64 16
  %30 = load i32, ptr %29, align 8, !tbaa !20
  %31 = or i32 %30, 2
  store i32 %31, ptr %29, align 8, !tbaa !20
  br label %.critedge

.critedge:                                        ; preds = %11, %28, %5, %15, %7, %2
  %.3 = phi i32 [ -1, %2 ], [ %6, %5 ], [ -1, %7 ], [ -2, %15 ], [ 0, %28 ], [ 0, %11 ]
  ret i32 %.3
}

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

attributes #0 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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, !7, i64 0}
!6 = !{!"geometric_encoding_config_t", !7, i64 0, !10, i64 4, !11, i64 8}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 4}
!13 = !{!14, !15, i64 0}
!14 = !{!"quantum_system_t", !15, i64 0, !15, i64 8, !10, i64 16, !10, i64 20, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48}
!15 = !{!"long", !8, i64 0}
!16 = !{!17, !15, i64 0}
!17 = !{!"", !15, i64 0, !15, i64 8, !10, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48}
!18 = !{!17, !15, i64 8}
!19 = !{!14, !11, i64 24}
!20 = !{!14, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass