; 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_set_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 %5, align 8, !tbaa !9
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = load ptr, ptr @global_config_context, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.config_context_t, ptr %17, i32 0, i32 0
  store i32 %16, ptr %18, align 8, !tbaa !11
  br label %37

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

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

31:                                               ; preds = %12
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = load ptr, ptr @global_config_context, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.config_context_t, ptr %34, i32 0, i32 3
  store i32 %33, ptr %35, align 4, !tbaa !21
  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 = !{!13, !13, i64 0}
!16 = !{!12, !13, i64 8}
!17 = !{!14, !14, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!12, !14, i64 16}
!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(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 -1, 1) i32 @geometric_set_config(i32 noundef %0, ptr noundef readonly %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 %1, align 4, !tbaa !9
  store i32 %8, ptr %3, align 8, !tbaa !11
  br label %18

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

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

15:                                               ; preds = %6
  %16 = load i32, ptr %1, align 4, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 %16, ptr %17, align 4, !tbaa !21
  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(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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !13, i64 8, !14, i64 16, !10, i64 20}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !13, i64 8}
!17 = !{!14, !14, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!12, !14, i64 16}
!21 = !{!12, !10, i64 20}


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