; LLVM IR from AlgoGenesis/C :: Sparse Matrix/Tuple Form (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"

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @sparseToTuple(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 [100 x [3 x i32]], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  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 1200, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %13

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

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

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

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

23:                                               ; preds = %19
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %63

24:                                               ; preds = %19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [10 x i32], ptr %25, i64 %27
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10 x i32], ptr %28, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %59

34:                                               ; preds = %24
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100 x [3 x i32]], ptr %7, i64 0, i64 %37
  %39 = getelementptr inbounds [3 x i32], ptr %38, i64 0, i64 0
  store i32 %35, ptr %39, align 4, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100 x [3 x i32]], ptr %7, i64 0, i64 %42
  %44 = getelementptr inbounds [3 x i32], ptr %43, i64 0, i64 1
  store i32 %40, ptr %44, align 4, !tbaa !9
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10 x i32], ptr %45, i64 %47
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [10 x i32], ptr %48, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100 x [3 x i32]], ptr %7, i64 0, i64 %54
  %56 = getelementptr inbounds [3 x i32], ptr %55, i64 0, i64 2
  store i32 %52, ptr %56, align 4, !tbaa !9
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %8, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %34, %24
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %11, align 4, !tbaa !9
  br label %19, !llvm.loop !11

63:                                               ; preds = %23
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %9, align 4, !tbaa !9
  br label %13, !llvm.loop !13

67:                                               ; preds = %17
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %92, %67
  %71 = load i32, ptr %12, align 4, !tbaa !9
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = icmp slt i32 %71, %72
  br i1 %73, label %75, label %74

74:                                               ; preds = %70
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %95

75:                                               ; preds = %70
  %76 = load i32, ptr %12, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [100 x [3 x i32]], ptr %7, i64 0, i64 %77
  %79 = getelementptr inbounds [3 x i32], ptr %78, i64 0, i64 0
  %80 = load i32, ptr %79, align 4, !tbaa !9
  %81 = load i32, ptr %12, align 4, !tbaa !9
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [100 x [3 x i32]], ptr %7, i64 0, i64 %82
  %84 = getelementptr inbounds [3 x i32], ptr %83, i64 0, i64 1
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = load i32, ptr %12, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [100 x [3 x i32]], ptr %7, i64 0, i64 %87
  %89 = getelementptr inbounds [3 x i32], ptr %88, i64 0, i64 2
  %90 = load i32, ptr %89, align 4, !tbaa !9
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %80, i32 noundef %85, i32 noundef %90)
  br label %92

92:                                               ; preds = %75
  %93 = load i32, ptr %12, align 4, !tbaa !9
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %12, align 4, !tbaa !9
  br label %70, !llvm.loop !14

95:                                               ; preds = %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1200, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }

!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, !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"

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @sparseToTuple(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca [100 x [3 x i32]], align 16
  call void @llvm.lifetime.start.p0(i64 1200, ptr nonnull %4) #3
  %5 = icmp sgt i32 %1, 0
  %6 = icmp sgt i32 %2, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge30

.preheader.us.preheader:                          ; preds = %3
  %wide.trip.count38 = zext nneg i32 %1 to i64
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %7 = icmp eq i32 %2, 1
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv35 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next36, %._crit_edge.us ]
  %.02528.us = phi i32 [ 0, %.preheader.us.preheader ], [ %.2.us.lcssa, %._crit_edge.us ]
  %8 = trunc nuw nsw i64 %indvars.iv35 to i32
  br i1 %7, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %28
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %28 ], [ 0, %.preheader.us ]
  %.126.us = phi i32 [ %.2.us.1, %28 ], [ %.02528.us, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %28 ], [ 0, %.preheader.us ]
  %9 = getelementptr inbounds [10 x i32], ptr %0, i64 %indvars.iv35, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not.us = icmp eq i32 %10, 0
  br i1 %.not.us, label %18, label %11

11:                                               ; preds = %.preheader.us.new
  %12 = sext i32 %.126.us to i64
  %13 = getelementptr inbounds [100 x [3 x i32]], ptr %4, i64 0, i64 %12
  store i32 %8, ptr %13, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %15 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %15, ptr %14, align 4, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %13, i64 8
  store i32 %10, ptr %16, align 4, !tbaa !5
  %17 = add nsw i32 %.126.us, 1
  br label %18

18:                                               ; preds = %11, %.preheader.us.new
  %.2.us = phi i32 [ %17, %11 ], [ %.126.us, %.preheader.us.new ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %19 = getelementptr inbounds [10 x i32], ptr %0, i64 %indvars.iv35, i64 %indvars.iv.next
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not.us.1 = icmp eq i32 %20, 0
  br i1 %.not.us.1, label %28, label %21

21:                                               ; preds = %18
  %22 = sext i32 %.2.us to i64
  %23 = getelementptr inbounds [100 x [3 x i32]], ptr %4, i64 0, i64 %22
  store i32 %8, ptr %23, align 4, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 4
  %25 = trunc nuw nsw i64 %indvars.iv.next to i32
  store i32 %25, ptr %24, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %23, i64 8
  store i32 %20, ptr %26, align 4, !tbaa !5
  %27 = add nsw i32 %.2.us, 1
  br label %28

28:                                               ; preds = %21, %18
  %.2.us.1 = phi i32 [ %27, %21 ], [ %.2.us, %18 ]
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %28, %.preheader.us
  %.2.us.lcssa.ph = phi i32 [ poison, %.preheader.us ], [ %.2.us.1, %28 ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %28 ]
  %.126.us.unr = phi i32 [ %.02528.us, %.preheader.us ], [ %.2.us.1, %28 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %29 = getelementptr inbounds [10 x i32], ptr %0, i64 %indvars.iv35, i64 %indvars.iv.unr
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %.not.us.epil = icmp eq i32 %30, 0
  br i1 %.not.us.epil, label %._crit_edge.us, label %31

31:                                               ; preds = %.epil.preheader
  %32 = sext i32 %.126.us.unr to i64
  %33 = getelementptr inbounds [100 x [3 x i32]], ptr %4, i64 0, i64 %32
  store i32 %8, ptr %33, align 4, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 4
  %35 = trunc nuw nsw i64 %indvars.iv.unr to i32
  store i32 %35, ptr %34, align 4, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %33, i64 8
  store i32 %30, ptr %36, align 4, !tbaa !5
  %37 = add nsw i32 %.126.us.unr, 1
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %.epil.preheader, %31, %._crit_edge.us.unr-lcssa
  %.2.us.lcssa = phi i32 [ %.2.us.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %37, %31 ], [ %.126.us.unr, %.epil.preheader ]
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  br i1 %exitcond39.not, label %._crit_edge30, label %.preheader.us, !llvm.loop !11

._crit_edge30:                                    ; preds = %._crit_edge.us, %3
  %.025.lcssa = phi i32 [ 0, %3 ], [ %.2.us.lcssa, %._crit_edge.us ]
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %40 = icmp sgt i32 %.025.lcssa, 0
  br i1 %40, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %._crit_edge30
  %wide.trip.count43 = zext nneg i32 %.025.lcssa to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %._crit_edge30
  call void @llvm.lifetime.end.p0(i64 1200, ptr nonnull %4) #3
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv40 = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next41, %.lr.ph ]
  %41 = getelementptr inbounds [100 x [3 x i32]], ptr %4, i64 0, i64 %indvars.iv40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %41, i64 4
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %41, i64 8
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %42, i32 noundef %44, i32 noundef %46)
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond44.not = icmp eq i64 %indvars.iv.next41, %wide.trip.count43
  br i1 %exitcond44.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12
}

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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