; 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.56 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [29 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

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

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

9:                                                ; preds = %2
  %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.56) #5
  %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) #5
  call void @abort() #6
  unreachable

31:                                               ; preds = %9
  br label %32

32:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.sb_mat, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call i64 @fwrite(ptr noundef %34, i64 noundef 8, i64 noundef 1, ptr noundef %35)
  store i64 %36, ptr %6, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %32
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = icmp ne i64 %38, 1
  br i1 %39, label %40, label %59

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.57) #5
  %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) #5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %127

59:                                               ; preds = %37
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.sb_mat, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = call i64 @fwrite(ptr noundef %63, i64 noundef 8, i64 noundef 1, ptr noundef %64)
  store i64 %65, ptr %6, align 8, !tbaa !9
  br label %66

66:                                               ; preds = %61
  %67 = load i64, ptr %6, align 8, !tbaa !9
  %68 = icmp ne i64 %67, 1
  br i1 %68, label %69, label %88

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

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

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

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

81:                                               ; preds = %76
  %82 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %85

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

85:                                               ; preds = %83, %81
  %86 = phi ptr [ %82, %81 ], [ %84, %83 ]
  %87 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %86, ptr noundef @.str.1) #5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %127

88:                                               ; preds = %66
  br label %89

89:                                               ; preds = %88
  br label %90

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

100:                                              ; preds = %90
  %101 = load i64, ptr %6, align 8, !tbaa !9
  %102 = load i64, ptr %8, align 8, !tbaa !9
  %103 = icmp ne i64 %101, %102
  br i1 %103, label %104, label %123

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

107:                                              ; preds = %104
  %108 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %111

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

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

116:                                              ; preds = %111
  %117 = load ptr, ptr @sb_error_log, align 8, !tbaa !5
  br label %120

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

120:                                              ; preds = %118, %116
  %121 = phi ptr [ %117, %116 ], [ %119, %118 ]
  %122 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %121, ptr noundef @.str.1) #5
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %126

123:                                              ; preds = %100
  br label %124

124:                                              ; preds = %123
  br label %125

125:                                              ; preds = %124
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %126

126:                                              ; preds = %125, %120
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %127

127:                                              ; preds = %126, %85, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %128 = load i32, ptr %3, align 4
  ret i32 %128
}

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #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 = { "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 = { 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.56 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.57 = external hidden unnamed_addr constant [29 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: nounwind uwtable
define dso_local range(i32 0, 2) i32 @sb_mat_fwrite(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %3, label %12

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

12:                                               ; preds = %2
  %13 = tail call i64 @fwrite(ptr noundef nonnull %1, i64 noundef 8, i64 noundef 1, ptr noundef %0)
  %.not16 = icmp eq i64 %13, 1
  br i1 %.not16, label %14, label %.sink.split

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  %16 = tail call i64 @fwrite(ptr noundef nonnull %15, i64 noundef 8, i64 noundef 1, ptr noundef %0)
  %.not17 = icmp eq i64 %16, 1
  br i1 %.not17, label %17, label %.sink.split

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %1, i64 16
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %1, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = tail call i64 @fwrite(ptr noundef %21, i64 noundef 8, i64 noundef %19, ptr noundef %0)
  %.not18 = icmp eq i64 %22, %19
  br i1 %.not18, label %31, label %.sink.split

.sink.split:                                      ; preds = %17, %14, %12
  %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 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.57) #3
  %27 = load ptr, ptr @sb_error_log, align 8
  %.not20 = icmp eq ptr %27, null
  %28 = load ptr, ptr @stderr, align 8
  %29 = select i1 %.not20, ptr %28, ptr %27
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str.1) #3
  br label %31

31:                                               ; preds = %.sink.split, %17
  %.1 = phi i32 [ 0, %17 ], [ 1, %.sink.split ]
  ret i32 %.1
}

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #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 = { 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 #3 = { nounwind }
attributes #4 = { 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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass