; LLVM IR from FOSS-UCSC/FOSSALGO :: algorithms/gr-dfsrh/c (depth_first_search)

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

@visited = external dso_local global [1000 x i8], align 16
@size = external dso_local global [1000 x i32], align 16
@graph = external dso_local global [1000 x [1000 x i32]], align 16
@.str.1 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@vertex_cnt = external dso_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [41 x i8], align 1
@edge_cnt = external dso_local global i32, align 4
@.str.4 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@response = external dso_local global i8, align 1
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@u = external dso_local global i32, align 4
@v = external dso_local global i32, align 4
@.str.8 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @depthfirstsearch(i32 noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %16, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 1000
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1000 x i32], ptr @size, i64 0, i64 %11
  store i32 0, ptr %12, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1000 x i8], ptr @visited, i64 0, i64 %14
  store i8 0, ptr %15, align 1, !tbaa !9
  br label %16

16:                                               ; preds = %9
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !11

19:                                               ; preds = %8
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @vertex_cnt)
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @edge_cnt)
  %24 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.5, ptr noundef @response)
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %77, %19
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr @edge_cnt, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %80

32:                                               ; preds = %27
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.7, ptr noundef @u, ptr noundef @v)
  %34 = load i32, ptr @u, align 4, !tbaa !5
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr @u, align 4, !tbaa !5
  %36 = load i32, ptr @v, align 4, !tbaa !5
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr @v, align 4, !tbaa !5
  %38 = load i8, ptr @response, align 1, !tbaa !13
  %39 = sext i8 %38 to i32
  %40 = icmp eq i32 %39, 121
  br i1 %40, label %41, label %53

41:                                               ; preds = %32
  %42 = load i32, ptr @v, align 4, !tbaa !5
  %43 = load i32, ptr @u, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000 x [1000 x i32]], ptr @graph, i64 0, i64 %44
  %46 = load i32, ptr @u, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1000 x i32], ptr @size, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %48, align 4, !tbaa !5
  %51 = sext i32 %49 to i64
  %52 = getelementptr inbounds [1000 x i32], ptr %45, i64 0, i64 %51
  store i32 %42, ptr %52, align 4, !tbaa !5
  br label %76

53:                                               ; preds = %32
  %54 = load i32, ptr @v, align 4, !tbaa !5
  %55 = load i32, ptr @u, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1000 x [1000 x i32]], ptr @graph, i64 0, i64 %56
  %58 = load i32, ptr @u, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1000 x i32], ptr @size, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %60, align 4, !tbaa !5
  %63 = sext i32 %61 to i64
  %64 = getelementptr inbounds [1000 x i32], ptr %57, i64 0, i64 %63
  store i32 %54, ptr %64, align 4, !tbaa !5
  %65 = load i32, ptr @u, align 4, !tbaa !5
  %66 = load i32, ptr @v, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [1000 x [1000 x i32]], ptr @graph, i64 0, i64 %67
  %69 = load i32, ptr @v, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [1000 x i32], ptr @size, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %71, align 4, !tbaa !5
  %74 = sext i32 %72 to i64
  %75 = getelementptr inbounds [1000 x i32], ptr %68, i64 0, i64 %74
  store i32 %65, ptr %75, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %53, %41
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %3, align 4, !tbaa !5
  br label %27, !llvm.loop !14

80:                                               ; preds = %31
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %98, %80
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = load i32, ptr @vertex_cnt, align 4, !tbaa !5
  %85 = icmp slt i32 %83, %84
  br i1 %85, label %87, label %86

86:                                               ; preds = %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %101

87:                                               ; preds = %82
  %88 = load i32, ptr %4, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [1000 x i8], ptr @visited, i64 0, i64 %89
  %91 = load i8, ptr %90, align 1, !tbaa !9, !range !15, !noundef !16
  %92 = trunc i8 %91 to i1
  %93 = zext i1 %92 to i32
  %94 = icmp eq i32 %93, 0
  br i1 %94, label %95, label %97

95:                                               ; preds = %87
  %96 = load i32, ptr %4, align 4, !tbaa !5
  call void @depthfirstsearch(i32 noundef %96)
  br label %97

97:                                               ; preds = %95, %87
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %4, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %4, align 4, !tbaa !5
  br label %82, !llvm.loop !17

101:                                              ; preds = %86
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !12}


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

@visited = external dso_local local_unnamed_addr global [1000 x i8], align 16
@size = external dso_local local_unnamed_addr global [1000 x i32], align 16
@graph = external dso_local local_unnamed_addr global [1000 x [1000 x i32]], align 16
@.str.1 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@vertex_cnt = external dso_local global i32, align 4
@.str.3 = external hidden unnamed_addr constant [41 x i8], align 1
@edge_cnt = external dso_local global i32, align 4
@.str.4 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1
@response = external dso_local global i8, align 1
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1
@u = external dso_local global i32, align 4
@v = external dso_local global i32, align 4
@.str.8 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @depthfirstsearch(i32 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000) @size, i8 0, i64 4000, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1000) @visited, i8 0, i64 1000, i1 false), !tbaa !9
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @vertex_cnt)
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @edge_cnt)
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.5, ptr noundef nonnull @response)
  %7 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  %8 = load i32, ptr @edge_cnt, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %33, %0
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %11 = load i32, ptr @vertex_cnt, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph16, label %._crit_edge17

.lr.ph:                                           ; preds = %0, %33
  %.01013 = phi i32 [ %34, %33 ], [ 0, %0 ]
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.7, ptr noundef nonnull @u, ptr noundef nonnull @v)
  %14 = load i32, ptr @u, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr @u, align 4, !tbaa !5
  %16 = load i32, ptr @v, align 4, !tbaa !5
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr @v, align 4, !tbaa !5
  %18 = load i8, ptr @response, align 1, !tbaa !11
  %19 = icmp eq i8 %18, 121
  %20 = sext i32 %15 to i64
  %21 = getelementptr inbounds [1000 x i32], ptr @size, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %21, align 4, !tbaa !5
  %24 = sext i32 %22 to i64
  %25 = getelementptr inbounds [1000 x [1000 x i32]], ptr @graph, i64 0, i64 %20, i64 %24
  store i32 %17, ptr %25, align 4, !tbaa !5
  br i1 %19, label %33, label %26

26:                                               ; preds = %.lr.ph
  %27 = sext i32 %17 to i64
  %28 = getelementptr inbounds [1000 x i32], ptr @size, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %28, align 4, !tbaa !5
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds [1000 x [1000 x i32]], ptr @graph, i64 0, i64 %27, i64 %31
  store i32 %15, ptr %32, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %.lr.ph, %26
  %34 = add nuw nsw i32 %.01013, 1
  %35 = load i32, ptr @edge_cnt, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge17:                                    ; preds = %44, %._crit_edge
  %37 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  ret i32 0

.lr.ph16:                                         ; preds = %._crit_edge, %44
  %38 = phi i32 [ %45, %44 ], [ %11, %._crit_edge ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %44 ], [ 0, %._crit_edge ]
  %39 = getelementptr inbounds [1000 x i8], ptr @visited, i64 0, i64 %indvars.iv
  %40 = load i8, ptr %39, align 1, !tbaa !9, !range !14, !noundef !15
  %41 = icmp eq i8 %40, 0
  br i1 %41, label %42, label %44

42:                                               ; preds = %.lr.ph16
  %43 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @depthfirstsearch(i32 noundef %43)
  %.pre = load i32, ptr @vertex_cnt, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %.lr.ph16, %42
  %45 = phi i32 [ %38, %.lr.ph16 ], [ %.pre, %42 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %46 = sext i32 %45 to i64
  %47 = icmp slt i64 %indvars.iv.next, %46
  br i1 %47, label %.lr.ph16, label %._crit_edge17, !llvm.loop !16
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { 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" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !13}


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