; 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.59 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.69 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.70 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.71 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @sb_mat_malloc(i64 noundef, i64 noundef) #0

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

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

; 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 @sb_mat_free(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @sb_mat_fscanf(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %11, ptr noundef @.str.59, ptr noundef %5, ptr noundef %6)
  store i32 %12, ptr %4, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %1
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 2
  br i1 %15, label %16, label %35

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

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

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

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

28:                                               ; preds = %23
  %29 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %32

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

32:                                               ; preds = %30, %28
  %33 = phi ptr [ %29, %28 ], [ %31, %30 ]
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.1) #4
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %117

35:                                               ; preds = %13
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %38 = load i64, ptr %5, align 8, !tbaa !11
  %39 = load i64, ptr %6, align 8, !tbaa !11
  %40 = call ptr @sb_mat_malloc(i64 noundef %38, i64 noundef %39)
  store ptr %40, ptr %8, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %37
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %63, label %44

44:                                               ; preds = %41
  %45 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %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 !5
  br label %51

49:                                               ; preds = %44
  %50 = load ptr, ptr @stderr, align 8, !tbaa !5
  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.70) #4
  %54 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %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 !5
  br label %60

58:                                               ; preds = %51
  %59 = load ptr, ptr @stderr, align 8, !tbaa !5
  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) #4
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %116

63:                                               ; preds = %41
  br label %64

64:                                               ; preds = %63
  br label %65

65:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.sb_mat, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !13
  store ptr %68, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %69

69:                                               ; preds = %108, %65
  %70 = load i64, ptr %10, align 8, !tbaa !11
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.sb_mat, ptr %71, i32 0, i32 2
  %73 = load i64, ptr %72, align 8, !tbaa !15
  %74 = icmp ult i64 %70, %73
  br i1 %74, label %76, label %75

75:                                               ; preds = %69
  store i32 6, ptr %7, align 4
  br label %111

76:                                               ; preds = %69
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = load i64, ptr %10, align 8, !tbaa !11
  %80 = getelementptr inbounds double, ptr %78, i64 %79
  %81 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %77, ptr noundef @.str.71, ptr noundef %80)
  store i32 %81, ptr %4, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %76
  %83 = load i32, ptr %4, align 4, !tbaa !9
  %84 = icmp ne i32 %83, 1
  br i1 %84, label %85, label %105

85:                                               ; preds = %82
  %86 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %87 = icmp ne ptr %86, null
  br i1 %87, label %88, label %90

88:                                               ; preds = %85
  %89 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %92

90:                                               ; preds = %85
  %91 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %92

92:                                               ; preds = %90, %88
  %93 = phi ptr [ %89, %88 ], [ %91, %90 ]
  %94 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %93, ptr noundef @.str.69) #4
  %95 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %96 = icmp ne ptr %95, null
  br i1 %96, label %97, label %99

97:                                               ; preds = %92
  %98 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %101

99:                                               ; preds = %92
  %100 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %101

101:                                              ; preds = %99, %97
  %102 = phi ptr [ %98, %97 ], [ %100, %99 ]
  %103 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %102, ptr noundef @.str.1) #4
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  call void @sb_mat_free(ptr noundef %104)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %111

105:                                              ; preds = %82
  br label %106

106:                                              ; preds = %105
  br label %107

107:                                              ; preds = %106
  br label %108

108:                                              ; preds = %107
  %109 = load i64, ptr %10, align 8, !tbaa !11
  %110 = add i64 %109, 1
  store i64 %110, ptr %10, align 8, !tbaa !11
  br label %69, !llvm.loop !16

111:                                              ; preds = %101, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %112 = load i32, ptr %7, align 4
  switch i32 %112, label %115 [
    i32 6, label %113
  ]

113:                                              ; preds = %111
  %114 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %114, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %115

115:                                              ; preds = %113, %111
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %116

116:                                              ; preds = %115, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %117

117:                                              ; preds = %116, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %118 = load ptr, ptr %2, align 8
  ret ptr %118
}

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) #3

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

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !6, i64 24}
!15 = !{!14, !12, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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.59 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.69 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.70 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.71 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @sb_mat_malloc(i64 noundef, i64 noundef) 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: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; 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 @sb_mat_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @sb_mat_fscanf(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %4 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %0, ptr noundef nonnull @.str.59, ptr noundef nonnull %2, ptr noundef nonnull %3) #4
  %.not = icmp eq i32 %4, 2
  br i1 %.not, label %14, label %5

5:                                                ; preds = %1
  %6 = load ptr, ptr @sb_error_log, align 8
  %.not24 = icmp eq ptr %6, null
  %7 = load ptr, ptr @stderr, align 8
  %8 = select i1 %.not24, ptr %7, ptr %6
  %9 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.69) #4
  %10 = load ptr, ptr @sb_error_log, align 8
  %.not25 = icmp eq ptr %10, null
  %11 = load ptr, ptr @stderr, align 8
  %12 = select i1 %.not25, ptr %11, ptr %10
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.1) #4
  br label %.loopexit

14:                                               ; preds = %1
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = call ptr @sb_mat_malloc(i64 noundef %15, i64 noundef %16)
  %.not17 = icmp eq ptr %17, null
  br i1 %.not17, label %18, label %27

18:                                               ; preds = %14
  %19 = load ptr, ptr @sb_error_log, align 8
  %.not18 = icmp eq ptr %19, null
  %20 = load ptr, ptr @stderr, align 8
  %21 = select i1 %.not18, ptr %20, ptr %19
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.70) #4
  %23 = load ptr, ptr @sb_error_log, align 8
  %.not19 = icmp eq ptr %23, null
  %24 = load ptr, ptr @stderr, align 8
  %25 = select i1 %.not19, ptr %24, ptr %23
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.1) #4
  br label %.loopexit

27:                                               ; preds = %14
  %28 = getelementptr inbounds i8, ptr %17, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %17, i64 16
  %31 = load i64, ptr %30, align 8, !tbaa !12
  %.not2326.not = icmp eq i64 %31, 0
  br i1 %.not2326.not, label %.loopexit, label %.lr.ph

32:                                               ; preds = %.lr.ph
  %33 = add nuw i64 %.027, 1
  %34 = load i64, ptr %30, align 8, !tbaa !12
  %.not23 = icmp ult i64 %33, %34
  br i1 %.not23, label %.lr.ph, label %.loopexit, !llvm.loop !13

.lr.ph:                                           ; preds = %27, %32
  %.027 = phi i64 [ %33, %32 ], [ 0, %27 ]
  %35 = getelementptr inbounds double, ptr %29, i64 %.027
  %36 = call i32 (ptr, ptr, ...) @__isoc99_fscanf(ptr noundef %0, ptr noundef nonnull @.str.71, ptr noundef %35) #4
  %.not20 = icmp eq i32 %36, 1
  br i1 %.not20, label %32, label %37

37:                                               ; preds = %.lr.ph
  %38 = load ptr, ptr @sb_error_log, align 8
  %.not21 = icmp eq ptr %38, null
  %39 = load ptr, ptr @stderr, align 8
  %40 = select i1 %.not21, ptr %39, ptr %38
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str.69) #4
  %42 = load ptr, ptr @sb_error_log, align 8
  %.not22 = icmp eq ptr %42, null
  %43 = load ptr, ptr @stderr, align 8
  %44 = select i1 %.not22, ptr %43, ptr %42
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef nonnull @.str.1) #4
  call void @sb_mat_free(ptr noundef nonnull %17)
  br label %.loopexit

.loopexit:                                        ; preds = %32, %27, %37, %18, %5
  %.3 = phi ptr [ null, %5 ], [ null, %18 ], [ null, %37 ], [ %17, %27 ], [ %17, %32 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret ptr %.3
}

declare i32 @__isoc99_fscanf(ptr noundef, ptr noundef, ...) local_unnamed_addr #3

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 = { "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 }

!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, !11, i64 24}
!10 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass