; 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.44 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [47 x i8], align 1

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

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

; 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) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @sb_mat_subcpy(ptr noalias noundef %0, i64 noundef %1, ptr noalias noundef %2, i64 noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %4
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %31, label %12

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

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

17:                                               ; preds = %12
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %19

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

24:                                               ; preds = %19
  %25 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %28

26:                                               ; preds = %19
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %26, %24
  %29 = phi ptr [ %25, %24 ], [ %27, %26 ]
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str.1) #4
  call void @abort() #5
  unreachable

31:                                               ; preds = %9
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %55, label %36

36:                                               ; preds = %33
  %37 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %41

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

41:                                               ; preds = %36
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %43

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

48:                                               ; preds = %43
  %49 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %52

50:                                               ; preds = %43
  %51 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %50, %48
  %53 = phi ptr [ %49, %48 ], [ %51, %50 ]
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str.1) #4
  call void @abort() #5
  unreachable

55:                                               ; preds = %33
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.sb_mat, ptr %58, i32 0, i32 2
  %60 = load i64, ptr %59, align 8, !tbaa !11
  %61 = load i64, ptr %6, align 8, !tbaa !9
  %62 = sub i64 %60, %61
  %63 = load i64, ptr %8, align 8, !tbaa !9
  %64 = icmp ult i64 %62, %63
  br i1 %64, label %65, label %84

65:                                               ; preds = %57
  %66 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %70

68:                                               ; preds = %65
  %69 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %72

70:                                               ; preds = %65
  %71 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %70, %68
  %73 = phi ptr [ %69, %68 ], [ %71, %70 ]
  %74 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %73, ptr noundef @.str.46) #4
  %75 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %79

77:                                               ; preds = %72
  %78 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %81

79:                                               ; preds = %72
  %80 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %81

81:                                               ; preds = %79, %77
  %82 = phi ptr [ %78, %77 ], [ %80, %79 ]
  %83 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %82, ptr noundef @.str.1) #4
  call void @abort() #5
  unreachable

84:                                               ; preds = %57
  br label %85

85:                                               ; preds = %84
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.sb_mat, ptr %86, i32 0, i32 3
  %88 = load ptr, ptr %87, align 8, !tbaa !13
  %89 = load i64, ptr %6, align 8, !tbaa !9
  %90 = getelementptr inbounds double, ptr %88, i64 %89
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = load i64, ptr %8, align 8, !tbaa !9
  %93 = mul i64 %92, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %90, ptr align 8 %91, i64 %93, i1 false)
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  ret ptr %94
}

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }
attributes #5 = { noreturn 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24}
!13 = !{!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.44 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [47 x i8], align 1

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

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

; 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) #2

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @sb_mat_subcpy(ptr noalias noundef readonly returned %0, i64 noundef %1, ptr noalias noundef readonly %2, i64 noundef %3) local_unnamed_addr #3 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %14

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

14:                                               ; preds = %4
  %.not13 = icmp eq ptr %2, null
  br i1 %.not13, label %15, label %24

15:                                               ; preds = %14
  %16 = load ptr, ptr @sb_error_log, align 8
  %.not14 = icmp eq ptr %16, null
  %17 = load ptr, ptr @stderr, align 8
  %18 = select i1 %.not14, ptr %17, ptr %16
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.45) #4
  %20 = load ptr, ptr @sb_error_log, align 8
  %.not15 = icmp eq ptr %20, null
  %21 = load ptr, ptr @stderr, align 8
  %22 = select i1 %.not15, ptr %21, ptr %20
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str.1) #4
  tail call void @abort() #5
  unreachable

24:                                               ; preds = %14
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = sub i64 %26, %1
  %28 = icmp ult i64 %27, %3
  br i1 %28, label %29, label %38

29:                                               ; preds = %24
  %30 = load ptr, ptr @sb_error_log, align 8
  %.not16 = icmp eq ptr %30, null
  %31 = load ptr, ptr @stderr, align 8
  %32 = select i1 %.not16, ptr %31, ptr %30
  %33 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.46) #4
  %34 = load ptr, ptr @sb_error_log, align 8
  %.not17 = icmp eq ptr %34, null
  %35 = load ptr, ptr @stderr, align 8
  %36 = select i1 %.not17, ptr %35, ptr %34
  %37 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str.1) #4
  tail call void @abort() #5
  unreachable

38:                                               ; preds = %24
  %39 = getelementptr inbounds i8, ptr %0, i64 24
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds double, ptr %40, i64 %1
  %42 = shl i64 %3, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %41, ptr nonnull align 8 %2, i64 %42, i1 false)
  ret ptr %0
}

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }
attributes #5 = { noreturn 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 16}
!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, !10, i64 24}


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