; 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

; 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_ins_vertex(ptr noundef %0, ptr noundef %1) #1 {
  %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 i32, align 4
  %9 = 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 4, ptr %8) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Graph_, ptr %10, i32 0, i32 4
  %12 = getelementptr inbounds %struct.List_, ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %6, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %31, %2
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %35

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

29:                                               ; preds = %17
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %67

30:                                               ; preds = %17
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ListElmt_, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  store ptr %34, ptr %6, align 8, !tbaa !5
  br label %14, !llvm.loop !19

35:                                               ; preds = %14
  %36 = call noalias ptr @malloc(i64 noundef 48) #5
  store ptr %36, ptr %7, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %67

39:                                               ; preds = %35
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.AdjList_, ptr %41, i32 0, i32 0
  store ptr %40, ptr %42, align 8, !tbaa !16
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.AdjList_, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Graph_, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Graph_, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !21
  call void @set_init(ptr noundef %44, ptr noundef %47, ptr noundef %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Graph_, ptr %51, i32 0, i32 4
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Graph_, ptr %53, i32 0, i32 4
  %55 = getelementptr inbounds %struct.List_, ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !22
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = call i32 @list_ins_next(ptr noundef %52, ptr noundef %56, ptr noundef %57)
  store i32 %58, ptr %8, align 4, !tbaa !23
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %62

60:                                               ; preds = %39
  %61 = load i32, ptr %8, align 4, !tbaa !23
  store i32 %61, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %67

62:                                               ; preds = %39
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Graph_, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !24
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %64, align 8, !tbaa !24
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %67

67:                                               ; preds = %62, %60, %38, %29
  call void @llvm.lifetime.end.p0(i64 4, 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
  %68 = load i32, ptr %3, align 4
  ret i32 %68
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare void @set_init(ptr noundef, ptr noundef, ptr noundef) #3

declare i32 @list_ins_next(ptr noundef, ptr noundef, ptr noundef) #3

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 allocsize(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 #3 = { "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 }
attributes #5 = { nounwind allocsize(0) }

!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 48}
!10 = !{!"Graph_", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !12, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"List_", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!10, !6, i64 8}
!14 = !{!15, !6, i64 0}
!15 = !{!"ListElmt_", !6, i64 0, !6, i64 8}
!16 = !{!17, !6, i64 0}
!17 = !{!"AdjList_", !6, i64 0, !12, i64 8}
!18 = !{!15, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!10, !6, i64 16}
!22 = !{!10, !6, i64 56}
!23 = !{!11, !11, i64 0}
!24 = !{!10, !11, 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: nounwind uwtable
define dso_local i32 @graph_ins_vertex(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  %.01621 = load ptr, ptr %4, align 8, !tbaa !5
  %.not22 = icmp eq ptr %.01621, null
  br i1 %.not22, label %._crit_edge, label %.lr.ph

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

6:                                                ; preds = %8
  %7 = getelementptr inbounds i8, ptr %.01623, i64 8
  %.016 = load ptr, ptr %7, align 8, !tbaa !5
  %.not = icmp eq ptr %.016, null
  br i1 %.not, label %._crit_edge, label %8, !llvm.loop !9

8:                                                ; preds = %.lr.ph, %6
  %.01623 = phi ptr [ %.01621, %.lr.ph ], [ %.016, %6 ]
  %9 = load ptr, ptr %5, align 8, !tbaa !11
  %10 = load ptr, ptr %.01623, align 8, !tbaa !15
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  %12 = tail call i32 %9(ptr noundef %1, ptr noundef %11) #3
  %.not20 = icmp eq i32 %12, 0
  br i1 %.not20, label %6, label %.loopexit

._crit_edge:                                      ; preds = %6, %2
  %13 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #4
  %14 = icmp eq ptr %13, null
  br i1 %14, label %.loopexit, label %15

15:                                               ; preds = %._crit_edge
  store ptr %1, ptr %13, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %13, i64 8
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !19
  tail call void @set_init(ptr noundef nonnull %16, ptr noundef %18, ptr noundef %20) #3
  %21 = getelementptr inbounds i8, ptr %0, i64 56
  %22 = load ptr, ptr %21, align 8, !tbaa !20
  %23 = tail call i32 @list_ins_next(ptr noundef nonnull %3, ptr noundef %22, ptr noundef nonnull %13) #3
  %.not19 = icmp eq i32 %23, 0
  br i1 %.not19, label %24, label %.loopexit

24:                                               ; preds = %15
  %25 = load i32, ptr %0, align 8, !tbaa !21
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %0, align 8, !tbaa !21
  br label %.loopexit

.loopexit:                                        ; preds = %8, %15, %._crit_edge, %24
  %.0 = phi i32 [ 0, %24 ], [ -1, %._crit_edge ], [ %23, %15 ], [ 1, %8 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

declare void @set_init(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @list_ins_next(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 = { "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 }
attributes #4 = { nounwind allocsize(0) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!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 = !{!"ListElmt_", !6, i64 0, !6, i64 8}
!17 = !{!18, !6, i64 0}
!18 = !{!"AdjList_", !6, i64 0, !14, i64 8}
!19 = !{!12, !6, i64 16}
!20 = !{!12, !6, i64 56}
!21 = !{!12, !13, i64 0}


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