; LLVM IR from AlgoGenesis/C :: Graph Algorithms/Gabow's Algorithm (program)

; 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"

@adj = external dso_local global [100 x [100 x i32]], align 16
@discovered = external dso_local global [100 x i32], align 16
@sccId = external dso_local global [100 x i32], align 16
@visited = external dso_local global [100 x i32], align 16
@stackTop = external dso_local global i32, align 4
@discoveryTime = external dso_local global i32, align 4
@sccCount = external dso_local global i32, align 4
@root = external dso_local global [100 x i32], align 16
@stack = external dso_local global [100 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local void @dfs(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr @discoveryTime, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @discoveryTime, align 4, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100 x i32], ptr @root, i64 0, i64 %11
  store i32 %8, ptr %12, align 4, !tbaa !5
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100 x i32], ptr @discovered, i64 0, i64 %14
  store i32 %8, ptr %15, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr @stackTop, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @stackTop, align 4, !tbaa !5
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds [100 x i32], ptr @stack, i64 0, i64 %19
  store i32 %16, ptr %20, align 4, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100 x i32], ptr @visited, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %80, %2
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %83

29:                                               ; preds = %24
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100 x [100 x i32]], ptr @adj, i64 0, i64 %31
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100 x i32], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %79

38:                                               ; preds = %29
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100 x i32], ptr @discovered, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp eq i32 %42, -1
  br i1 %43, label %44, label %47

44:                                               ; preds = %38
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  call void @dfs(i32 noundef %45, i32 noundef %46)
  br label %47

47:                                               ; preds = %44, %38
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100 x i32], ptr @sccId, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp eq i32 %51, -1
  br i1 %52, label %53, label %78

53:                                               ; preds = %47
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100 x i32], ptr @root, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100 x i32], ptr @root, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = icmp slt i32 %57, %61
  br i1 %62, label %63, label %68

63:                                               ; preds = %53
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [100 x i32], ptr @root, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  br label %73

68:                                               ; preds = %53
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100 x i32], ptr @root, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %68, %63
  %74 = phi i32 [ %67, %63 ], [ %72, %68 ]
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [100 x i32], ptr @root, i64 0, i64 %76
  store i32 %74, ptr %77, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %73, %47
  br label %79

79:                                               ; preds = %78, %29
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %5, align 4, !tbaa !5
  br label %24, !llvm.loop !9

83:                                               ; preds = %28
  %84 = load i32, ptr %3, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [100 x i32], ptr @root, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [100 x i32], ptr @discovered, i64 0, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = icmp eq i32 %87, %91
  br i1 %92, label %93, label %115

93:                                               ; preds = %83
  br label %94

94:                                               ; preds = %111, %93
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %95 = load i32, ptr @stackTop, align 4, !tbaa !5
  %96 = add nsw i32 %95, -1
  store i32 %96, ptr @stackTop, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [100 x i32], ptr @stack, i64 0, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !5
  store i32 %99, ptr %6, align 4, !tbaa !5
  %100 = load i32, ptr @sccCount, align 4, !tbaa !5
  %101 = load i32, ptr %6, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [100 x i32], ptr @sccId, i64 0, i64 %102
  store i32 %100, ptr %103, align 4, !tbaa !5
  %104 = load i32, ptr %3, align 4, !tbaa !5
  %105 = load i32, ptr %6, align 4, !tbaa !5
  %106 = icmp eq i32 %104, %105
  br i1 %106, label %107, label %108

107:                                              ; preds = %94
  store i32 6, ptr %7, align 4
  br label %109

108:                                              ; preds = %94
  store i32 0, ptr %7, align 4
  br label %109

109:                                              ; preds = %108, %107
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %110 = load i32, ptr %7, align 4
  switch i32 %110, label %116 [
    i32 0, label %111
    i32 6, label %112
  ]

111:                                              ; preds = %109
  br label %94

112:                                              ; preds = %109
  %113 = load i32, ptr @sccCount, align 4, !tbaa !5
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr @sccCount, align 4, !tbaa !5
  br label %115

115:                                              ; preds = %112, %83
  ret void

116:                                              ; preds = %109
  unreachable
}

; 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

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

@adj = external dso_local local_unnamed_addr global [100 x [100 x i32]], align 16
@discovered = external dso_local local_unnamed_addr global [100 x i32], align 16
@sccId = external dso_local local_unnamed_addr global [100 x i32], align 16
@visited = external dso_local local_unnamed_addr global [100 x i32], align 16
@stackTop = external dso_local local_unnamed_addr global i32, align 4
@discoveryTime = external dso_local local_unnamed_addr global i32, align 4
@sccCount = external dso_local local_unnamed_addr global i32, align 4
@root = external dso_local local_unnamed_addr global [100 x i32], align 16
@stack = external dso_local local_unnamed_addr global [100 x i32], align 16

; Function Attrs: nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @dfs(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @discoveryTime, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @discoveryTime, align 4, !tbaa !5
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [100 x i32], ptr @root, i64 0, i64 %5
  store i32 %3, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds [100 x i32], ptr @discovered, i64 0, i64 %5
  store i32 %3, ptr %7, align 4, !tbaa !5
  %8 = load i32, ptr @stackTop, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @stackTop, align 4, !tbaa !5
  %10 = sext i32 %8 to i64
  %11 = getelementptr inbounds [100 x i32], ptr @stack, i64 0, i64 %10
  store i32 %0, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds [100 x i32], ptr @visited, i64 0, i64 %5
  store i32 1, ptr %12, align 4, !tbaa !5
  %13 = icmp sgt i32 %1, 0
  br i1 %13, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %33
  %.pre = load i32, ptr %6, align 4, !tbaa !5
  %.pre36 = load i32, ptr %7, align 4, !tbaa !5
  %14 = icmp eq i32 %.pre, %.pre36
  br i1 %14, label %.preheader, label %43

.preheader:                                       ; preds = %2, %._crit_edge
  %15 = load i32, ptr @sccCount, align 4, !tbaa !5
  %stackTop.promoted = load i32, ptr @stackTop, align 4, !tbaa !5
  %16 = sext i32 %stackTop.promoted to i64
  br label %34

.lr.ph:                                           ; preds = %.lr.ph.preheader, %33
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %33 ]
  %17 = getelementptr inbounds [100 x [100 x i32]], ptr @adj, i64 0, i64 %5, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %33, label %19

19:                                               ; preds = %.lr.ph
  %20 = getelementptr inbounds [100 x i32], ptr @discovered, i64 0, i64 %indvars.iv
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %25

23:                                               ; preds = %19
  %24 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @dfs(i32 noundef %24, i32 noundef %1)
  br label %25

25:                                               ; preds = %23, %19
  %26 = getelementptr inbounds [100 x i32], ptr @sccId, i64 0, i64 %indvars.iv
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %33

29:                                               ; preds = %25
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = getelementptr inbounds [100 x i32], ptr @root, i64 0, i64 %indvars.iv
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %. = tail call i32 @llvm.smin.i32(i32 %30, i32 %32)
  store i32 %., ptr %6, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %.lr.ph, %29, %25
  %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 %._crit_edge, label %.lr.ph, !llvm.loop !9

34:                                               ; preds = %.preheader, %34
  %indvars.iv33 = phi i64 [ %16, %.preheader ], [ %indvars.iv.next34, %34 ]
  %indvars.iv.next34 = add nsw i64 %indvars.iv33, -1
  %35 = getelementptr inbounds [100 x i32], ptr @stack, i64 0, i64 %indvars.iv.next34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100 x i32], ptr @sccId, i64 0, i64 %37
  store i32 %15, ptr %38, align 4, !tbaa !5
  %39 = icmp eq i32 %36, %0
  br i1 %39, label %40, label %34

40:                                               ; preds = %34
  %41 = trunc nsw i64 %indvars.iv.next34 to i32
  store i32 %41, ptr @stackTop, align 4, !tbaa !5
  %42 = add nsw i32 %15, 1
  store i32 %42, ptr @sccCount, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %40, %._crit_edge
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

attributes #0 = { nofree nosync nounwind memory(readwrite, argmem: none, 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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