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

@streams = external hidden global [16 x %struct.Stream], align 16
@is_initialized = external hidden global i8, align 1

; 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
define dso_local i32 @geometric_core_create_stream(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i32 -1, ptr %2, align 4
  br label %69

10:                                               ; preds = %1
  %11 = load i8, ptr @is_initialized, align 1, !tbaa !9, !range !11, !noundef !12
  %12 = trunc i8 %11 to i1
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  store i32 -4, ptr %2, align 4
  br label %69

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 -1, ptr %4, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !13
  br label %15

15:                                               ; preds = %36, %14
  %16 = load i32, ptr %5, align 4, !tbaa !13
  %17 = icmp slt i32 %16, 16
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  store i32 2, ptr %6, align 4
  br label %39

19:                                               ; preds = %15
  %20 = load i32, ptr %5, align 4, !tbaa !13
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.Stream, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 16, !tbaa !15
  %25 = icmp ne ptr %24, null
  br i1 %25, label %35, label %26

26:                                               ; preds = %19
  %27 = load i32, ptr %5, align 4, !tbaa !13
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.Stream, ptr %29, i32 0, i32 1
  %31 = load i8, ptr %30, align 8, !tbaa !17, !range !11, !noundef !12
  %32 = trunc i8 %31 to i1
  br i1 %32, label %35, label %33

33:                                               ; preds = %26
  %34 = load i32, ptr %5, align 4, !tbaa !13
  store i32 %34, ptr %4, align 4, !tbaa !13
  store i32 2, ptr %6, align 4
  br label %39

35:                                               ; preds = %26, %19
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %5, align 4, !tbaa !13
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %5, align 4, !tbaa !13
  br label %15, !llvm.loop !18

39:                                               ; preds = %33, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %4, align 4, !tbaa !13
  %42 = icmp eq i32 %41, -1
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store i32 -14, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %68

44:                                               ; preds = %40
  %45 = call ptr @geometric_allocate(i64 noundef 8)
  %46 = load i32, ptr %4, align 4, !tbaa !13
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.Stream, ptr %48, i32 0, i32 0
  store ptr %45, ptr %49, align 16, !tbaa !15
  %50 = load i32, ptr %4, align 4, !tbaa !13
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.Stream, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 16, !tbaa !15
  %55 = icmp ne ptr %54, null
  br i1 %55, label %57, label %56

56:                                               ; preds = %44
  store i32 -2, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %68

57:                                               ; preds = %44
  %58 = load i32, ptr %4, align 4, !tbaa !13
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.Stream, ptr %60, i32 0, i32 1
  store i8 1, ptr %61, align 8, !tbaa !17
  %62 = load i32, ptr %4, align 4, !tbaa !13
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.Stream, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 16, !tbaa !15
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %66, ptr %67, align 8, !tbaa !5
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %68

68:                                               ; preds = %57, %56, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %69

69:                                               ; preds = %68, %13, %9
  %70 = load i32, ptr %2, align 4
  ret i32 %70
}

declare ptr @geometric_allocate(i64 noundef) #2

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 = { "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 }

!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 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"Stream", !6, i64 0, !10, i64 8}
!17 = !{!16, !10, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"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.Stream = type { ptr, i8 }

@streams = external hidden local_unnamed_addr global [16 x %struct.Stream], align 16
@is_initialized = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -14, 1) i32 @geometric_core_create_stream(ptr noundef writeonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.thread, label %3

3:                                                ; preds = %1
  %4 = load i8, ptr @is_initialized, align 1, !tbaa !5, !range !9, !noundef !10
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %.preheader.preheader, label %.thread

.preheader.preheader:                             ; preds = %3
  %6 = load ptr, ptr @streams, align 16, !tbaa !11
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %7, label %.preheader.1

7:                                                ; preds = %.preheader.preheader
  %8 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 8), align 8, !tbaa !14, !range !9, !noundef !10
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %.preheader.1, label %70

.preheader.1:                                     ; preds = %.preheader.preheader, %7
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 16), align 16, !tbaa !11
  %.not.1 = icmp eq ptr %10, null
  br i1 %.not.1, label %11, label %.preheader.2

11:                                               ; preds = %.preheader.1
  %12 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 24), align 8, !tbaa !14, !range !9, !noundef !10
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %.preheader.2, label %70

.preheader.2:                                     ; preds = %11, %.preheader.1
  %14 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 32), align 16, !tbaa !11
  %.not.2 = icmp eq ptr %14, null
  br i1 %.not.2, label %15, label %.preheader.3

15:                                               ; preds = %.preheader.2
  %16 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 40), align 8, !tbaa !14, !range !9, !noundef !10
  %17 = trunc nuw i8 %16 to i1
  br i1 %17, label %.preheader.3, label %70

.preheader.3:                                     ; preds = %15, %.preheader.2
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 48), align 16, !tbaa !11
  %.not.3 = icmp eq ptr %18, null
  br i1 %.not.3, label %19, label %.preheader.4

19:                                               ; preds = %.preheader.3
  %20 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 56), align 8, !tbaa !14, !range !9, !noundef !10
  %21 = trunc nuw i8 %20 to i1
  br i1 %21, label %.preheader.4, label %70

.preheader.4:                                     ; preds = %19, %.preheader.3
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 64), align 16, !tbaa !11
  %.not.4 = icmp eq ptr %22, null
  br i1 %.not.4, label %23, label %.preheader.5

23:                                               ; preds = %.preheader.4
  %24 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 72), align 8, !tbaa !14, !range !9, !noundef !10
  %25 = trunc nuw i8 %24 to i1
  br i1 %25, label %.preheader.5, label %70

.preheader.5:                                     ; preds = %23, %.preheader.4
  %26 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 80), align 16, !tbaa !11
  %.not.5 = icmp eq ptr %26, null
  br i1 %.not.5, label %27, label %.preheader.6

27:                                               ; preds = %.preheader.5
  %28 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 88), align 8, !tbaa !14, !range !9, !noundef !10
  %29 = trunc nuw i8 %28 to i1
  br i1 %29, label %.preheader.6, label %70

.preheader.6:                                     ; preds = %27, %.preheader.5
  %30 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 96), align 16, !tbaa !11
  %.not.6 = icmp eq ptr %30, null
  br i1 %.not.6, label %31, label %.preheader.7

31:                                               ; preds = %.preheader.6
  %32 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 104), align 8, !tbaa !14, !range !9, !noundef !10
  %33 = trunc nuw i8 %32 to i1
  br i1 %33, label %.preheader.7, label %70

.preheader.7:                                     ; preds = %31, %.preheader.6
  %34 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 112), align 16, !tbaa !11
  %.not.7 = icmp eq ptr %34, null
  br i1 %.not.7, label %35, label %.preheader.8

35:                                               ; preds = %.preheader.7
  %36 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 120), align 8, !tbaa !14, !range !9, !noundef !10
  %37 = trunc nuw i8 %36 to i1
  br i1 %37, label %.preheader.8, label %70

.preheader.8:                                     ; preds = %35, %.preheader.7
  %38 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 128), align 16, !tbaa !11
  %.not.8 = icmp eq ptr %38, null
  br i1 %.not.8, label %39, label %.preheader.9

39:                                               ; preds = %.preheader.8
  %40 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 136), align 8, !tbaa !14, !range !9, !noundef !10
  %41 = trunc nuw i8 %40 to i1
  br i1 %41, label %.preheader.9, label %70

.preheader.9:                                     ; preds = %39, %.preheader.8
  %42 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 144), align 16, !tbaa !11
  %.not.9 = icmp eq ptr %42, null
  br i1 %.not.9, label %43, label %.preheader.10

43:                                               ; preds = %.preheader.9
  %44 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 152), align 8, !tbaa !14, !range !9, !noundef !10
  %45 = trunc nuw i8 %44 to i1
  br i1 %45, label %.preheader.10, label %70

.preheader.10:                                    ; preds = %43, %.preheader.9
  %46 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 160), align 16, !tbaa !11
  %.not.10 = icmp eq ptr %46, null
  br i1 %.not.10, label %47, label %.preheader.11

47:                                               ; preds = %.preheader.10
  %48 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 168), align 8, !tbaa !14, !range !9, !noundef !10
  %49 = trunc nuw i8 %48 to i1
  br i1 %49, label %.preheader.11, label %70

.preheader.11:                                    ; preds = %47, %.preheader.10
  %50 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 176), align 16, !tbaa !11
  %.not.11 = icmp eq ptr %50, null
  br i1 %.not.11, label %51, label %.preheader.12

51:                                               ; preds = %.preheader.11
  %52 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 184), align 8, !tbaa !14, !range !9, !noundef !10
  %53 = trunc nuw i8 %52 to i1
  br i1 %53, label %.preheader.12, label %70

.preheader.12:                                    ; preds = %51, %.preheader.11
  %54 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 192), align 16, !tbaa !11
  %.not.12 = icmp eq ptr %54, null
  br i1 %.not.12, label %55, label %.preheader.13

55:                                               ; preds = %.preheader.12
  %56 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 200), align 8, !tbaa !14, !range !9, !noundef !10
  %57 = trunc nuw i8 %56 to i1
  br i1 %57, label %.preheader.13, label %70

.preheader.13:                                    ; preds = %55, %.preheader.12
  %58 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 208), align 16, !tbaa !11
  %.not.13 = icmp eq ptr %58, null
  br i1 %.not.13, label %59, label %.preheader.14

59:                                               ; preds = %.preheader.13
  %60 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 216), align 8, !tbaa !14, !range !9, !noundef !10
  %61 = trunc nuw i8 %60 to i1
  br i1 %61, label %.preheader.14, label %70

.preheader.14:                                    ; preds = %59, %.preheader.13
  %62 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 224), align 16, !tbaa !11
  %.not.14 = icmp eq ptr %62, null
  br i1 %.not.14, label %63, label %.preheader.15

63:                                               ; preds = %.preheader.14
  %64 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 232), align 8, !tbaa !14, !range !9, !noundef !10
  %65 = trunc nuw i8 %64 to i1
  br i1 %65, label %.preheader.15, label %70

.preheader.15:                                    ; preds = %63, %.preheader.14
  %66 = load ptr, ptr getelementptr inbounds (i8, ptr @streams, i64 240), align 16, !tbaa !11
  %.not.15 = icmp eq ptr %66, null
  br i1 %.not.15, label %67, label %.thread

67:                                               ; preds = %.preheader.15
  %68 = load i8, ptr getelementptr inbounds (i8, ptr @streams, i64 248), align 8, !tbaa !14, !range !9, !noundef !10
  %69 = trunc nuw i8 %68 to i1
  br i1 %69, label %.thread, label %70

70:                                               ; preds = %67, %63, %59, %55, %51, %47, %43, %39, %35, %31, %27, %23, %19, %15, %11, %7
  %.018.lcssa.wide = phi i64 [ 0, %7 ], [ 1, %11 ], [ 2, %15 ], [ 3, %19 ], [ 4, %23 ], [ 5, %27 ], [ 6, %31 ], [ 7, %35 ], [ 8, %39 ], [ 9, %43 ], [ 10, %47 ], [ 11, %51 ], [ 12, %55 ], [ 13, %59 ], [ 14, %63 ], [ 15, %67 ]
  %71 = tail call ptr @geometric_allocate(i64 noundef 8) #2
  %72 = getelementptr inbounds [16 x %struct.Stream], ptr @streams, i64 0, i64 %.018.lcssa.wide
  store ptr %71, ptr %72, align 16, !tbaa !11
  %.not15 = icmp eq ptr %71, null
  br i1 %.not15, label %.thread, label %73

73:                                               ; preds = %70
  %74 = getelementptr inbounds i8, ptr %72, i64 8
  store i8 1, ptr %74, align 8, !tbaa !14
  store ptr %71, ptr %0, align 8, !tbaa !15
  br label %.thread

.thread:                                          ; preds = %.preheader.15, %67, %73, %70, %3, %1
  %.1 = phi i32 [ -1, %1 ], [ -4, %3 ], [ 0, %73 ], [ -2, %70 ], [ -14, %67 ], [ -14, %.preheader.15 ]
  ret i32 %.1
}

declare ptr @geometric_allocate(i64 noundef) local_unnamed_addr #1

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 = { "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 = !{!"_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 = !{!"Stream", !13, i64 0, !6, i64 8}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!13, !13, i64 0}


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