; 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.5 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.7 = 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_of_arr(ptr noundef %0, i64 noundef %1, i64 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %34, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %22

20:                                               ; preds = %15
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %22

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

27:                                               ; preds = %22
  %28 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %31

29:                                               ; preds = %22
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %29, %27
  %32 = phi ptr [ %28, %27 ], [ %30, %29 ]
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.1) #6
  call void @abort() #7
  unreachable

34:                                               ; preds = %12
  br label %35

35:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %36 = call noalias ptr @malloc(i64 noundef 32) #8
  store ptr %36, ptr %8, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %35
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %59, label %40

40:                                               ; preds = %37
  %41 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %45

43:                                               ; preds = %40
  %44 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %47

45:                                               ; preds = %40
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %45, %43
  %48 = phi ptr [ %44, %43 ], [ %46, %45 ]
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef @.str.6) #6
  %50 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %54

52:                                               ; preds = %47
  %53 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %56

54:                                               ; preds = %47
  %55 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %54, %52
  %57 = phi ptr [ %53, %52 ], [ %55, %54 ]
  %58 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %57, ptr noundef @.str.1) #6
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %111

59:                                               ; preds = %37
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %62 = load i64, ptr %6, align 8, !tbaa !9
  %63 = load i64, ptr %7, align 8, !tbaa !9
  %64 = mul i64 %62, %63
  store i64 %64, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %65 = load i64, ptr %10, align 8, !tbaa !9
  %66 = mul i64 %65, 8
  %67 = call noalias ptr @malloc(i64 noundef %66) #8
  store ptr %67, ptr %11, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %61
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = icmp ne ptr %69, null
  br i1 %70, label %91, label %71

71:                                               ; preds = %68
  %72 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %73 = icmp ne ptr %72, null
  br i1 %73, label %74, label %76

74:                                               ; preds = %71
  %75 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %78

76:                                               ; preds = %71
  %77 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %76, %74
  %79 = phi ptr [ %75, %74 ], [ %77, %76 ]
  %80 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %79, ptr noundef @.str.7) #6
  %81 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %85

83:                                               ; preds = %78
  %84 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %87

85:                                               ; preds = %78
  %86 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %87

87:                                               ; preds = %85, %83
  %88 = phi ptr [ %84, %83 ], [ %86, %85 ]
  %89 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %88, ptr noundef @.str.1) #6
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %90) #6
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %110

91:                                               ; preds = %68
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  %94 = load i64, ptr %6, align 8, !tbaa !9
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.sb_mat, ptr %95, i32 0, i32 0
  store i64 %94, ptr %96, align 8, !tbaa !11
  %97 = load i64, ptr %7, align 8, !tbaa !9
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.sb_mat, ptr %98, i32 0, i32 1
  store i64 %97, ptr %99, align 8, !tbaa !13
  %100 = load i64, ptr %10, align 8, !tbaa !9
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.sb_mat, ptr %101, i32 0, i32 2
  store i64 %100, ptr %102, align 8, !tbaa !14
  %103 = load ptr, ptr %11, align 8, !tbaa !5
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = load i64, ptr %10, align 8, !tbaa !9
  %106 = mul i64 %105, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %103, ptr align 8 %104, i64 %106, i1 false)
  %107 = load ptr, ptr %8, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.sb_mat, ptr %107, i32 0, i32 3
  store ptr %103, ptr %108, align 8, !tbaa !15
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %109, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %110

110:                                              ; preds = %93, %87
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %111

111:                                              ; preds = %110, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %112 = load ptr, ptr %4, align 8
  ret ptr %112
}

; Function Attrs: noreturn nounwind
declare void @abort() #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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 = { noreturn 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !6, 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.5 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.7 = 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_of_arr(ptr noundef readonly %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #3 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %13

4:                                                ; preds = %3
  %5 = load ptr, ptr @sb_error_log, align 8
  %.not21 = icmp eq ptr %5, null
  %6 = load ptr, ptr @stderr, align 8
  %7 = select i1 %.not21, ptr %6, ptr %5
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.5) #6
  %9 = load ptr, ptr @sb_error_log, align 8
  %.not22 = icmp eq ptr %9, null
  %10 = load ptr, ptr @stderr, align 8
  %11 = select i1 %.not22, ptr %10, ptr %9
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.1) #6
  tail call void @abort() #7
  unreachable

13:                                               ; preds = %3
  %14 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #8
  %.not23 = icmp eq ptr %14, null
  br i1 %.not23, label %15, label %24

15:                                               ; preds = %13
  %16 = load ptr, ptr @sb_error_log, align 8
  %.not24 = icmp eq ptr %16, null
  %17 = load ptr, ptr @stderr, align 8
  %18 = select i1 %.not24, ptr %17, ptr %16
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.6) #6
  %20 = load ptr, ptr @sb_error_log, align 8
  %.not25 = icmp eq ptr %20, null
  %21 = load ptr, ptr @stderr, align 8
  %22 = select i1 %.not25, ptr %21, ptr %20
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str.1) #6
  br label %41

24:                                               ; preds = %13
  %25 = mul i64 %2, %1
  %26 = shl i64 %25, 3
  %27 = tail call noalias ptr @malloc(i64 noundef %26) #8
  %.not26 = icmp eq ptr %27, null
  br i1 %.not26, label %28, label %37

28:                                               ; preds = %24
  %29 = load ptr, ptr @sb_error_log, align 8
  %.not27 = icmp eq ptr %29, null
  %30 = load ptr, ptr @stderr, align 8
  %31 = select i1 %.not27, ptr %30, ptr %29
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.7) #6
  %33 = load ptr, ptr @sb_error_log, align 8
  %.not28 = icmp eq ptr %33, null
  %34 = load ptr, ptr @stderr, align 8
  %35 = select i1 %.not28, ptr %34, ptr %33
  %36 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull @.str.1) #6
  tail call void @free(ptr noundef nonnull %14) #6
  br label %41

37:                                               ; preds = %24
  store i64 %1, ptr %14, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %14, i64 8
  store i64 %2, ptr %38, align 8, !tbaa !11
  %39 = getelementptr inbounds i8, ptr %14, i64 16
  store i64 %25, ptr %39, align 8, !tbaa !12
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %27, ptr nonnull align 8 %0, i64 %26, i1 false)
  %40 = getelementptr inbounds i8, ptr %14, i64 24
  store ptr %27, ptr %40, align 8, !tbaa !13
  br label %41

41:                                               ; preds = %28, %37, %15
  %.1 = phi ptr [ null, %15 ], [ %14, %37 ], [ null, %28 ]
  ret ptr %.1
}

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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 = { noreturn 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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, !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