; LLVM IR from AlgoGenesis/C :: Graph Algorithms/Handshaking Lemma and Interesting Tree Properties (program)

; 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 { [100 x [100 x i32]], i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @initGraph(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Graph, ptr %9, i32 0, i32 1
  store i32 %8, ptr %10, align 4, !tbaa !11
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.Graph, ptr %11, i32 0, i32 2
  store i32 0, ptr %12, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %37, %2
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %40

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %33, %18
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %36

24:                                               ; preds = %19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Graph, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100 x [100 x i32]], ptr %26, i64 0, i64 %28
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100 x i32], ptr %29, i64 0, i64 %31
  store i32 0, ptr %32, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %24
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !9
  br label %19, !llvm.loop !14

36:                                               ; preds = %23
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !9
  br label %13, !llvm.loop !16

40:                                               ; preds = %17
  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: 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 }

!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, !10, i64 40000}
!12 = !{!"", !7, i64 0, !10, i64 40000, !10, i64 40004}
!13 = !{!12, !10, i64 40004}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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: nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local void @initGraph(ptr nocapture noundef writeonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 40000
  store i32 %1, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 40004
  store i32 0, ptr %4, align 4, !tbaa !10
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.preheader.us.preheader, label %._crit_edge15

.preheader.us.preheader:                          ; preds = %2
  %6 = zext nneg i32 %1 to i64
  %7 = shl nuw nsw i64 %6, 2
  %xtraiter = and i64 %6, 7
  %8 = icmp ult i32 %1, 8
  br i1 %8, label %._crit_edge15.loopexit.unr-lcssa, label %.preheader.us.preheader.new

.preheader.us.preheader.new:                      ; preds = %.preheader.us.preheader
  %unroll_iter = and i64 %6, 2147483640
  %invariant.gep = getelementptr i8, ptr %0, i64 400
  %invariant.gep18 = getelementptr i8, ptr %0, i64 800
  %invariant.gep20 = getelementptr i8, ptr %0, i64 1200
  %invariant.gep22 = getelementptr i8, ptr %0, i64 1600
  %invariant.gep24 = getelementptr i8, ptr %0, i64 2000
  %invariant.gep26 = getelementptr i8, ptr %0, i64 2400
  %invariant.gep28 = getelementptr i8, ptr %0, i64 2800
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us, %.preheader.us.preheader.new
  %indvar = phi i64 [ 0, %.preheader.us.preheader.new ], [ %indvar.next.7, %.preheader.us ]
  %niter = phi i64 [ 0, %.preheader.us.preheader.new ], [ %niter.next.7, %.preheader.us ]
  %9 = mul nuw nsw i64 %indvar, 400
  %scevgep = getelementptr i8, ptr %0, i64 %9
  tail call void @llvm.memset.p0.i64(ptr align 4 %scevgep, i8 0, i64 %7, i1 false), !tbaa !11
  %10 = mul nuw i64 %indvar, 400
  %gep = getelementptr i8, ptr %invariant.gep, i64 %10
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep, i8 0, i64 %7, i1 false), !tbaa !11
  %11 = mul nuw i64 %indvar, 400
  %gep19 = getelementptr i8, ptr %invariant.gep18, i64 %11
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep19, i8 0, i64 %7, i1 false), !tbaa !11
  %12 = mul nuw i64 %indvar, 400
  %gep21 = getelementptr i8, ptr %invariant.gep20, i64 %12
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep21, i8 0, i64 %7, i1 false), !tbaa !11
  %13 = mul nuw i64 %indvar, 400
  %gep23 = getelementptr i8, ptr %invariant.gep22, i64 %13
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep23, i8 0, i64 %7, i1 false), !tbaa !11
  %14 = mul nuw i64 %indvar, 400
  %gep25 = getelementptr i8, ptr %invariant.gep24, i64 %14
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep25, i8 0, i64 %7, i1 false), !tbaa !11
  %15 = mul nuw i64 %indvar, 400
  %gep27 = getelementptr i8, ptr %invariant.gep26, i64 %15
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep27, i8 0, i64 %7, i1 false), !tbaa !11
  %16 = mul nuw i64 %indvar, 400
  %gep29 = getelementptr i8, ptr %invariant.gep28, i64 %16
  tail call void @llvm.memset.p0.i64(ptr align 4 %gep29, i8 0, i64 %7, i1 false), !tbaa !11
  %indvar.next.7 = add nuw nsw i64 %indvar, 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_edge15.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !12

._crit_edge15.loopexit.unr-lcssa:                 ; preds = %.preheader.us, %.preheader.us.preheader
  %indvar.unr = phi i64 [ 0, %.preheader.us.preheader ], [ %indvar.next.7, %.preheader.us ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge15, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge15.loopexit.unr-lcssa, %.preheader.us.epil
  %indvar.epil = phi i64 [ %indvar.next.epil, %.preheader.us.epil ], [ %indvar.unr, %._crit_edge15.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.us.epil ], [ 0, %._crit_edge15.loopexit.unr-lcssa ]
  %17 = mul nuw nsw i64 %indvar.epil, 400
  %scevgep.epil = getelementptr i8, ptr %0, i64 %17
  tail call void @llvm.memset.p0.i64(ptr align 4 %scevgep.epil, i8 0, i64 %7, i1 false), !tbaa !11
  %indvar.next.epil = add nuw nsw i64 %indvar.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_edge15, label %.preheader.us.epil, !llvm.loop !14

._crit_edge15:                                    ; preds = %._crit_edge15.loopexit.unr-lcssa, %.preheader.us.epil, %2
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: write) 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 nounwind willreturn memory(argmem: write) }

!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, !9, i64 40000}
!6 = !{!"", !7, i64 0, !9, i64 40000, !9, i64 40004}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 40004}
!11 = !{!9, !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}


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