; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (sparse)

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

@.str = external hidden unnamed_addr constant [35 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@__func__.sp_mat_alloc = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @sp_mat_alloc(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca [2048 x i8], align 16
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca [2048 x i8], align 16
  %18 = alloca i32, align 4
  %19 = alloca [2048 x i8], align 16
  %20 = alloca i32, align 4
  %21 = alloca [2048 x i8], align 16
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %12, align 4, !tbaa !9
  %24 = call noalias ptr @malloc(i64 noundef 40) #5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %24, ptr %25, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %34

29:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 40, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2048, ptr %14) #4
  %30 = getelementptr inbounds [2048 x i8], ptr %14, i64 0, i64 0
  %31 = load i32, ptr %13, align 4, !tbaa !9
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %30, ptr noundef @.str, ptr noundef @.str.1, i32 noundef %31)
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds [2048 x i8], ptr %14, i64 0, i64 0
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %32, ptr noundef @.str.2, ptr noundef @__func__.sp_mat_alloc, i32 noundef 19, ptr noundef %33)
  call void @llvm.lifetime.end.p0(i64 2048, ptr %14) #4
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %113

34:                                               ; preds = %5
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = mul i64 %36, 8
  %38 = call noalias ptr @malloc(i64 noundef %37) #5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.sparse_matrix, ptr %40, i32 0, i32 5
  store ptr %38, ptr %41, align 8, !tbaa !11
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.sparse_matrix, ptr %43, i32 0, i32 5
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %56

47:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = mul i64 %49, 8
  %51 = trunc i64 %50 to i32
  store i32 %51, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2048, ptr %17) #4
  %52 = getelementptr inbounds [2048 x i8], ptr %17, i64 0, i64 0
  %53 = load i32, ptr %16, align 4, !tbaa !9
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %52, ptr noundef @.str, ptr noundef @.str.3, i32 noundef %53)
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds [2048 x i8], ptr %17, i64 0, i64 0
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %54, ptr noundef @.str.2, ptr noundef @__func__.sp_mat_alloc, i32 noundef 20, ptr noundef %55)
  call void @llvm.lifetime.end.p0(i64 2048, ptr %17) #4
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %113

56:                                               ; preds = %34
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = mul i64 %58, 4
  %60 = call noalias ptr @malloc(i64 noundef %59) #5
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.sparse_matrix, ptr %62, i32 0, i32 4
  store ptr %60, ptr %63, align 8, !tbaa !13
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.sparse_matrix, ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = icmp eq ptr %67, null
  br i1 %68, label %69, label %78

69:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = mul i64 %71, 4
  %73 = trunc i64 %72 to i32
  store i32 %73, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2048, ptr %19) #4
  %74 = getelementptr inbounds [2048 x i8], ptr %19, i64 0, i64 0
  %75 = load i32, ptr %18, align 4, !tbaa !9
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %74, ptr noundef @.str, ptr noundef @.str.4, i32 noundef %75)
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = getelementptr inbounds [2048 x i8], ptr %19, i64 0, i64 0
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %76, ptr noundef @.str.2, ptr noundef @__func__.sp_mat_alloc, i32 noundef 21, ptr noundef %77)
  call void @llvm.lifetime.end.p0(i64 2048, ptr %19) #4
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  br label %113

78:                                               ; preds = %56
  %79 = load i32, ptr %12, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = mul i64 %80, 4
  %82 = call noalias ptr @malloc(i64 noundef %81) #5
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.sparse_matrix, ptr %84, i32 0, i32 3
  store ptr %82, ptr %85, align 8, !tbaa !14
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = load ptr, ptr %86, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.sparse_matrix, ptr %87, i32 0, i32 3
  %89 = load ptr, ptr %88, align 8, !tbaa !14
  %90 = icmp eq ptr %89, null
  br i1 %90, label %91, label %100

91:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  %92 = load i32, ptr %12, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = mul i64 %93, 4
  %95 = trunc i64 %94 to i32
  store i32 %95, ptr %20, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2048, ptr %21) #4
  %96 = getelementptr inbounds [2048 x i8], ptr %21, i64 0, i64 0
  %97 = load i32, ptr %20, align 4, !tbaa !9
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %96, ptr noundef @.str, ptr noundef @.str.5, i32 noundef %97)
  %98 = load ptr, ptr %11, align 8, !tbaa !5
  %99 = getelementptr inbounds [2048 x i8], ptr %21, i64 0, i64 0
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %98, ptr noundef @.str.2, ptr noundef @__func__.sp_mat_alloc, i32 noundef 22, ptr noundef %99)
  call void @llvm.lifetime.end.p0(i64 2048, ptr %21) #4
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  br label %113

100:                                              ; preds = %78
  %101 = load i32, ptr %8, align 4, !tbaa !9
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = load ptr, ptr %102, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.sparse_matrix, ptr %103, i32 0, i32 0
  store i32 %101, ptr %104, align 8, !tbaa !15
  %105 = load i32, ptr %9, align 4, !tbaa !9
  %106 = load ptr, ptr %7, align 8, !tbaa !5
  %107 = load ptr, ptr %106, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.sparse_matrix, ptr %107, i32 0, i32 1
  store i32 %105, ptr %108, align 4, !tbaa !16
  %109 = load i32, ptr %10, align 4, !tbaa !9
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = load ptr, ptr %110, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.sparse_matrix, ptr %111, i32 0, i32 2
  store i32 %109, ptr %112, align 8, !tbaa !17
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %113

113:                                              ; preds = %100, %91, %69, %47, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %114 = load i32, ptr %6, align 4
  ret i32 %114
}

; 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

declare void @class_protect_sprintf(ptr noundef, ptr noundef, ...) #3

; 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 = { "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 }
attributes #5 = { 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 = !{!12, !6, i64 32}
!12 = !{!"sparse_matrix", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 24}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !10, i64 4}
!17 = !{!12, !10, i64 8}


; 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 [35 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@__func__.sp_mat_alloc = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @sp_mat_alloc(ptr nocapture noundef writeonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca [2048 x i8], align 16
  %7 = alloca [2048 x i8], align 16
  %8 = alloca [2048 x i8], align 16
  %9 = alloca [2048 x i8], align 16
  %10 = add nsw i32 %1, 1
  %11 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #4
  store ptr %11, ptr %0, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %6) #5
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef nonnull %6, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 40) #5
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %4, ptr noundef nonnull @.str.2, ptr noundef nonnull @__func__.sp_mat_alloc, i32 noundef 19, ptr noundef nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %6) #5
  br label %40

14:                                               ; preds = %5
  %15 = sext i32 %3 to i64
  %16 = shl nsw i64 %15, 3
  %17 = tail call noalias ptr @malloc(i64 noundef %16) #4
  %18 = getelementptr inbounds i8, ptr %11, i64 32
  store ptr %17, ptr %18, align 8, !tbaa !9
  %19 = icmp eq ptr %17, null
  br i1 %19, label %20, label %22

20:                                               ; preds = %14
  %21 = trunc i64 %16 to i32
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %7) #5
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef nonnull %7, ptr noundef nonnull @.str, ptr noundef nonnull @.str.3, i32 noundef %21) #5
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %4, ptr noundef nonnull @.str.2, ptr noundef nonnull @__func__.sp_mat_alloc, i32 noundef 20, ptr noundef nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %7) #5
  br label %40

22:                                               ; preds = %14
  %23 = shl nsw i64 %15, 2
  %24 = tail call noalias ptr @malloc(i64 noundef %23) #4
  %25 = getelementptr inbounds i8, ptr %11, i64 24
  store ptr %24, ptr %25, align 8, !tbaa !12
  %26 = icmp eq ptr %24, null
  br i1 %26, label %27, label %29

27:                                               ; preds = %22
  %28 = trunc i64 %23 to i32
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %8) #5
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef nonnull %8, ptr noundef nonnull @.str, ptr noundef nonnull @.str.4, i32 noundef %28) #5
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %4, ptr noundef nonnull @.str.2, ptr noundef nonnull @__func__.sp_mat_alloc, i32 noundef 21, ptr noundef nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %8) #5
  br label %40

29:                                               ; preds = %22
  %30 = sext i32 %10 to i64
  %31 = shl nsw i64 %30, 2
  %32 = tail call noalias ptr @malloc(i64 noundef %31) #4
  %33 = getelementptr inbounds i8, ptr %11, i64 16
  store ptr %32, ptr %33, align 8, !tbaa !13
  %34 = icmp eq ptr %32, null
  br i1 %34, label %35, label %37

35:                                               ; preds = %29
  %36 = trunc i64 %31 to i32
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %9) #5
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef nonnull %9, ptr noundef nonnull @.str, ptr noundef nonnull @.str.5, i32 noundef %36) #5
  call void (ptr, ptr, ...) @class_protect_sprintf(ptr noundef %4, ptr noundef nonnull @.str.2, ptr noundef nonnull @__func__.sp_mat_alloc, i32 noundef 22, ptr noundef nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %9) #5
  br label %40

37:                                               ; preds = %29
  store i32 %1, ptr %11, align 8, !tbaa !14
  %38 = getelementptr inbounds i8, ptr %11, i64 4
  store i32 %2, ptr %38, align 4, !tbaa !15
  %39 = getelementptr inbounds i8, ptr %11, i64 8
  store i32 %3, ptr %39, align 8, !tbaa !16
  br label %40

40:                                               ; preds = %37, %35, %27, %20, %13
  %.0 = phi i32 [ 1, %13 ], [ 1, %20 ], [ 1, %27 ], [ 1, %35 ], [ 0, %37 ]
  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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

declare void @class_protect_sprintf(ptr noundef, ptr noundef, ...) 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

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 = { 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 #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 allocsize(0) }
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, !6, i64 32}
!10 = !{!"sparse_matrix", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 24}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !11, i64 0}
!15 = !{!10, !11, i64 4}
!16 = !{!10, !11, i64 8}


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