; LLVM IR from lekkas/c-algorithms :: src/algos (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 { ptr, ptr, i32, i32, i8 }
%struct.Edgenode = type { i32, i32, ptr }

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

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

; 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 void @insert_edge(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %13 = zext i1 %4 to i8
  store i8 %13, ptr %10, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  store i8 0, ptr %11, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.Graph, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds ptr, ptr %16, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %20, ptr %12, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %31, %5
  %22 = load ptr, ptr %12, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %35

24:                                               ; preds = %21
  %25 = load ptr, ptr %12, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Edgenode, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !15
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp eq i32 %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  store i8 1, ptr %11, align 1, !tbaa !11
  br label %35

31:                                               ; preds = %24
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Edgenode, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  store ptr %34, ptr %12, align 8, !tbaa !5
  br label %21, !llvm.loop !18

35:                                               ; preds = %30, %21
  %36 = load i8, ptr %11, align 1, !tbaa !11, !range !20, !noundef !21
  %37 = trunc i8 %36 to i1
  br i1 %37, label %62, label %38

38:                                               ; preds = %35
  store i8 1, ptr %11, align 1, !tbaa !11
  %39 = call noalias ptr @malloc(i64 noundef 16) #4
  store ptr %39, ptr %12, align 8, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Edgenode, ptr %41, i32 0, i32 0
  store i32 %40, ptr %42, align 8, !tbaa !15
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Edgenode, ptr %44, i32 0, i32 1
  store i32 %43, ptr %45, align 4, !tbaa !22
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Graph, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Edgenode, ptr %53, i32 0, i32 2
  store ptr %52, ptr %54, align 8, !tbaa !17
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Graph, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds ptr, ptr %58, i64 %60
  store ptr %55, ptr %61, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %38, %35
  %63 = load i8, ptr %10, align 1, !tbaa !11, !range !20, !noundef !21
  %64 = trunc i8 %63 to i1
  br i1 %64, label %70, label %65

65:                                               ; preds = %62
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = load i32, ptr %7, align 4, !tbaa !9
  %69 = load i32, ptr %9, align 4, !tbaa !9
  call void @insert_edge(ptr noundef %66, i32 noundef %67, i32 noundef %68, i32 noundef %69, i1 noundef zeroext true)
  br label %70

70:                                               ; preds = %65, %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"Graph", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !12, i64 24}
!15 = !{!16, !10, i64 0}
!16 = !{!"Edgenode", !10, i64 0, !10, i64 4, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!16, !10, i64 4}


; 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @insert_edge(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i1 noundef zeroext %4) local_unnamed_addr #1 {
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds ptr, ptr %6, i64 %7
  %.022 = load ptr, ptr %8, align 8, !tbaa !12
  %.not.not23 = icmp eq ptr %.022, null
  br i1 %.not.not23, label %.critedge, label %.lr.ph

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %.024, i64 8
  %.0 = load ptr, ptr %10, align 8, !tbaa !12
  %.not.not = icmp eq ptr %.0, null
  br i1 %.not.not, label %.critedge, label %.lr.ph, !llvm.loop !13

.lr.ph:                                           ; preds = %5, %9
  %.024 = phi ptr [ %.0, %9 ], [ %.022, %5 ]
  %11 = load i32, ptr %.024, align 8, !tbaa !15
  %12 = icmp eq i32 %11, %2
  br i1 %12, label %.loopexit, label %9

.critedge:                                        ; preds = %9, %5
  %13 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  store i32 %2, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  store i32 %3, ptr %14, align 4, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %.022, ptr %15, align 8, !tbaa !18
  store ptr %13, ptr %8, align 8, !tbaa !12
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.critedge
  br i1 %4, label %insert_edge.exit, label %16

16:                                               ; preds = %.loopexit
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = sext i32 %2 to i64
  %19 = getelementptr inbounds ptr, ptr %17, i64 %18
  %.0.i25 = load ptr, ptr %19, align 8, !tbaa !12
  %.not.not.i26 = icmp eq ptr %.0.i25, null
  br i1 %.not.not.i26, label %.critedge.i, label %.lr.ph28

20:                                               ; preds = %.lr.ph28
  %21 = getelementptr inbounds i8, ptr %.0.i27, i64 8
  %.0.i = load ptr, ptr %21, align 8, !tbaa !12
  %.not.not.i = icmp eq ptr %.0.i, null
  br i1 %.not.not.i, label %.critedge.i, label %.lr.ph28, !llvm.loop !13

.lr.ph28:                                         ; preds = %16, %20
  %.0.i27 = phi ptr [ %.0.i, %20 ], [ %.0.i25, %16 ]
  %22 = load i32, ptr %.0.i27, align 8, !tbaa !15
  %23 = icmp eq i32 %22, %1
  br i1 %23, label %insert_edge.exit, label %20

.critedge.i:                                      ; preds = %20, %16
  %24 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #2
  store i32 %1, ptr %24, align 8, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %24, i64 4
  store i32 %3, ptr %25, align 4, !tbaa !17
  %26 = getelementptr inbounds i8, ptr %24, i64 8
  store ptr %.0.i25, ptr %26, align 8, !tbaa !18
  store ptr %24, ptr %19, align 8, !tbaa !12
  br label %insert_edge.exit

insert_edge.exit:                                 ; preds = %.lr.ph28, %.critedge.i, %.loopexit
  ret void
}

attributes #0 = { 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 #1 = { nofree 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) }

!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, !7, i64 0}
!6 = !{!"Graph", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !11, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 0}
!16 = !{!"Edgenode", !10, i64 0, !10, i64 4, !7, i64 8}
!17 = !{!16, !10, i64 4}
!18 = !{!16, !7, i64 8}


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