; LLVM IR from AllAlgorithms/c :: algorithms (sparse-matrix-multiplication)

; 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.sparse = type { i32, i32, i32, [20 x i32], [20 x i32], [20 x i32] }

@.str.9 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @addMatrix(ptr dead_on_unwind noalias writable sret(%struct.sparse) align 4, ptr noundef byval(%struct.sparse) align 8, ptr noundef byval(%struct.sparse) align 8) #0

; 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

; Function Attrs: nounwind uwtable
declare dso_local void @readMatrix(ptr noundef) #0

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local void @printMatrix(ptr noundef byval(%struct.sparse) align 8) #0

; Function Attrs: nounwind uwtable
declare dso_local void @multiplyMatrix(ptr dead_on_unwind noalias writable sret(%struct.sparse) align 4, ptr noundef byval(%struct.sparse) align 8, ptr noundef byval(%struct.sparse) align 8) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.sparse, align 8
  %3 = alloca %struct.sparse, align 8
  %4 = alloca %struct.sparse, align 8
  %5 = alloca %struct.sparse, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 252, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 252, ptr %3) #3
  %6 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  call void @readMatrix(ptr noundef %2)
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  call void @readMatrix(ptr noundef %3)
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  call void @printMatrix(ptr noundef byval(%struct.sparse) align 8 %2)
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  call void @printMatrix(ptr noundef byval(%struct.sparse) align 8 %3)
  %10 = getelementptr inbounds %struct.sparse, ptr %2, i32 0, i32 0
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds %struct.sparse, ptr %3, i32 0, i32 0
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp eq i32 %11, %13
  br i1 %14, label %15, label %23

15:                                               ; preds = %0
  %16 = getelementptr inbounds %struct.sparse, ptr %2, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !10
  %18 = getelementptr inbounds %struct.sparse, ptr %3, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !10
  %20 = icmp eq i32 %17, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 252, ptr %4) #3
  call void @addMatrix(ptr dead_on_unwind writable sret(%struct.sparse) align 4 %4, ptr noundef byval(%struct.sparse) align 8 %2, ptr noundef byval(%struct.sparse) align 8 %3)
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.13)
  call void @printMatrix(ptr noundef byval(%struct.sparse) align 8 %4)
  call void @llvm.lifetime.end.p0(i64 252, ptr %4) #3
  br label %25

23:                                               ; preds = %15, %0
  %24 = call i32 (ptr, ...) @printf(ptr noundef @.str.14)
  br label %25

25:                                               ; preds = %23, %21
  %26 = getelementptr inbounds %struct.sparse, ptr %2, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !10
  %28 = getelementptr inbounds %struct.sparse, ptr %3, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp eq i32 %27, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 252, ptr %5) #3
  call void @multiplyMatrix(ptr dead_on_unwind writable sret(%struct.sparse) align 4 %5, ptr noundef byval(%struct.sparse) align 8 %2, ptr noundef byval(%struct.sparse) align 8 %3)
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.15)
  call void @printMatrix(ptr noundef byval(%struct.sparse) align 8 %5)
  call void @llvm.lifetime.end.p0(i64 252, ptr %5) #3
  br label %35

33:                                               ; preds = %25
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.16)
  br label %35

35:                                               ; preds = %33, %31
  call void @llvm.lifetime.end.p0(i64 252, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 252, ptr %2) #3
  ret i32 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 = { "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, !7, i64 0}
!6 = !{!"sparse", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 92, !8, i64 172}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, 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"

%struct.sparse = type { i32, i32, i32, [20 x i32], [20 x i32], [20 x i32] }

@.str.9 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [52 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @addMatrix(ptr dead_on_unwind noalias writable sret(%struct.sparse) align 4, ptr noundef byval(%struct.sparse) align 8, ptr noundef byval(%struct.sparse) align 8) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @readMatrix(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @printMatrix(ptr noundef byval(%struct.sparse) align 8) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @multiplyMatrix(ptr dead_on_unwind noalias writable sret(%struct.sparse) align 4, ptr noundef byval(%struct.sparse) align 8, ptr noundef byval(%struct.sparse) align 8) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.sparse, align 8
  %2 = alloca %struct.sparse, align 8
  %3 = alloca %struct.sparse, align 8
  %4 = alloca %struct.sparse, align 8
  call void @llvm.lifetime.start.p0(i64 252, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 252, ptr nonnull %2) #3
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  call void @readMatrix(ptr noundef nonnull %1)
  %6 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  call void @readMatrix(ptr noundef nonnull %2)
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  call void @printMatrix(ptr noundef nonnull byval(%struct.sparse) align 8 %1)
  %8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  call void @printMatrix(ptr noundef nonnull byval(%struct.sparse) align 8 %2)
  %9 = load i32, ptr %1, align 8, !tbaa !5
  %10 = load i32, ptr %2, align 8, !tbaa !5
  %11 = icmp eq i32 %9, %10
  br i1 %11, label %12, label %20

12:                                               ; preds = %0
  %13 = getelementptr inbounds i8, ptr %1, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !10
  %15 = getelementptr inbounds i8, ptr %2, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !10
  %17 = icmp eq i32 %14, %16
  br i1 %17, label %18, label %20

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 252, ptr nonnull %3) #3
  call void @addMatrix(ptr dead_on_unwind nonnull writable sret(%struct.sparse) align 4 %3, ptr noundef nonnull byval(%struct.sparse) align 8 %1, ptr noundef nonnull byval(%struct.sparse) align 8 %2)
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13)
  call void @printMatrix(ptr noundef nonnull byval(%struct.sparse) align 8 %3)
  call void @llvm.lifetime.end.p0(i64 252, ptr nonnull %3) #3
  br label %22

20:                                               ; preds = %12, %0
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14)
  br label %22

22:                                               ; preds = %20, %18
  %23 = getelementptr inbounds i8, ptr %1, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !10
  %25 = load i32, ptr %2, align 8, !tbaa !5
  %26 = icmp eq i32 %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 252, ptr nonnull %4) #3
  call void @multiplyMatrix(ptr dead_on_unwind nonnull writable sret(%struct.sparse) align 4 %4, ptr noundef nonnull byval(%struct.sparse) align 8 %1, ptr noundef nonnull byval(%struct.sparse) align 8 %2)
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15)
  call void @printMatrix(ptr noundef nonnull byval(%struct.sparse) align 8 %4)
  call void @llvm.lifetime.end.p0(i64 252, ptr nonnull %4) #3
  br label %31

29:                                               ; preds = %22
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16)
  br label %31

31:                                               ; preds = %29, %27
  call void @llvm.lifetime.end.p0(i64 252, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 252, ptr nonnull %1) #3
  ret i32 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 = { 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, !7, i64 0}
!6 = !{!"sparse", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 92, !8, i64 172}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass