; LLVM IR from harharkh/sb_desc :: src (matrix)

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

@sb_error_log = external global ptr, align 8
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [39 x i8], align 1

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @sb_mat_calloc(i64 noundef %0, i64 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %10 = call noalias ptr @malloc(i64 noundef 32) #6
  store ptr %10, ptr %6, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %6, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %33, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr @sb_error_log, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %18 = load ptr, ptr @sb_error_log, align 8, !tbaa !9
  br label %21

19:                                               ; preds = %14
  %20 = load ptr, ptr @stderr, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %19, %17
  %22 = phi ptr [ %18, %17 ], [ %20, %19 ]
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str.3) #5
  %24 = load ptr, ptr @sb_error_log, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %28

26:                                               ; preds = %21
  %27 = load ptr, ptr @sb_error_log, align 8, !tbaa !9
  br label %30

28:                                               ; preds = %21
  %29 = load ptr, ptr @stderr, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %28, %26
  %31 = phi ptr [ %27, %26 ], [ %29, %28 ]
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef @.str.1) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %81

33:                                               ; preds = %11
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %36 = load i64, ptr %4, align 8, !tbaa !5
  %37 = load i64, ptr %5, align 8, !tbaa !5
  %38 = mul i64 %36, %37
  store i64 %38, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %39 = load i64, ptr %8, align 8, !tbaa !5
  %40 = call noalias ptr @calloc(i64 noundef %39, i64 noundef 8) #7
  store ptr %40, ptr %9, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %35
  %42 = load ptr, ptr %9, align 8, !tbaa !9
  %43 = icmp ne ptr %42, null
  br i1 %43, label %64, label %44

44:                                               ; preds = %41
  %45 = load ptr, ptr @sb_error_log, align 8, !tbaa !9
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %49

47:                                               ; preds = %44
  %48 = load ptr, ptr @sb_error_log, align 8, !tbaa !9
  br label %51

49:                                               ; preds = %44
  %50 = load ptr, ptr @stderr, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %49, %47
  %52 = phi ptr [ %48, %47 ], [ %50, %49 ]
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str.4) #5
  %54 = load ptr, ptr @sb_error_log, align 8, !tbaa !9
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %58

56:                                               ; preds = %51
  %57 = load ptr, ptr @sb_error_log, align 8, !tbaa !9
  br label %60

58:                                               ; preds = %51
  %59 = load ptr, ptr @stderr, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %58, %56
  %61 = phi ptr [ %57, %56 ], [ %59, %58 ]
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef @.str.1) #5
  %63 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free(ptr noundef %63) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %80

64:                                               ; preds = %41
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %4, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.sb_mat, ptr %68, i32 0, i32 0
  store i64 %67, ptr %69, align 8, !tbaa !11
  %70 = load i64, ptr %5, align 8, !tbaa !5
  %71 = load ptr, ptr %6, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.sb_mat, ptr %71, i32 0, i32 1
  store i64 %70, ptr %72, align 8, !tbaa !13
  %73 = load i64, ptr %8, align 8, !tbaa !5
  %74 = load ptr, ptr %6, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.sb_mat, ptr %74, i32 0, i32 2
  store i64 %73, ptr %75, align 8, !tbaa !14
  %76 = load ptr, ptr %9, align 8, !tbaa !9
  %77 = load ptr, ptr %6, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.sb_mat, ptr %77, i32 0, i32 3
  store ptr %76, ptr %78, align 8, !tbaa !15
  %79 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %79, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %80

80:                                               ; preds = %66, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %81

81:                                               ; preds = %80, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %82 = load ptr, ptr %3, align 8
  ret ptr %82
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 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 #4 = { nounwind allocsize(0,1) "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 allocsize(0) }
attributes #7 = { nounwind allocsize(0,1) }

!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 = !{!"long", !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 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !10, i64 24}


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

@sb_error_log = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [39 x i8], align 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 #0

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @sb_mat_calloc(i64 noundef %0, i64 noundef %1) local_unnamed_addr #3 {
  %3 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %13

4:                                                ; preds = %2
  %5 = load ptr, ptr @sb_error_log, align 8
  %.not17 = icmp eq ptr %5, null
  %6 = load ptr, ptr @stderr, align 8
  %7 = select i1 %.not17, ptr %6, ptr %5
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.3) #6
  %9 = load ptr, ptr @sb_error_log, align 8
  %.not18 = icmp eq ptr %9, null
  %10 = load ptr, ptr @stderr, align 8
  %11 = select i1 %.not18, ptr %10, ptr %9
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.1) #6
  br label %29

13:                                               ; preds = %2
  %14 = mul i64 %1, %0
  %15 = tail call noalias ptr @calloc(i64 noundef %14, i64 noundef 8) #7
  %.not19 = icmp eq ptr %15, null
  br i1 %.not19, label %16, label %25

16:                                               ; preds = %13
  %17 = load ptr, ptr @sb_error_log, align 8
  %.not20 = icmp eq ptr %17, null
  %18 = load ptr, ptr @stderr, align 8
  %19 = select i1 %.not20, ptr %18, ptr %17
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.4) #6
  %21 = load ptr, ptr @sb_error_log, align 8
  %.not21 = icmp eq ptr %21, null
  %22 = load ptr, ptr @stderr, align 8
  %23 = select i1 %.not21, ptr %22, ptr %21
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.1) #6
  tail call void @free(ptr noundef nonnull %3) #6
  br label %29

25:                                               ; preds = %13
  store i64 %0, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %3, i64 8
  store i64 %1, ptr %26, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %3, i64 16
  store i64 %14, ptr %27, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr %15, ptr %28, align 8, !tbaa !13
  br label %29

29:                                               ; preds = %16, %25, %4
  %.1 = phi ptr [ null, %4 ], [ %3, %25 ], [ null, %16 ]
  ret ptr %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #4

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 = { 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 #4 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }

!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 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !10, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass