; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: DataStructure/Graphs/Sources (DirectedGraph)

; 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.DirectedGraph = type { ptr, ptr, ptr }
%struct.DirGraphNode = type { ptr, ptr, ptr }

@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @freeDGraphNode(ptr 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
declare void @free(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

declare ptr @arrayListInitialization(i32 noundef, ptr noundef, ptr noundef) #4

declare ptr @hashMapToArray(ptr noundef) #4

declare i32 @hashMapGetLength(ptr noundef) #4

declare void @arrayListAdd(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local void @freeUintptr_t(ptr noundef) #0

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

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

declare ptr @hashSetInitialization(ptr noundef, ptr noundef, ptr noundef) #4

declare ptr @stackInitialization(ptr noundef) #4

declare signext i16 @stackIsEmpty(ptr noundef) #4

declare ptr @stackPop(ptr noundef) #4

declare void @destroyHashSet(ptr noundef) #4

declare void @destroyStack(ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @dirGraphTopologicalSort(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %1
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str.7, ptr noundef @.str.8, ptr noundef @.str.2) #5
  call void @exit(i32 noundef -83386157) #6
  unreachable

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.DirectedGraph, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call ptr @hashMapToArray(ptr noundef %17)
  store ptr %18, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.DirectedGraph, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = call i32 @hashMapGetLength(ptr noundef %21)
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.DirectedGraph, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.DirectedGraph, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = call ptr @arrayListInitialization(i32 noundef %22, ptr noundef %25, ptr noundef %28)
  store ptr %29, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %30 = call ptr @hashSetInitialization(ptr noundef @freeUintptr_t, ptr noundef @compUintptr_t, ptr noundef @uintptr_tHashFunDirG)
  store ptr %30, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %31 = call ptr @stackInitialization(ptr noundef @freeDGraphNode)
  store ptr %31, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %32

32:                                               ; preds = %48, %14
  %33 = load i32, ptr %7, align 4, !tbaa !13
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.DirectedGraph, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = call i32 @hashMapGetLength(ptr noundef %36)
  %38 = icmp slt i32 %33, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %51

40:                                               ; preds = %32
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !13
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds ptr, ptr %41, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  call void @dirGraphTopologicalSortR(ptr noundef %45, ptr noundef %46, ptr noundef %47)
  br label %48

48:                                               ; preds = %40
  %49 = load i32, ptr %7, align 4, !tbaa !13
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !13
  br label %32, !llvm.loop !15

51:                                               ; preds = %39
  br label %52

52:                                               ; preds = %57, %51
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = call signext i16 @stackIsEmpty(ptr noundef %53)
  %55 = icmp ne i16 %54, 0
  %56 = xor i1 %55, true
  br i1 %56, label %57, label %64

57:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = call ptr @stackPop(ptr noundef %58)
  store ptr %59, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.DirGraphNode, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !17
  call void @arrayListAdd(ptr noundef %60, ptr noundef %63)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %52, !llvm.loop !19

64:                                               ; preds = %52
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  call void @destroyStack(ptr noundef %65)
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  call void @destroyHashSet(ptr noundef %66)
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %67) #5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret ptr %68
}

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

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 "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 = { noreturn 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 #4 = { "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 #5 = { nounwind }
attributes #6 = { noreturn 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, !6, i64 0}
!10 = !{!"DirectedGraph", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !6, i64 0}
!18 = !{!"DirGraphNode", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = distinct !{!19, !16}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @freeDGraphNode(ptr noundef) #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

declare ptr @arrayListInitialization(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare ptr @hashMapToArray(ptr noundef) local_unnamed_addr #4

declare i32 @hashMapGetLength(ptr noundef) local_unnamed_addr #4

declare void @arrayListAdd(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare dso_local void @freeUintptr_t(ptr noundef) #0

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

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

declare ptr @hashSetInitialization(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

declare ptr @stackInitialization(ptr noundef) local_unnamed_addr #4

declare signext i16 @stackIsEmpty(ptr noundef) local_unnamed_addr #4

declare ptr @stackPop(ptr noundef) local_unnamed_addr #4

declare void @destroyHashSet(ptr noundef) local_unnamed_addr #4

declare void @destroyStack(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local ptr @dirGraphTopologicalSort(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %3, label %6

3:                                                ; preds = %1
  %4 = load ptr, ptr @stderr, align 8, !tbaa !5
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.2) #5
  tail call void @exit(i32 noundef -83386157) #6
  unreachable

6:                                                ; preds = %1
  %7 = load ptr, ptr %0, align 8, !tbaa !9
  %8 = tail call ptr @hashMapToArray(ptr noundef %7) #7
  %9 = load ptr, ptr %0, align 8, !tbaa !9
  %10 = tail call i32 @hashMapGetLength(ptr noundef %9) #7
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = tail call ptr @arrayListInitialization(i32 noundef %10, ptr noundef %12, ptr noundef %14) #7
  %16 = tail call ptr @hashSetInitialization(ptr noundef nonnull @freeUintptr_t, ptr noundef nonnull @compUintptr_t, ptr noundef nonnull @uintptr_tHashFunDirG) #7
  %17 = tail call ptr @stackInitialization(ptr noundef nonnull @freeDGraphNode) #7
  %18 = load ptr, ptr %0, align 8, !tbaa !9
  %19 = tail call i32 @hashMapGetLength(ptr noundef %18) #7
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %6
  %21 = tail call signext i16 @stackIsEmpty(ptr noundef %17) #7
  %.not21 = icmp eq i16 %21, 0
  br i1 %.not21, label %.lr.ph22, label %._crit_edge

.lr.ph:                                           ; preds = %6, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %6 ]
  %22 = getelementptr inbounds ptr, ptr %8, i64 %indvars.iv
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  tail call void @dirGraphTopologicalSortR(ptr noundef %23, ptr noundef %16, ptr noundef %17)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = load ptr, ptr %0, align 8, !tbaa !9
  %25 = tail call i32 @hashMapGetLength(ptr noundef %24) #7
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next, %26
  br i1 %27, label %.lr.ph, label %.preheader, !llvm.loop !13

.lr.ph22:                                         ; preds = %.preheader, %.lr.ph22
  %28 = tail call ptr @stackPop(ptr noundef %17) #7
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  tail call void @arrayListAdd(ptr noundef %15, ptr noundef %29) #7
  %30 = tail call signext i16 @stackIsEmpty(ptr noundef %17) #7
  %.not = icmp eq i16 %30, 0
  br i1 %.not, label %.lr.ph22, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph22, %.preheader
  tail call void @destroyStack(ptr noundef %17) #7
  tail call void @destroyHashSet(ptr noundef %16) #7
  tail call void @free(ptr noundef %8) #7
  ret ptr %15
}

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

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #3 = { noreturn 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 #4 = { "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 #5 = { cold nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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, !6, i64 0}
!10 = !{!"DirectedGraph", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !6, i64 0}
!16 = !{!"DirGraphNode", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = distinct !{!17, !14}


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