; LLVM IR from yourtion/LearningMasteringAlgorithms-C :: source (graph)

; 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 { i32, i32, ptr, ptr, %struct.List_ }
%struct.List_ = type { i32, ptr, ptr, ptr, ptr }
%struct.ListElmt_ = type { ptr, ptr }
%struct.AdjList_ = type { ptr, %struct.List_ }

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

declare i32 @list_rem_next(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; 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
define dso_local i32 @graph_rem_vertex(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Graph_, ptr %12, i32 0, i32 4
  %14 = getelementptr inbounds %struct.List_, ptr %13, i32 0, i32 3
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %6, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %50, %2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %54

19:                                               ; preds = %16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ListElmt_, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = getelementptr inbounds %struct.AdjList_, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = call i32 @set_is_member(ptr noundef %23, ptr noundef %25)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %19
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %84

29:                                               ; preds = %19
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Graph_, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ListElmt_, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = getelementptr inbounds %struct.AdjList_, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  %40 = call i32 %32(ptr noundef %34, ptr noundef %39)
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %44

42:                                               ; preds = %29
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %43, ptr %7, align 8, !tbaa !5
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %42, %29
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %49, label %47

47:                                               ; preds = %44
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %48, ptr %8, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %47, %44
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ListElmt_, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !19
  store ptr %53, ptr %6, align 8, !tbaa !5
  br label %16, !llvm.loop !20

54:                                               ; preds = %16
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %58, label %57

57:                                               ; preds = %54
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %84

58:                                               ; preds = %54
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ListElmt_, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !14
  %62 = getelementptr inbounds %struct.AdjList_, ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds %struct.List_, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %63, align 8, !tbaa !22
  %65 = icmp sgt i32 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %58
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %84

67:                                               ; preds = %58
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Graph_, ptr %68, i32 0, i32 4
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = call i32 @list_rem_next(ptr noundef %69, ptr noundef %70, ptr noundef %9)
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %67
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %84

74:                                               ; preds = %67
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.AdjList_, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !17
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %77, ptr %78, align 8, !tbaa !5
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  call void @free(ptr noundef %79) #4
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.Graph_, ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 8, !tbaa !23
  %83 = add nsw i32 %82, -1
  store i32 %83, ptr %81, align 8, !tbaa !23
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %84

84:                                               ; preds = %74, %73, %66, %57, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %85 = load i32, ptr %3, align 4
  ret i32 %85
}

declare i32 @set_is_member(ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #4 = { 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, !6, i64 48}
!12 = !{!"Graph_", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !13, i64 24}
!13 = !{!"List_", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = !{!15, !6, i64 0}
!15 = !{!"ListElmt_", !6, i64 0, !6, i64 8}
!16 = !{!12, !6, i64 8}
!17 = !{!18, !6, i64 0}
!18 = !{!"AdjList_", !6, i64 0, !13, i64 8}
!19 = !{!15, !6, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!18, !10, i64 8}
!23 = !{!12, !10, i64 0}


; 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

declare i32 @list_rem_next(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

; 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
define dso_local range(i32 -1, 1) i32 @graph_rem_vertex(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #3 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %.02132 = load ptr, ptr %5, align 8, !tbaa !5
  %.not33 = icmp eq ptr %.02132, null
  br i1 %.not33, label %.loopexit, label %.lr.ph

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

7:                                                ; preds = %.lr.ph, %12
  %.02137 = phi ptr [ %.02132, %.lr.ph ], [ %.021, %12 ]
  %.036 = phi i32 [ 0, %.lr.ph ], [ %spec.select28, %12 ]
  %.01735 = phi ptr [ null, %.lr.ph ], [ %.118, %12 ]
  %.01934 = phi ptr [ null, %.lr.ph ], [ %spec.select, %12 ]
  %8 = load ptr, ptr %.02137, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = tail call i32 @set_is_member(ptr noundef nonnull %9, ptr noundef %10) #4
  %.not25 = icmp eq i32 %11, 0
  br i1 %.not25, label %12, label %.loopexit

12:                                               ; preds = %7
  %13 = load ptr, ptr %6, align 8, !tbaa !11
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = load ptr, ptr %.02137, align 8, !tbaa !9
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = tail call i32 %13(ptr noundef %14, ptr noundef %16) #4
  %.not26 = icmp eq i32 %17, 0
  %spec.select = select i1 %.not26, ptr %.01934, ptr %.02137
  %spec.select28 = select i1 %.not26, i32 %.036, i32 1
  %.not27 = icmp eq i32 %spec.select28, 0
  %.118 = select i1 %.not27, ptr %.02137, ptr %.01735
  %18 = getelementptr inbounds i8, ptr %.02137, i64 8
  %.021 = load ptr, ptr %18, align 8, !tbaa !5
  %.not = icmp eq ptr %.021, null
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !17

._crit_edge:                                      ; preds = %12
  %19 = icmp eq i32 %spec.select28, 0
  br i1 %19, label %.loopexit, label %20

20:                                               ; preds = %._crit_edge
  %21 = load ptr, ptr %spec.select, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !19
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %.loopexit, label %25

25:                                               ; preds = %20
  %26 = call i32 @list_rem_next(ptr noundef nonnull %4, ptr noundef %.01735, ptr noundef nonnull %3) #4
  %.not24 = icmp eq i32 %26, 0
  br i1 %.not24, label %27, label %.loopexit

27:                                               ; preds = %25
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  store ptr %29, ptr %1, align 8, !tbaa !5
  call void @free(ptr noundef %28) #4
  %30 = load i32, ptr %0, align 8, !tbaa !20
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %0, align 8, !tbaa !20
  br label %.loopexit

.loopexit:                                        ; preds = %7, %2, %25, %20, %._crit_edge, %27
  %.022 = phi i32 [ 0, %27 ], [ -1, %._crit_edge ], [ -1, %20 ], [ -1, %25 ], [ -1, %2 ], [ -1, %7 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 %.022
}

declare i32 @set_is_member(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 #4 = { 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 = !{!"ListElmt_", !6, i64 0, !6, i64 8}
!11 = !{!12, !6, i64 8}
!12 = !{!"Graph_", !13, i64 0, !13, i64 4, !6, i64 8, !6, i64 16, !14, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!"List_", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!16, !6, i64 0}
!16 = !{!"AdjList_", !6, i64 0, !14, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!16, !13, i64 8}
!20 = !{!12, !13, i64 0}


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