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

; 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.computational_graph_t = type { ptr, i64, i64, ptr, ptr, i64, i64, 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
declare void @free(ptr noundef) #1

; 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 zeroext i1 @validate_graph(ptr noundef %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %23

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.computational_graph_t, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %23

18:                                               ; preds = %13
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.computational_graph_t, ptr %19, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !12
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %18, %13, %1
  store i1 false, ptr %2, align 1
  br label %109

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.computational_graph_t, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !12
  %28 = call noalias ptr @calloc(i64 noundef %27, i64 noundef 1) #6
  store ptr %28, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.computational_graph_t, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !12
  %32 = call noalias ptr @calloc(i64 noundef %31, i64 noundef 1) #6
  store ptr %32, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %38

35:                                               ; preds = %24
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %41, label %38

38:                                               ; preds = %35, %24
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %39) #5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %40) #5
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %108

41:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  store i8 1, ptr %7, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !15
  br label %42

42:                                               ; preds = %100, %41
  %43 = load i64, ptr %8, align 8, !tbaa !15
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.computational_graph_t, ptr %44, i32 0, i32 5
  %46 = load i64, ptr %45, align 8, !tbaa !16
  %47 = icmp ult i64 %43, %46
  br i1 %47, label %49, label %48

48:                                               ; preds = %42
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %103

49:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.computational_graph_t, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = load i64, ptr %8, align 8, !tbaa !15
  %54 = getelementptr inbounds ptr, ptr %52, i64 %53
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  store ptr %55, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !15
  br label %56

56:                                               ; preds = %95, %49
  %57 = load i64, ptr %10, align 8, !tbaa !15
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.computational_graph_t, ptr %58, i32 0, i32 1
  %60 = load i64, ptr %59, align 8, !tbaa !12
  %61 = icmp ult i64 %57, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %56
  store i32 5, ptr %6, align 4
  br label %98

63:                                               ; preds = %56
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.computational_graph_t, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !9
  %67 = load i64, ptr %10, align 8, !tbaa !15
  %68 = getelementptr inbounds ptr, ptr %66, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = icmp eq ptr %69, %70
  br i1 %71, label %72, label %94

72:                                               ; preds = %63
  %73 = load i8, ptr %7, align 1, !tbaa !13, !range !18, !noundef !19
  %74 = trunc i8 %73 to i1
  br i1 %74, label %76, label %75

75:                                               ; preds = %72
  store i32 5, ptr %6, align 4
  br label %98

76:                                               ; preds = %72
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.computational_graph_t, ptr %78, i32 0, i32 1
  %80 = load i64, ptr %79, align 8, !tbaa !12
  %81 = mul i64 %80, 1
  call void @llvm.memset.p0.i64(ptr align 1 %77, i8 0, i64 %81, i1 false)
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.computational_graph_t, ptr %83, i32 0, i32 1
  %85 = load i64, ptr %84, align 8, !tbaa !12
  %86 = mul i64 %85, 1
  call void @llvm.memset.p0.i64(ptr align 1 %82, i8 0, i64 %86, i1 false)
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = load i64, ptr %10, align 8, !tbaa !15
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = call zeroext i1 @has_cycle(ptr noundef %87, i64 noundef %88, ptr noundef %89, ptr noundef %90)
  %92 = xor i1 %91, true
  %93 = zext i1 %92 to i8
  store i8 %93, ptr %7, align 1, !tbaa !13
  store i32 5, ptr %6, align 4
  br label %98

94:                                               ; preds = %63
  br label %95

95:                                               ; preds = %94
  %96 = load i64, ptr %10, align 8, !tbaa !15
  %97 = add i64 %96, 1
  store i64 %97, ptr %10, align 8, !tbaa !15
  br label %56, !llvm.loop !20

98:                                               ; preds = %76, %75, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %99

99:                                               ; preds = %98
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %100

100:                                              ; preds = %99
  %101 = load i64, ptr %8, align 8, !tbaa !15
  %102 = add i64 %101, 1
  store i64 %102, ptr %8, align 8, !tbaa !15
  br label %42, !llvm.loop !22

103:                                              ; preds = %48
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %104) #5
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %105) #5
  %106 = load i8, ptr %7, align 1, !tbaa !13, !range !18, !noundef !19
  %107 = trunc i8 %106 to i1
  store i1 %107, ptr %2, align 1
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  br label %108

108:                                              ; preds = %103, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %109

109:                                              ; preds = %108, %23
  %110 = load i1, ptr %2, align 1
  ret i1 %110
}

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

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @has_cycle(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 allocsize(0,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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,1) }

!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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 48, !6, i64 56}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 40}
!17 = !{!10, !6, i64 24}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @validate_graph(ptr noundef %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %38, label %2

2:                                                ; preds = %1
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not42 = icmp eq ptr %3, null
  br i1 %.not42, label %38, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !11
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %38, label %8

8:                                                ; preds = %4
  %9 = tail call noalias ptr @calloc(i64 noundef %6, i64 noundef 1) #4
  %10 = tail call noalias ptr @calloc(i64 noundef %6, i64 noundef 1) #4
  %11 = icmp ne ptr %9, null
  %12 = icmp ne ptr %10, null
  %or.cond = and i1 %11, %12
  br i1 %or.cond, label %.preheader, label %.sink.split

.preheader:                                       ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %.not49 = icmp eq i64 %14, 0
  br i1 %.not49, label %.sink.split, label %.lr.ph48.split.preheader

.lr.ph48.split.preheader:                         ; preds = %.preheader
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  br label %.lr.ph48.split

._crit_edge.loopexit52:                           ; preds = %.loopexit
  %16 = trunc nuw i8 %.136 to i1
  br label %.sink.split

.lr.ph48.split:                                   ; preds = %.lr.ph48.split.preheader, %.loopexit
  %17 = phi i64 [ %35, %.loopexit ], [ %14, %.lr.ph48.split.preheader ]
  %.03447 = phi i64 [ %36, %.loopexit ], [ 0, %.lr.ph48.split.preheader ]
  %.03546 = phi i8 [ %.136, %.loopexit ], [ 1, %.lr.ph48.split.preheader ]
  %18 = load ptr, ptr %15, align 8, !tbaa !13
  %19 = getelementptr inbounds ptr, ptr %18, i64 %.03447
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = load i64, ptr %5, align 8, !tbaa !11
  %.not51 = icmp eq i64 %21, 0
  br i1 %.not51, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph48.split
  %22 = load ptr, ptr %0, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %.lr.ph, %33
  %.045 = phi i64 [ 0, %.lr.ph ], [ %34, %33 ]
  %24 = getelementptr inbounds ptr, ptr %22, i64 %.045
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = icmp eq ptr %25, %20
  br i1 %26, label %27, label %33

27:                                               ; preds = %23
  %28 = trunc nuw i8 %.03546 to i1
  br i1 %28, label %29, label %.loopexit

29:                                               ; preds = %27
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %9, i8 0, i64 %21, i1 false)
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %10, i8 0, i64 %21, i1 false)
  %30 = tail call zeroext i1 @has_cycle(ptr noundef nonnull %0, i64 noundef %.045, ptr noundef nonnull %9, ptr noundef nonnull %10)
  %31 = xor i1 %30, true
  %32 = zext i1 %31 to i8
  %.pre = load i64, ptr %13, align 8, !tbaa !12
  br label %.loopexit

33:                                               ; preds = %23
  %34 = add nuw i64 %.045, 1
  %exitcond.not = icmp eq i64 %34, %21
  br i1 %exitcond.not, label %.loopexit, label %23, !llvm.loop !15

.loopexit:                                        ; preds = %33, %.lr.ph48.split, %27, %29
  %35 = phi i64 [ %.pre, %29 ], [ %17, %27 ], [ %17, %.lr.ph48.split ], [ %17, %33 ]
  %.136 = phi i8 [ %32, %29 ], [ %.03546, %27 ], [ %.03546, %.lr.ph48.split ], [ %.03546, %33 ]
  %36 = add nuw i64 %.03447, 1
  %37 = icmp ult i64 %36, %35
  br i1 %37, label %.lr.ph48.split, label %._crit_edge.loopexit52, !llvm.loop !17

.sink.split:                                      ; preds = %.preheader, %._crit_edge.loopexit52, %8
  %.1.ph = phi i1 [ false, %8 ], [ true, %.preheader ], [ %16, %._crit_edge.loopexit52 ]
  tail call void @free(ptr noundef %9) #5
  tail call void @free(ptr noundef %10) #5
  br label %38

38:                                               ; preds = %.sink.split, %1, %2, %4
  %.1 = phi i1 [ false, %4 ], [ false, %2 ], [ false, %1 ], [ %.1.ph, %.sink.split ]
  ret i1 %.1
}

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

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @has_cycle(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind allocsize(0,1) }
attributes #5 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 48, !7, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 40}
!13 = !{!6, !7, i64 24}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16, !18}
!18 = !{!"llvm.loop.unswitch.partial.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass