; 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.67 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.68 = external hidden unnamed_addr constant [35 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_fread(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call i64 @fread(ptr noundef %5, i64 noundef 8, i64 noundef 1, ptr noundef %10)
  store i64 %11, ptr %4, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %1
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = icmp ne i64 %13, 1
  br i1 %14, label %15, label %34

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.67) #4
  %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) #4
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %132

34:                                               ; preds = %12
  br label %35

35:                                               ; preds = %34
  br label %36

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

39:                                               ; preds = %36
  %40 = load i64, ptr %4, align 8, !tbaa !9
  %41 = icmp ne i64 %40, 1
  br i1 %41, label %42, label %61

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

45:                                               ; preds = %42
  %46 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %49

47:                                               ; preds = %42
  %48 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %49

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

54:                                               ; preds = %49
  %55 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %58

56:                                               ; preds = %49
  %57 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %58

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

61:                                               ; preds = %39
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %64 = load i64, ptr %5, align 8, !tbaa !9
  %65 = load i64, ptr %7, align 8, !tbaa !9
  %66 = call ptr @sb_mat_malloc(i64 noundef %64, i64 noundef %65)
  store ptr %66, ptr %8, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %63
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %89, label %70

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

73:                                               ; preds = %70
  %74 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %77

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

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

82:                                               ; preds = %77
  %83 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %86

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

86:                                               ; preds = %84, %82
  %87 = phi ptr [ %83, %82 ], [ %85, %84 ]
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef @.str.1) #4
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %130

89:                                               ; preds = %67
  br label %90

90:                                               ; preds = %89
  br label %91

91:                                               ; preds = %90
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.sb_mat, ptr %92, i32 0, i32 2
  %94 = load i64, ptr %93, align 8, !tbaa !11
  store i64 %94, ptr %9, align 8, !tbaa !9
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.sb_mat, ptr %95, i32 0, i32 3
  %97 = load ptr, ptr %96, align 8, !tbaa !13
  %98 = load i64, ptr %9, align 8, !tbaa !9
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  %100 = call i64 @fread(ptr noundef %97, i64 noundef 8, i64 noundef %98, ptr noundef %99)
  store i64 %100, ptr %4, align 8, !tbaa !9
  br label %101

101:                                              ; preds = %91
  %102 = load i64, ptr %4, align 8, !tbaa !9
  %103 = load i64, ptr %9, align 8, !tbaa !9
  %104 = icmp ne i64 %102, %103
  br i1 %104, label %105, label %125

105:                                              ; preds = %101
  %106 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %107 = icmp ne ptr %106, null
  br i1 %107, label %108, label %110

108:                                              ; preds = %105
  %109 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %112

110:                                              ; preds = %105
  %111 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %112

112:                                              ; preds = %110, %108
  %113 = phi ptr [ %109, %108 ], [ %111, %110 ]
  %114 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %113, ptr noundef @.str.67) #4
  %115 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  %116 = icmp ne ptr %115, null
  br i1 %116, label %117, label %119

117:                                              ; preds = %112
  %118 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %121

119:                                              ; preds = %112
  %120 = load ptr, ptr @stderr, align 8, !tbaa !5
  br label %121

121:                                              ; preds = %119, %117
  %122 = phi ptr [ %118, %117 ], [ %120, %119 ]
  %123 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %122, ptr noundef @.str.1) #4
  %124 = load ptr, ptr %8, align 8, !tbaa !5
  call void @sb_mat_free(ptr noundef %124)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %129

125:                                              ; preds = %101
  br label %126

126:                                              ; preds = %125
  br label %127

127:                                              ; preds = %126
  %128 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %128, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %129

129:                                              ; preds = %127, %121
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %130

130:                                              ; preds = %129, %86
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %131

131:                                              ; preds = %130, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %132

132:                                              ; preds = %131, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %133 = load ptr, ptr %2, align 8
  ret ptr %133
}

declare i64 @fread(ptr noundef, i64 noundef, i64 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 = !{!"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.67 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.68 = external hidden unnamed_addr constant [35 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_fread(ptr nocapture 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) #3
  %4 = call i64 @fread(ptr noundef nonnull %2, i64 noundef 8, i64 noundef 1, ptr noundef %0)
  %.not = icmp eq i64 %4, 1
  br i1 %.not, label %14, label %5

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

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %15 = call i64 @fread(ptr noundef nonnull %3, i64 noundef 8, i64 noundef 1, ptr noundef %0)
  %.not14 = icmp eq i64 %15, 1
  br i1 %.not14, label %25, label %16

16:                                               ; preds = %14
  %17 = load ptr, ptr @sb_error_log, align 8
  %.not21 = icmp eq ptr %17, null
  %18 = load ptr, ptr @stderr, align 8
  %19 = select i1 %.not21, ptr %18, ptr %17
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.67) #3
  %21 = load ptr, ptr @sb_error_log, align 8
  %.not22 = icmp eq ptr %21, null
  %22 = load ptr, ptr @stderr, align 8
  %23 = select i1 %.not22, ptr %22, ptr %21
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.1) #3
  br label %53

25:                                               ; preds = %14
  %26 = load i64, ptr %2, align 8, !tbaa !5
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = tail call ptr @sb_mat_malloc(i64 noundef %26, i64 noundef %27)
  %.not15 = icmp eq ptr %28, null
  br i1 %.not15, label %29, label %38

29:                                               ; preds = %25
  %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.68) #3
  %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) #3
  br label %53

38:                                               ; preds = %25
  %39 = getelementptr inbounds i8, ptr %28, i64 16
  %40 = load i64, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %28, i64 24
  %42 = load ptr, ptr %41, align 8, !tbaa !12
  %43 = tail call i64 @fread(ptr noundef %42, i64 noundef 8, i64 noundef %40, ptr noundef %0)
  %.not18 = icmp eq i64 %43, %40
  br i1 %.not18, label %53, label %44

44:                                               ; preds = %38
  %45 = load ptr, ptr @sb_error_log, align 8
  %.not19 = icmp eq ptr %45, null
  %46 = load ptr, ptr @stderr, align 8
  %47 = select i1 %.not19, ptr %46, ptr %45
  %48 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef nonnull @.str.67) #3
  %49 = load ptr, ptr @sb_error_log, align 8
  %.not20 = icmp eq ptr %49, null
  %50 = load ptr, ptr @stderr, align 8
  %51 = select i1 %.not20, ptr %50, ptr %49
  %52 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef nonnull @.str.1) #3
  tail call void @sb_mat_free(ptr noundef nonnull %28)
  br label %53

53:                                               ; preds = %29, %38, %44, %16
  %.2 = phi ptr [ null, %16 ], [ null, %29 ], [ null, %44 ], [ %28, %38 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %54

54:                                               ; preds = %53, %5
  %.3 = phi ptr [ null, %5 ], [ %.2, %53 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret ptr %.3
}

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

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 = { 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, !6, i64 16}
!10 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 24}


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