; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: Data Structures/Graphs/Representation (Adjacency_List)

; 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.AdjacencyList = type { i32, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15insert_to_graphP13AdjacencyListii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.AdjacencyList, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  store ptr %12, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.AdjacencyList, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %29

17:                                               ; preds = %3
  %18 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #4
  store ptr %18, ptr %7, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.AdjacencyList, ptr %20, i32 0, i32 0
  store i32 %19, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.AdjacencyList, ptr %22, i32 0, i32 2
  store ptr null, ptr %23, align 8, !tbaa !14
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.AdjacencyList, ptr %24, i32 0, i32 1
  store ptr null, ptr %25, align 8, !tbaa !11
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.AdjacencyList, ptr %27, i32 0, i32 1
  store ptr %26, ptr %28, align 8, !tbaa !11
  br label %62

29:                                               ; preds = %3
  br label %30

30:                                               ; preds = %41, %29
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %39

33:                                               ; preds = %30
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.AdjacencyList, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !13
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = icmp ne i32 %36, %37
  br label %39

39:                                               ; preds = %33, %30
  %40 = phi i1 [ false, %30 ], [ %38, %33 ]
  br i1 %40, label %41, label %46

41:                                               ; preds = %39
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %42, ptr %8, align 8, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.AdjacencyList, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  store ptr %45, ptr %7, align 8, !tbaa !5
  br label %30, !llvm.loop !15

46:                                               ; preds = %39
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = icmp eq ptr %47, null
  br i1 %48, label %49, label %61

49:                                               ; preds = %46
  %50 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #4
  store ptr %50, ptr %7, align 8, !tbaa !5
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.AdjacencyList, ptr %52, i32 0, i32 0
  store i32 %51, ptr %53, align 8, !tbaa !13
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.AdjacencyList, ptr %54, i32 0, i32 2
  store ptr null, ptr %55, align 8, !tbaa !14
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.AdjacencyList, ptr %56, i32 0, i32 1
  store ptr null, ptr %57, align 8, !tbaa !11
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.AdjacencyList, ptr %59, i32 0, i32 2
  store ptr %58, ptr %60, align 8, !tbaa !14
  br label %61

61:                                               ; preds = %49, %46
  br label %62

62:                                               ; preds = %61, %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %63 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #4
  store ptr %63, ptr %9, align 8, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.AdjacencyList, ptr %65, i32 0, i32 0
  store i32 %64, ptr %66, align 8, !tbaa !13
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.AdjacencyList, ptr %67, i32 0, i32 1
  store ptr null, ptr %68, align 8, !tbaa !11
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.AdjacencyList, ptr %69, i32 0, i32 2
  store ptr null, ptr %70, align 8, !tbaa !14
  br label %71

71:                                               ; preds = %76, %62
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.AdjacencyList, ptr %72, i32 0, i32 1
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %80

76:                                               ; preds = %71
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.AdjacencyList, ptr %77, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !11
  store ptr %79, ptr %7, align 8, !tbaa !5
  br label %71, !llvm.loop !17

80:                                               ; preds = %71
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.AdjacencyList, ptr %82, i32 0, i32 1
  store ptr %81, ptr %83, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

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

attributes #0 = { mustprogress 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 = { nobuiltin 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 = { nounwind }
attributes #4 = { builtin 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS13AdjacencyList", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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"

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15insert_to_graphP13AdjacencyListii(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %.critedge.sink.split, label %.preheader

.preheader:                                       ; preds = %3, %8
  %.034 = phi ptr [ %10, %8 ], [ %5, %3 ]
  %7 = load i32, ptr %.034, align 8, !tbaa !11
  %.not30 = icmp eq i32 %7, %1
  br i1 %.not30, label %.critedge, label %8

8:                                                ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %.034, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %cond = icmp eq ptr %10, null
  br i1 %cond, label %11, label %.preheader, !llvm.loop !13

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %.034, i64 16
  br label %.critedge.sink.split

.critedge.sink.split:                             ; preds = %3, %11
  %.sink39 = phi ptr [ %12, %11 ], [ %4, %3 ]
  %13 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #3
  store i32 %1, ptr %13, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %14, i8 0, i64 16, i1 false)
  store ptr %13, ptr %.sink39, align 8, !tbaa !15
  br label %.critedge

.critedge:                                        ; preds = %.preheader, %.critedge.sink.split
  %.1 = phi ptr [ %13, %.critedge.sink.split ], [ %.034, %.preheader ]
  %15 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #3
  store i32 %2, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %16, i8 0, i64 16, i1 false)
  br label %17

17:                                               ; preds = %17, %.critedge
  %.2 = phi ptr [ %.1, %.critedge ], [ %19, %17 ]
  %18 = getelementptr inbounds i8, ptr %.2, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %.not31 = icmp eq ptr %19, null
  br i1 %.not31, label %20, label %17, !llvm.loop !16

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %.2, i64 8
  store ptr %15, ptr %21, align 8, !tbaa !5
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) 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 = { mustprogress 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 = { nobuiltin 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { builtin 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, !10, i64 8}
!6 = !{!"_ZTS13AdjacencyList", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !10, i64 0}
!16 = distinct !{!16, !14}


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