; LLVM IR from bartobri/data-structures-c :: graph/adjacency-matrix (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"

@adj = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @graphInit(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = mul i64 %6, 8
  %8 = call noalias ptr @malloc(i64 noundef %7) #4
  store ptr %8, ptr @adj, align 8, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %22, %1
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %25

13:                                               ; preds = %9
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = mul i64 %15, 4
  %17 = call noalias ptr @malloc(i64 noundef %16) #4
  %18 = load ptr, ptr @adj, align 8, !tbaa !9
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %18, i64 %20
  store ptr %17, ptr %21, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %13
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %3, align 4, !tbaa !5
  br label %9, !llvm.loop !11

25:                                               ; preds = %9
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %48, %25
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %51

30:                                               ; preds = %26
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %44, %30
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %47

35:                                               ; preds = %31
  %36 = load ptr, ptr @adj, align 8, !tbaa !9
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds ptr, ptr %36, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %40, i64 %42
  store i32 0, ptr %43, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %35
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %4, align 4, !tbaa !5
  br label %31, !llvm.loop !13

47:                                               ; preds = %31
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %3, align 4, !tbaa !5
  br label %26, !llvm.loop !14

51:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #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: nounwind allocsize(0)
declare noalias ptr @malloc(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 = { 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 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

@adj = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nofree nounwind uwtable
define dso_local void @graphInit(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = shl nsw i64 %2, 3
  %4 = tail call noalias ptr @malloc(i64 noundef %3) #3
  store ptr %4, ptr @adj, align 8, !tbaa !5
  %5 = icmp sgt i32 %0, 0
  br i1 %5, label %.lr.ph, label %._crit_edge21

.lr.ph:                                           ; preds = %1
  %6 = shl nuw nsw i64 %2, 2
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %27

.preheader16:                                     ; preds = %27
  br i1 %5, label %.preheader.lr.ph, label %._crit_edge21

.preheader.lr.ph:                                 ; preds = %.preheader16
  %7 = load ptr, ptr @adj, align 8
  %8 = zext nneg i32 %0 to i64
  %9 = shl nuw nsw i64 %8, 2
  %xtraiter = and i64 %wide.trip.count, 7
  %10 = icmp ult i32 %0, 8
  br i1 %10, label %._crit_edge21.loopexit.unr-lcssa, label %.preheader.lr.ph.new

.preheader.lr.ph.new:                             ; preds = %.preheader.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483640
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us, %.preheader.lr.ph.new
  %indvars.iv26 = phi i64 [ 0, %.preheader.lr.ph.new ], [ %indvars.iv.next27.7, %.preheader.us ]
  %niter = phi i64 [ 0, %.preheader.lr.ph.new ], [ %niter.next.7, %.preheader.us ]
  %11 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv26
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 4 %12, i8 0, i64 %9, i1 false), !tbaa !9
  %indvars.iv.next27 = or disjoint i64 %indvars.iv26, 1
  %13 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.next27
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 4 %14, i8 0, i64 %9, i1 false), !tbaa !9
  %indvars.iv.next27.1 = or disjoint i64 %indvars.iv26, 2
  %15 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.next27.1
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 4 %16, i8 0, i64 %9, i1 false), !tbaa !9
  %indvars.iv.next27.2 = or disjoint i64 %indvars.iv26, 3
  %17 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.next27.2
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 4 %18, i8 0, i64 %9, i1 false), !tbaa !9
  %indvars.iv.next27.3 = or disjoint i64 %indvars.iv26, 4
  %19 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.next27.3
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 4 %20, i8 0, i64 %9, i1 false), !tbaa !9
  %indvars.iv.next27.4 = or disjoint i64 %indvars.iv26, 5
  %21 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.next27.4
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 4 %22, i8 0, i64 %9, i1 false), !tbaa !9
  %indvars.iv.next27.5 = or disjoint i64 %indvars.iv26, 6
  %23 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.next27.5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 4 %24, i8 0, i64 %9, i1 false), !tbaa !9
  %indvars.iv.next27.6 = or disjoint i64 %indvars.iv26, 7
  %25 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv.next27.6
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 4 %26, i8 0, i64 %9, i1 false), !tbaa !9
  %indvars.iv.next27.7 = add nuw nsw i64 %indvars.iv26, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge21.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !11

27:                                               ; preds = %.lr.ph, %27
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %27 ]
  %28 = tail call noalias ptr @malloc(i64 noundef %6) #3
  %29 = load ptr, ptr @adj, align 8, !tbaa !5
  %30 = getelementptr inbounds ptr, ptr %29, i64 %indvars.iv
  store ptr %28, ptr %30, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader16, label %27, !llvm.loop !13

._crit_edge21.loopexit.unr-lcssa:                 ; preds = %.preheader.us, %.preheader.lr.ph
  %indvars.iv26.unr = phi i64 [ 0, %.preheader.lr.ph ], [ %indvars.iv.next27.7, %.preheader.us ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge21, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge21.loopexit.unr-lcssa, %.preheader.us.epil
  %indvars.iv26.epil = phi i64 [ %indvars.iv.next27.epil, %.preheader.us.epil ], [ %indvars.iv26.unr, %._crit_edge21.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.us.epil ], [ 0, %._crit_edge21.loopexit.unr-lcssa ]
  %31 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv26.epil
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 4 %32, i8 0, i64 %9, i1 false), !tbaa !9
  %indvars.iv.next27.epil = add nuw nsw i64 %indvars.iv26.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge21, label %.preheader.us.epil, !llvm.loop !14

._crit_edge21:                                    ; preds = %._crit_edge21.loopexit.unr-lcssa, %.preheader.us.epil, %1, %.preheader16
  ret void
}

; 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

; 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 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}


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