; LLVM IR from VAR-solutions/Algorithms :: Sorting/Topological Sorting/C (topological_sorting)

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

; 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
declare dso_local void @DFS_visit(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @DFS(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca [10 x i32], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %19, %3
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 10
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %11
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 %17
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %15
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %8, align 4, !tbaa !9
  br label %11, !llvm.loop !11

22:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %48, %22
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 10
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %51

27:                                               ; preds = %23
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %47

33:                                               ; preds = %27
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %34, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %47

40:                                               ; preds = %33
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 0
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  call void @DFS_visit(ptr noundef %41, ptr noundef %42, i32 noundef %43, i32 noundef %44, ptr noundef %45, ptr noundef %46)
  br label %47

47:                                               ; preds = %40, %33, %27
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %10, align 4, !tbaa !9
  br label %23, !llvm.loop !13

51:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 40, ptr %7) #2
  ret void
}

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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @DFS_visit(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @DFS(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca [10 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %4, i8 0, i64 40, i1 false), !tbaa !5
  %5 = load ptr, ptr %0, align 8, !tbaa !9
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %.preheader.1.thread, label %.preheader.1

.preheader.1:                                     ; preds = %3
  call void @DFS_visit(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 0, i32 noundef 0, ptr noundef nonnull %4, ptr noundef %2)
  %.phi.trans.insert = getelementptr inbounds i8, ptr %4, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  %6 = icmp eq i32 %.pre, 0
  br i1 %6, label %.preheader.1.thread, label %.preheader.2

.preheader.1.thread:                              ; preds = %3, %.preheader.1
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %.not.1 = icmp eq ptr %8, null
  br i1 %.not.1, label %.preheader.2, label %9

9:                                                ; preds = %.preheader.1.thread
  call void @DFS_visit(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 1, i32 noundef 0, ptr noundef nonnull %4, ptr noundef %2)
  br label %.preheader.2

.preheader.2:                                     ; preds = %9, %.preheader.1.thread, %.preheader.1
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !5
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %.preheader.3

13:                                               ; preds = %.preheader.2
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %.not.2 = icmp eq ptr %15, null
  br i1 %.not.2, label %.preheader.3, label %16

16:                                               ; preds = %13
  call void @DFS_visit(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 2, i32 noundef 0, ptr noundef nonnull %4, ptr noundef %2)
  br label %.preheader.3

.preheader.3:                                     ; preds = %16, %13, %.preheader.2
  %17 = getelementptr inbounds i8, ptr %4, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %.preheader.4

20:                                               ; preds = %.preheader.3
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %.not.3 = icmp eq ptr %22, null
  br i1 %.not.3, label %.preheader.4, label %23

23:                                               ; preds = %20
  call void @DFS_visit(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 3, i32 noundef 0, ptr noundef nonnull %4, ptr noundef %2)
  br label %.preheader.4

.preheader.4:                                     ; preds = %23, %20, %.preheader.3
  %24 = getelementptr inbounds i8, ptr %4, i64 16
  %25 = load i32, ptr %24, align 16, !tbaa !5
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %.preheader.5

27:                                               ; preds = %.preheader.4
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %.not.4 = icmp eq ptr %29, null
  br i1 %.not.4, label %.preheader.5, label %30

30:                                               ; preds = %27
  call void @DFS_visit(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 4, i32 noundef 0, ptr noundef nonnull %4, ptr noundef %2)
  br label %.preheader.5

.preheader.5:                                     ; preds = %30, %27, %.preheader.4
  %31 = getelementptr inbounds i8, ptr %4, i64 20
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %.preheader.6

34:                                               ; preds = %.preheader.5
  %35 = getelementptr inbounds i8, ptr %0, i64 40
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %.not.5 = icmp eq ptr %36, null
  br i1 %.not.5, label %.preheader.6, label %37

37:                                               ; preds = %34
  call void @DFS_visit(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 5, i32 noundef 0, ptr noundef nonnull %4, ptr noundef %2)
  br label %.preheader.6

.preheader.6:                                     ; preds = %37, %34, %.preheader.5
  %38 = getelementptr inbounds i8, ptr %4, i64 24
  %39 = load i32, ptr %38, align 8, !tbaa !5
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %41, label %.preheader.7

41:                                               ; preds = %.preheader.6
  %42 = getelementptr inbounds i8, ptr %0, i64 48
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %.not.6 = icmp eq ptr %43, null
  br i1 %.not.6, label %.preheader.7, label %44

44:                                               ; preds = %41
  call void @DFS_visit(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 6, i32 noundef 0, ptr noundef nonnull %4, ptr noundef %2)
  br label %.preheader.7

.preheader.7:                                     ; preds = %44, %41, %.preheader.6
  %45 = getelementptr inbounds i8, ptr %4, i64 28
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %.preheader.8

48:                                               ; preds = %.preheader.7
  %49 = getelementptr inbounds i8, ptr %0, i64 56
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %.not.7 = icmp eq ptr %50, null
  br i1 %.not.7, label %.preheader.8, label %51

51:                                               ; preds = %48
  call void @DFS_visit(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 7, i32 noundef 0, ptr noundef nonnull %4, ptr noundef %2)
  br label %.preheader.8

.preheader.8:                                     ; preds = %51, %48, %.preheader.7
  %52 = getelementptr inbounds i8, ptr %4, i64 32
  %53 = load i32, ptr %52, align 16, !tbaa !5
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %.preheader.9

55:                                               ; preds = %.preheader.8
  %56 = getelementptr inbounds i8, ptr %0, i64 64
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %.not.8 = icmp eq ptr %57, null
  br i1 %.not.8, label %.preheader.9, label %58

58:                                               ; preds = %55
  call void @DFS_visit(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 8, i32 noundef 0, ptr noundef nonnull %4, ptr noundef %2)
  br label %.preheader.9

.preheader.9:                                     ; preds = %58, %55, %.preheader.8
  %59 = getelementptr inbounds i8, ptr %4, i64 36
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %62, label %66

62:                                               ; preds = %.preheader.9
  %63 = getelementptr inbounds i8, ptr %0, i64 72
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  %.not.9 = icmp eq ptr %64, null
  br i1 %.not.9, label %66, label %65

65:                                               ; preds = %62
  call void @DFS_visit(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 9, i32 noundef 0, ptr noundef nonnull %4, ptr noundef %2)
  br label %66

66:                                               ; preds = %65, %62, %.preheader.9
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #3
  ret void
}

; 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 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass