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

; 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.config_context_t = type { i32, i64, i8, i32 }

@global_config_context = external hidden global ptr, align 8

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

8:                                                ; preds = %2
  %9 = load ptr, ptr %5, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %8, %2
  store i32 -1, ptr %3, align 4
  br label %38

12:                                               ; preds = %8
  %13 = load i32, ptr %4, align 4, !tbaa !5
  switch i32 %13, label %36 [
    i32 0, label %14
    i32 1, label %19
    i32 2, label %24
    i32 3, label %31
  ]

14:                                               ; preds = %12
  %15 = load ptr, ptr @global_config_context, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.config_context_t, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 %17, ptr %18, align 4, !tbaa !5
  br label %37

19:                                               ; preds = %12
  %20 = load ptr, ptr @global_config_context, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.config_context_t, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  store i64 %22, ptr %23, align 8, !tbaa !16
  br label %37

24:                                               ; preds = %12
  %25 = load ptr, ptr @global_config_context, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.config_context_t, ptr %25, i32 0, i32 2
  %27 = load i8, ptr %26, align 8, !tbaa !17, !range !18, !noundef !19
  %28 = trunc i8 %27 to i1
  %29 = load ptr, ptr %5, align 8, !tbaa !9
  %30 = zext i1 %28 to i8
  store i8 %30, ptr %29, align 1, !tbaa !20
  br label %37

31:                                               ; preds = %12
  %32 = load ptr, ptr @global_config_context, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.config_context_t, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 4, !tbaa !21
  %35 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 %34, ptr %35, align 4, !tbaa !5
  br label %37

36:                                               ; preds = %12
  store i32 -1, ptr %3, align 4
  br label %38

37:                                               ; preds = %31, %24, %19, %14
  store i32 0, ptr %3, align 4
  br label %38

38:                                               ; preds = %37, %36, %11
  %39 = load i32, ptr %3, align 4
  ret i32 %39
}

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


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

@global_config_context = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 -1, 1) i32 @geometric_get_config(i32 noundef %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @global_config_context, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  %5 = icmp ne ptr %1, null
  %or.cond = and i1 %5, %4
  br i1 %or.cond, label %6, label %18

6:                                                ; preds = %2
  switch i32 %0, label %18 [
    i32 0, label %7
    i32 1, label %9
    i32 2, label %12
    i32 3, label %15
  ]

7:                                                ; preds = %6
  %8 = load i32, ptr %3, align 8, !tbaa !9
  store i32 %8, ptr %1, align 4, !tbaa !14
  br label %18

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %3, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !15
  store i64 %11, ptr %1, align 8, !tbaa !16
  br label %18

12:                                               ; preds = %6
  %13 = getelementptr inbounds i8, ptr %3, i64 16
  %14 = load i8, ptr %13, align 8, !tbaa !17, !range !18, !noundef !19
  store i8 %14, ptr %1, align 1, !tbaa !20
  br label %18

15:                                               ; preds = %6
  %16 = getelementptr inbounds i8, ptr %3, i64 20
  %17 = load i32, ptr %16, align 4, !tbaa !21
  store i32 %17, ptr %1, align 4, !tbaa !14
  br label %18

18:                                               ; preds = %7, %9, %12, %15, %6, %2
  %.0 = phi i32 [ -1, %2 ], [ -1, %6 ], [ 0, %15 ], [ 0, %12 ], [ 0, %9 ], [ 0, %7 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !12, i64 8, !13, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !12, i64 8}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !13, i64 16}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!13, !13, i64 0}
!21 = !{!10, !11, i64 20}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass