; LLVM IR from stivalaa/EstimNetDirected :: src (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.graph_s = type { i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i32, ptr, ptr, i32, ptr, ptr, i32, ptr, ptr, ptr, i32, i32, i32, i32, i32, ptr, i32, i32, ptr, ptr, i32, ptr, i32, ptr, ptr, i32, i32, ptr, i32, ptr }
%struct.nodepair_s = type { i32, i32 }

; 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 @num_loops(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.graph_s, ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %42

9:                                                ; preds = %1
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %38, %9
  %11 = load i32, ptr %3, align 4, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.graph_s, ptr %12, i32 0, i32 3
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = icmp ult i32 %11, %14
  br i1 %15, label %16, label %41

16:                                               ; preds = %10
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.graph_s, ptr %17, i32 0, i32 8
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds %struct.nodepair_s, ptr %19, i64 %21
  %23 = getelementptr inbounds %struct.nodepair_s, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 4, !tbaa !15
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.graph_s, ptr %25, i32 0, i32 8
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds %struct.nodepair_s, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct.nodepair_s, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !17
  %33 = icmp eq i32 %24, %32
  br i1 %33, label %34, label %37

34:                                               ; preds = %16
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = add i32 %35, 1
  store i32 %36, ptr %4, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %34, %16
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = add i32 %39, 1
  store i32 %40, ptr %3, align 4, !tbaa !9
  br label %10, !llvm.loop !18

41:                                               ; preds = %10
  br label %75

42:                                               ; preds = %1
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %71, %42
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.graph_s, ptr %45, i32 0, i32 9
  %47 = load i32, ptr %46, align 8, !tbaa !20
  %48 = icmp ult i32 %44, %47
  br i1 %48, label %49, label %74

49:                                               ; preds = %43
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.graph_s, ptr %50, i32 0, i32 12
  %52 = load ptr, ptr %51, align 8, !tbaa !21
  %53 = load i32, ptr %3, align 4, !tbaa !9
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds %struct.nodepair_s, ptr %52, i64 %54
  %56 = getelementptr inbounds %struct.nodepair_s, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 4, !tbaa !15
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.graph_s, ptr %58, i32 0, i32 12
  %60 = load ptr, ptr %59, align 8, !tbaa !21
  %61 = load i32, ptr %3, align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds %struct.nodepair_s, ptr %60, i64 %62
  %64 = getelementptr inbounds %struct.nodepair_s, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !17
  %66 = icmp eq i32 %57, %65
  br i1 %66, label %67, label %70

67:                                               ; preds = %49
  %68 = load i32, ptr %4, align 4, !tbaa !9
  %69 = add i32 %68, 1
  store i32 %69, ptr %4, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %67, %49
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %3, align 4, !tbaa !9
  %73 = add i32 %72, 1
  store i32 %73, ptr %3, align 4, !tbaa !9
  br label %43, !llvm.loop !22

74:                                               ; preds = %43
  br label %75

75:                                               ; preds = %74, %41
  %76 = load i32, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %76
}

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"graph_s", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !10, i64 92, !10, i64 96, !6, i64 104, !6, i64 112, !10, i64 120, !6, i64 128, !6, i64 136, !10, i64 144, !6, i64 152, !6, i64 160, !10, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !10, i64 200, !10, i64 204, !10, i64 208, !10, i64 212, !10, i64 216, !6, i64 224, !10, i64 232, !10, i64 236, !6, i64 240, !6, i64 248, !10, i64 256, !6, i64 264, !10, i64 272, !6, i64 280, !6, i64 288, !10, i64 296, !10, i64 300, !6, i64 304, !10, i64 312, !6, i64 320}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !6, i64 48}
!15 = !{!16, !10, i64 0}
!16 = !{!"nodepair_s", !10, i64 0, !10, i64 4}
!17 = !{!16, !10, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!12, !10, i64 56}
!21 = !{!12, !6, i64 80}
!22 = distinct !{!22, !19}


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

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @num_loops(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %.preheader, label %.preheader20

.preheader20:                                     ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !11
  %.not28 = icmp eq i32 %5, 0
  br i1 %.not28, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader20
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %wide.trip.count = zext i32 %5 to i64
  %min.iters.check = icmp ult i32 %5, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %.023.ph = phi i32 [ 0, %.lr.ph ], [ %18, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %15, %vector.body ]
  %vec.phi39 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %16, %vector.body ]
  %8 = or disjoint i64 %index, 4
  %9 = getelementptr inbounds %struct.nodepair_s, ptr %7, i64 %index
  %10 = getelementptr inbounds %struct.nodepair_s, ptr %7, i64 %8
  %wide.vec = load <8 x i32>, ptr %9, align 4, !tbaa !13
  %wide.vec40 = load <8 x i32>, ptr %10, align 4, !tbaa !13
  %strided.vec = shufflevector <8 x i32> %wide.vec, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec41 = shufflevector <8 x i32> %wide.vec40, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec42 = shufflevector <8 x i32> %wide.vec, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %strided.vec43 = shufflevector <8 x i32> %wide.vec40, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %11 = icmp eq <4 x i32> %strided.vec, %strided.vec42
  %12 = icmp eq <4 x i32> %strided.vec41, %strided.vec43
  %13 = zext <4 x i1> %11 to <4 x i32>
  %14 = zext <4 x i1> %12 to <4 x i32>
  %15 = add <4 x i32> %vec.phi, %13
  %16 = add <4 x i32> %vec.phi39, %14
  %index.next = add nuw i64 %index, 8
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %16, %15
  %18 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

.preheader:                                       ; preds = %1
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %20 = load i32, ptr %19, align 8, !tbaa !18
  %.not29 = icmp eq i32 %20, 0
  br i1 %.not29, label %.loopexit, label %.lr.ph26

.lr.ph26:                                         ; preds = %.preheader
  %21 = getelementptr inbounds i8, ptr %0, i64 80
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %wide.trip.count35 = zext i32 %20 to i64
  %min.iters.check46 = icmp ult i32 %20, 8
  br i1 %min.iters.check46, label %scalar.ph45.preheader, label %vector.ph47

scalar.ph45.preheader:                            ; preds = %middle.block44, %.lr.ph26
  %indvars.iv32.ph = phi i64 [ 0, %.lr.ph26 ], [ %n.vec49, %middle.block44 ]
  %.225.ph = phi i32 [ 0, %.lr.ph26 ], [ %33, %middle.block44 ]
  br label %scalar.ph45

vector.ph47:                                      ; preds = %.lr.ph26
  %n.vec49 = and i64 %wide.trip.count35, 4294967288
  br label %vector.body51

vector.body51:                                    ; preds = %vector.body51, %vector.ph47
  %index52 = phi i64 [ 0, %vector.ph47 ], [ %index.next61, %vector.body51 ]
  %vec.phi53 = phi <4 x i32> [ zeroinitializer, %vector.ph47 ], [ %30, %vector.body51 ]
  %vec.phi54 = phi <4 x i32> [ zeroinitializer, %vector.ph47 ], [ %31, %vector.body51 ]
  %23 = or disjoint i64 %index52, 4
  %24 = getelementptr inbounds %struct.nodepair_s, ptr %22, i64 %index52
  %25 = getelementptr inbounds %struct.nodepair_s, ptr %22, i64 %23
  %wide.vec55 = load <8 x i32>, ptr %24, align 4, !tbaa !13
  %wide.vec56 = load <8 x i32>, ptr %25, align 4, !tbaa !13
  %strided.vec57 = shufflevector <8 x i32> %wide.vec55, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec58 = shufflevector <8 x i32> %wide.vec56, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec59 = shufflevector <8 x i32> %wide.vec55, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %strided.vec60 = shufflevector <8 x i32> %wide.vec56, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %26 = icmp eq <4 x i32> %strided.vec57, %strided.vec59
  %27 = icmp eq <4 x i32> %strided.vec58, %strided.vec60
  %28 = zext <4 x i1> %26 to <4 x i32>
  %29 = zext <4 x i1> %27 to <4 x i32>
  %30 = add <4 x i32> %vec.phi53, %28
  %31 = add <4 x i32> %vec.phi54, %29
  %index.next61 = add nuw i64 %index52, 8
  %32 = icmp eq i64 %index.next61, %n.vec49
  br i1 %32, label %middle.block44, label %vector.body51, !llvm.loop !20

middle.block44:                                   ; preds = %vector.body51
  %bin.rdx62 = add <4 x i32> %31, %30
  %33 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx62)
  %cmp.n63 = icmp eq i64 %n.vec49, %wide.trip.count35
  br i1 %cmp.n63, label %.loopexit, label %scalar.ph45.preheader

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %.023 = phi i32 [ %spec.select, %scalar.ph ], [ %.023.ph, %scalar.ph.preheader ]
  %34 = getelementptr inbounds %struct.nodepair_s, ptr %7, i64 %indvars.iv
  %35 = load i32, ptr %34, align 4, !tbaa !21
  %36 = getelementptr inbounds i8, ptr %34, i64 4
  %37 = load i32, ptr %36, align 4, !tbaa !23
  %38 = icmp eq i32 %35, %37
  %39 = zext i1 %38 to i32
  %spec.select = add i32 %.023, %39
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !24

scalar.ph45:                                      ; preds = %scalar.ph45.preheader, %scalar.ph45
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %scalar.ph45 ], [ %indvars.iv32.ph, %scalar.ph45.preheader ]
  %.225 = phi i32 [ %spec.select19, %scalar.ph45 ], [ %.225.ph, %scalar.ph45.preheader ]
  %40 = getelementptr inbounds %struct.nodepair_s, ptr %22, i64 %indvars.iv32
  %41 = load i32, ptr %40, align 4, !tbaa !21
  %42 = getelementptr inbounds i8, ptr %40, i64 4
  %43 = load i32, ptr %42, align 4, !tbaa !23
  %44 = icmp eq i32 %41, %43
  %45 = zext i1 %44 to i32
  %spec.select19 = add i32 %.225, %45
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond36.not = icmp eq i64 %indvars.iv.next33, %wide.trip.count35
  br i1 %exitcond36.not, label %.loopexit, label %scalar.ph45, !llvm.loop !25

.loopexit:                                        ; preds = %scalar.ph, %scalar.ph45, %middle.block, %middle.block44, %.preheader20, %.preheader
  %.4 = phi i32 [ 0, %.preheader ], [ 0, %.preheader20 ], [ %33, %middle.block44 ], [ %18, %middle.block ], [ %spec.select19, %scalar.ph45 ], [ %spec.select, %scalar.ph ]
  ret i32 %.4
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #1

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 4}
!6 = !{!"graph_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !7, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !7, i64 88, !7, i64 92, !7, i64 96, !10, i64 104, !10, i64 112, !7, i64 120, !10, i64 128, !10, i64 136, !7, i64 144, !10, i64 152, !10, i64 160, !7, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !7, i64 200, !7, i64 204, !7, i64 208, !7, i64 212, !7, i64 216, !10, i64 224, !7, i64 232, !7, i64 236, !10, i64 240, !10, i64 248, !7, i64 256, !10, i64 264, !7, i64 272, !10, i64 280, !10, i64 288, !7, i64 296, !7, i64 300, !10, i64 304, !7, i64 312, !10, i64 320}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 12}
!12 = !{!6, !10, i64 48}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = !{!6, !7, i64 56}
!19 = !{!6, !10, i64 80}
!20 = distinct !{!20, !15, !16, !17}
!21 = !{!22, !7, i64 0}
!22 = !{!"nodepair_s", !7, i64 0, !7, i64 4}
!23 = !{!22, !7, i64 4}
!24 = distinct !{!24, !15, !17, !16}
!25 = distinct !{!25, !15, !17, !16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass