; LLVM IR from TyrantLucifer/DataStructure :: Graph/C (Prim)

; 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 = type { ptr, ptr, i32, i32 }
%struct.Edge = type { i8, i32 }

@.str = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @initEdge(ptr noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @getMinEdge(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @prim(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = call ptr @initEdge(ptr noundef %10, i32 noundef %11)
  store ptr %12, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %112, %2
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Graph, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = sub nsw i32 %17, 1
  %19 = icmp slt i32 %14, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %13
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %115

21:                                               ; preds = %13
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = call i32 @getMinEdge(ptr noundef %22, ptr noundef %23)
  store i32 %24, ptr %5, align 4, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.Edge, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct.Edge, ptr %28, i32 0, i32 0
  %30 = load i8, ptr %29, align 4, !tbaa !13
  %31 = sext i8 %30 to i32
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Graph, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %34, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !16
  %39 = sext i8 %38 to i32
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.Edge, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct.Edge, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !17
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %31, i32 noundef %39, i32 noundef %45)
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct.Edge, ptr %47, i64 %49
  %51 = getelementptr inbounds %struct.Edge, ptr %50, i32 0, i32 1
  store i32 0, ptr %51, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %108, %21
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Graph, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 8, !tbaa !11
  %57 = icmp slt i32 %53, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %52
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %111

59:                                               ; preds = %52
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Graph, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !18
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds ptr, ptr %62, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds %struct.Edge, ptr %71, i64 %73
  %75 = getelementptr inbounds %struct.Edge, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !17
  %77 = icmp slt i32 %70, %76
  br i1 %77, label %78, label %107

78:                                               ; preds = %59
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.Graph, ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !18
  %82 = load i32, ptr %5, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds ptr, ptr %81, i64 %83
  %85 = load ptr, ptr %84, align 8, !tbaa !5
  %86 = load i32, ptr %9, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i32, ptr %85, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !9
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load i32, ptr %9, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds %struct.Edge, ptr %90, i64 %92
  %94 = getelementptr inbounds %struct.Edge, ptr %93, i32 0, i32 1
  store i32 %89, ptr %94, align 4, !tbaa !17
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.Graph, ptr %95, i32 0, i32 0
  %97 = load ptr, ptr %96, align 8, !tbaa !15
  %98 = load i32, ptr %5, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds i8, ptr %97, i64 %99
  %101 = load i8, ptr %100, align 1, !tbaa !16
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = load i32, ptr %9, align 4, !tbaa !9
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds %struct.Edge, ptr %102, i64 %104
  %106 = getelementptr inbounds %struct.Edge, ptr %105, i32 0, i32 0
  store i8 %101, ptr %106, align 4, !tbaa !13
  br label %107

107:                                              ; preds = %78, %59
  br label %108

108:                                              ; preds = %107
  %109 = load i32, ptr %9, align 4, !tbaa !9
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %9, align 4, !tbaa !9
  br label %52, !llvm.loop !19

111:                                              ; preds = %58
  br label %112

112:                                              ; preds = %111
  %113 = load i32, ptr %7, align 4, !tbaa !9
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %7, align 4, !tbaa !9
  br label %13, !llvm.loop !21

115:                                              ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

declare i32 @printf(ptr noundef, ...) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"Graph", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20}
!13 = !{!14, !7, i64 0}
!14 = !{!"Edge", !7, i64 0, !10, i64 4}
!15 = !{!12, !6, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!14, !10, i64 4}
!18 = !{!12, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !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"

%struct.Edge = type { i8, i32 }

@.str = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @initEdge(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @getMinEdge(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @prim(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @initEdge(ptr noundef %0, i32 noundef %1)
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %.lr.ph36, label %._crit_edge37

.lr.ph36:                                         ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  br label %8

._crit_edge37:                                    ; preds = %._crit_edge, %2
  ret void

8:                                                ; preds = %.lr.ph36, %._crit_edge
  %.03134 = phi i32 [ 0, %.lr.ph36 ], [ %37, %._crit_edge ]
  %9 = tail call i32 @getMinEdge(ptr noundef %3, ptr noundef nonnull %0)
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds %struct.Edge, ptr %3, i64 %10
  %12 = load i8, ptr %11, align 4, !tbaa !11
  %13 = sext i8 %12 to i32
  %14 = load ptr, ptr %0, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %14, i64 %10
  %16 = load i8, ptr %15, align 1, !tbaa !14
  %17 = sext i8 %16 to i32
  %18 = getelementptr inbounds i8, ptr %11, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %13, i32 noundef %17, i32 noundef %19)
  store i32 0, ptr %18, align 4, !tbaa !15
  %21 = load i32, ptr %4, align 8, !tbaa !5
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %8
  %23 = load ptr, ptr %7, align 8, !tbaa !16
  %24 = getelementptr inbounds ptr, ptr %23, i64 %10
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %wide.trip.count = zext nneg i32 %21 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %26 = icmp eq i32 %21, 1
  br i1 %26, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %40

._crit_edge.loopexit.unr-lcssa:                   ; preds = %62, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %62 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa
  %27 = getelementptr inbounds i32, ptr %25, i64 %indvars.iv.unr
  %28 = load i32, ptr %27, align 4, !tbaa !18
  %29 = getelementptr inbounds %struct.Edge, ptr %3, i64 %indvars.iv.unr
  %30 = getelementptr inbounds i8, ptr %29, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !15
  %32 = icmp slt i32 %28, %31
  br i1 %32, label %33, label %._crit_edge

33:                                               ; preds = %.epil.preheader
  store i32 %28, ptr %30, align 4, !tbaa !15
  %34 = load ptr, ptr %0, align 8, !tbaa !13
  %35 = getelementptr inbounds i8, ptr %34, i64 %10
  %36 = load i8, ptr %35, align 1, !tbaa !14
  store i8 %36, ptr %29, align 4, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %33, %.epil.preheader, %8
  %37 = add nuw nsw i32 %.03134, 1
  %38 = add nsw i32 %21, -1
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %8, label %._crit_edge37, !llvm.loop !19

40:                                               ; preds = %62, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %62 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %62 ]
  %41 = getelementptr inbounds i32, ptr %25, i64 %indvars.iv
  %42 = load i32, ptr %41, align 4, !tbaa !18
  %43 = getelementptr inbounds %struct.Edge, ptr %3, i64 %indvars.iv
  %44 = getelementptr inbounds i8, ptr %43, i64 4
  %45 = load i32, ptr %44, align 4, !tbaa !15
  %46 = icmp slt i32 %42, %45
  br i1 %46, label %47, label %51

47:                                               ; preds = %40
  store i32 %42, ptr %44, align 4, !tbaa !15
  %48 = load ptr, ptr %0, align 8, !tbaa !13
  %49 = getelementptr inbounds i8, ptr %48, i64 %10
  %50 = load i8, ptr %49, align 1, !tbaa !14
  store i8 %50, ptr %43, align 4, !tbaa !11
  br label %51

51:                                               ; preds = %40, %47
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %52 = getelementptr inbounds i32, ptr %25, i64 %indvars.iv.next
  %53 = load i32, ptr %52, align 4, !tbaa !18
  %54 = getelementptr inbounds %struct.Edge, ptr %3, i64 %indvars.iv.next
  %55 = getelementptr inbounds i8, ptr %54, i64 4
  %56 = load i32, ptr %55, align 4, !tbaa !15
  %57 = icmp slt i32 %53, %56
  br i1 %57, label %58, label %62

58:                                               ; preds = %51
  store i32 %53, ptr %55, align 4, !tbaa !15
  %59 = load ptr, ptr %0, align 8, !tbaa !13
  %60 = getelementptr inbounds i8, ptr %59, i64 %10
  %61 = load i8, ptr %60, align 1, !tbaa !14
  store i8 %61, ptr %54, align 4, !tbaa !11
  br label %62

62:                                               ; preds = %58, %51
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %40, !llvm.loop !21
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 = { nofree 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" }

!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, !10, i64 16}
!6 = !{!"Graph", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !8, i64 0}
!12 = !{!"Edge", !8, i64 0, !10, i64 4}
!13 = !{!6, !7, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!12, !10, i64 4}
!16 = !{!6, !7, i64 8}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !10, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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