; LLVM IR from CMU-SAFARI/prim-benchmarks :: SpMV/data/generate (replicate)

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

@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca %struct.COOMatrix, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, 1
  br i1 %17, label %18, label %22

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds ptr, ptr %19, i64 1
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  br label %23

22:                                               ; preds = %2
  br label %23

23:                                               ; preds = %22, %18
  %24 = phi ptr [ %21, %18 ], [ @.str, %22 ]
  store ptr %24, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = icmp sgt i32 %25, 2
  br i1 %26, label %27, label %32

27:                                               ; preds = %23
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  %29 = getelementptr inbounds ptr, ptr %28, i64 2
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = call i32 @atoi(ptr noundef %30) #6
  br label %33

32:                                               ; preds = %23
  br label %33

33:                                               ; preds = %32, %27
  %34 = phi i32 [ %31, %27 ], [ 4, %32 ]
  store i32 %34, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = icmp sgt i32 %35, 3
  br i1 %36, label %37, label %41

37:                                               ; preds = %33
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = getelementptr inbounds ptr, ptr %38, i64 3
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  br label %42

41:                                               ; preds = %33
  br label %42

42:                                               ; preds = %41, %37
  %43 = phi ptr [ %40, %37 ], [ @.str.1, %41 ]
  store ptr %43, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #5
  %44 = load ptr, ptr %6, align 8, !tbaa !9
  call void @readCOOMatrix(ptr dead_on_unwind writable sret(%struct.COOMatrix) align 8 %9, ptr noundef %44)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  %46 = call noalias ptr @fopen(ptr noundef %45, ptr noundef @.str.2)
  store ptr %46, ptr %10, align 8, !tbaa !9
  %47 = load ptr, ptr %10, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.COOMatrix, ptr %9, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !11
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = mul i32 %49, %50
  %52 = getelementptr inbounds %struct.COOMatrix, ptr %9, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !13
  %54 = getelementptr inbounds %struct.COOMatrix, ptr %9, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !14
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = mul i32 %55, %56
  %58 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef @.str.3, i32 noundef %51, i32 noundef %53, i32 noundef %57) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %99, %42
  %60 = load i32, ptr %11, align 4, !tbaa !5
  %61 = getelementptr inbounds %struct.COOMatrix, ptr %9, i32 0, i32 2
  %62 = load i32, ptr %61, align 8, !tbaa !14
  %63 = icmp ult i32 %60, %62
  br i1 %63, label %65, label %64

64:                                               ; preds = %59
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %102

65:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %66 = getelementptr inbounds %struct.COOMatrix, ptr %9, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  %68 = load i32, ptr %11, align 4, !tbaa !5
  %69 = zext i32 %68 to i64
  %70 = getelementptr inbounds i32, ptr %67, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  store i32 %71, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %72 = getelementptr inbounds %struct.COOMatrix, ptr %9, i32 0, i32 4
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = load i32, ptr %11, align 4, !tbaa !5
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %73, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  store i32 %77, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %95, %65
  %79 = load i32, ptr %15, align 4, !tbaa !5
  %80 = load i32, ptr %7, align 4, !tbaa !5
  %81 = icmp ult i32 %79, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %78
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %98

83:                                               ; preds = %78
  %84 = load ptr, ptr %10, align 8, !tbaa !9
  %85 = load i32, ptr %13, align 4, !tbaa !5
  %86 = add i32 %85, 1
  %87 = load i32, ptr %15, align 4, !tbaa !5
  %88 = getelementptr inbounds %struct.COOMatrix, ptr %9, i32 0, i32 0
  %89 = load i32, ptr %88, align 8, !tbaa !11
  %90 = mul i32 %87, %89
  %91 = add i32 %86, %90
  %92 = load i32, ptr %14, align 4, !tbaa !5
  %93 = add i32 %92, 1
  %94 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %84, ptr noundef @.str.4, i32 noundef %91, i32 noundef %93) #5
  br label %95

95:                                               ; preds = %83
  %96 = load i32, ptr %15, align 4, !tbaa !5
  %97 = add i32 %96, 1
  store i32 %97, ptr %15, align 4, !tbaa !5
  br label %78, !llvm.loop !17

98:                                               ; preds = %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %99

99:                                               ; preds = %98
  %100 = load i32, ptr %11, align 4, !tbaa !5
  %101 = add i32 %100, 1
  store i32 %101, ptr %11, align 4, !tbaa !5
  br label %59, !llvm.loop !19

102:                                              ; preds = %64
  %103 = load ptr, ptr %10, align 8, !tbaa !9
  %104 = call i32 @fclose(ptr noundef %103)
  call void @freeCOOMatrix(ptr noundef byval(%struct.COOMatrix) align 8 %9)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %105 = load i32, ptr %3, align 4
  ret i32 %105
}

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #2

; Function Attrs: nounwind uwtable
declare hidden void @readCOOMatrix(ptr dead_on_unwind noalias writable sret(%struct.COOMatrix) align 8, ptr noundef) #0

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

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

declare i32 @fclose(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @freeCOOMatrix(ptr noundef byval(%struct.COOMatrix) align 8) #0

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 = { inlinehint nounwind willreturn memory(read) 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 = { "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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!12, !6, i64 0}
!12 = !{!"COOMatrix", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !10, i64 16}
!16 = !{!12, !10, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

%struct.COOMatrix = type { i32, i32, i32, ptr, ptr }

@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.COOMatrix, align 8
  %4 = icmp sgt i32 %0, 1
  br i1 %4, label %5, label %.thread24

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %.thread24, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %1, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = tail call i32 @atoi(ptr nocapture noundef %10) #4
  %12 = icmp ugt i32 %0, 3
  br i1 %12, label %13, label %.thread24

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %1, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  br label %.thread24

.thread24:                                        ; preds = %2, %5, %8, %13
  %16 = phi i32 [ %11, %13 ], [ %11, %8 ], [ 4, %5 ], [ 4, %2 ]
  %17 = phi ptr [ %7, %13 ], [ %7, %8 ], [ %7, %5 ], [ @.str, %2 ]
  %18 = phi ptr [ %15, %13 ], [ @.str.1, %8 ], [ @.str.1, %5 ], [ @.str.1, %2 ]
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #5
  call void @readCOOMatrix(ptr dead_on_unwind nonnull writable sret(%struct.COOMatrix) align 8 %3, ptr noundef %17)
  %19 = call noalias ptr @fopen(ptr noundef %18, ptr noundef nonnull @.str.2)
  %20 = load i32, ptr %3, align 8, !tbaa !9
  %21 = mul i32 %20, %16
  %22 = getelementptr inbounds i8, ptr %3, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %3, i64 8
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = mul i32 %25, %16
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.3, i32 noundef %21, i32 noundef %23, i32 noundef %26) #5
  %28 = load i32, ptr %24, align 8, !tbaa !13
  %.not29 = icmp eq i32 %28, 0
  br i1 %.not29, label %._crit_edge28, label %.lr.ph27

.lr.ph27:                                         ; preds = %.thread24
  %29 = getelementptr inbounds i8, ptr %3, i64 16
  %30 = getelementptr inbounds i8, ptr %3, i64 24
  %.not30 = icmp eq i32 %16, 0
  br i1 %.not30, label %._crit_edge28, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph27, %._crit_edge.us
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge.us ], [ 0, %.lr.ph27 ]
  %31 = load ptr, ptr %29, align 8, !tbaa !14
  %32 = getelementptr inbounds i32, ptr %31, i64 %indvars.iv
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = load ptr, ptr %30, align 8, !tbaa !16
  %35 = getelementptr inbounds i32, ptr %34, i64 %indvars.iv
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = add i32 %33, 1
  %38 = add i32 %36, 1
  br label %39

39:                                               ; preds = %.lr.ph.us, %39
  %.025.us = phi i32 [ 0, %.lr.ph.us ], [ %44, %39 ]
  %40 = load i32, ptr %3, align 8, !tbaa !9
  %41 = mul i32 %40, %.025.us
  %42 = add i32 %37, %41
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.4, i32 noundef %42, i32 noundef %38) #5
  %44 = add nuw i32 %.025.us, 1
  %exitcond.not = icmp eq i32 %44, %16
  br i1 %exitcond.not, label %._crit_edge.us, label %39, !llvm.loop !17

._crit_edge.us:                                   ; preds = %39
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %45 = load i32, ptr %24, align 8, !tbaa !13
  %46 = zext i32 %45 to i64
  %47 = icmp ult i64 %indvars.iv.next, %46
  br i1 %47, label %.lr.ph.us, label %._crit_edge28, !llvm.loop !19

._crit_edge28:                                    ; preds = %._crit_edge.us, %.lr.ph27, %.thread24
  %48 = call i32 @fclose(ptr noundef %19)
  call void @freeCOOMatrix(ptr noundef nonnull byval(%struct.COOMatrix) align 8 %3)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @readCOOMatrix(ptr dead_on_unwind noalias writable sret(%struct.COOMatrix) align 8, ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; 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 @fclose(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @freeCOOMatrix(ptr noundef byval(%struct.COOMatrix) align 8) local_unnamed_addr #0

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


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