; LLVM IR from harharkh/sb_desc :: src (vector)

; 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_vec = type { i64, ptr, i8 }

@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.4 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [39 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

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

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

9:                                                ; preds = %2
  %10 = load i8, ptr %5, align 1, !tbaa !9
  %11 = sext i8 %10 to i32
  %12 = icmp ne i32 %11, 99
  br i1 %12, label %13, label %36

13:                                               ; preds = %9
  %14 = load i8, ptr %5, align 1, !tbaa !9
  %15 = sext i8 %14 to i32
  %16 = icmp ne i32 %15, 114
  br i1 %16, label %17, label %36

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

20:                                               ; preds = %17
  %21 = load ptr, ptr @sb_error_log, align 8, !tbaa !10
  br label %24

22:                                               ; preds = %17
  %23 = load ptr, ptr @stderr, align 8, !tbaa !10
  br label %24

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

29:                                               ; preds = %24
  %30 = load ptr, ptr @sb_error_log, align 8, !tbaa !10
  br label %33

31:                                               ; preds = %24
  %32 = load ptr, ptr @stderr, align 8, !tbaa !10
  br label %33

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

36:                                               ; preds = %13, %9
  br label %37

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

39:                                               ; preds = %37
  %40 = load ptr, ptr %6, align 8, !tbaa !10
  %41 = icmp ne ptr %40, null
  br i1 %41, label %61, label %42

42:                                               ; preds = %39
  %43 = load ptr, ptr @sb_error_log, align 8, !tbaa !10
  %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 !10
  br label %49

47:                                               ; preds = %42
  %48 = load ptr, ptr @stderr, align 8, !tbaa !10
  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.5) #6
  %52 = load ptr, ptr @sb_error_log, align 8, !tbaa !10
  %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 !10
  br label %58

56:                                               ; preds = %49
  %57 = load ptr, ptr @stderr, align 8, !tbaa !10
  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) #6
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %103

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) #6
  %64 = load i64, ptr %4, align 8, !tbaa !5
  %65 = call noalias ptr @calloc(i64 noundef %64, i64 noundef 8) #9
  store ptr %65, ptr %8, align 8, !tbaa !10
  br label %66

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

69:                                               ; preds = %66
  %70 = load ptr, ptr @sb_error_log, align 8, !tbaa !10
  %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 !10
  br label %76

74:                                               ; preds = %69
  %75 = load ptr, ptr @stderr, align 8, !tbaa !10
  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.6) #6
  %79 = load ptr, ptr @sb_error_log, align 8, !tbaa !10
  %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 !10
  br label %85

83:                                               ; preds = %76
  %84 = load ptr, ptr @stderr, align 8, !tbaa !10
  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) #6
  %88 = load ptr, ptr %6, align 8, !tbaa !10
  call void @free(ptr noundef %88) #6
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %102

89:                                               ; preds = %66
  br label %90

90:                                               ; preds = %89
  br label %91

91:                                               ; preds = %90
  %92 = load i64, ptr %4, align 8, !tbaa !5
  %93 = load ptr, ptr %6, align 8, !tbaa !10
  %94 = getelementptr inbounds %struct.sb_vec, ptr %93, i32 0, i32 0
  store i64 %92, ptr %94, align 8, !tbaa !12
  %95 = load ptr, ptr %8, align 8, !tbaa !10
  %96 = load ptr, ptr %6, align 8, !tbaa !10
  %97 = getelementptr inbounds %struct.sb_vec, ptr %96, i32 0, i32 1
  store ptr %95, ptr %97, align 8, !tbaa !14
  %98 = load i8, ptr %5, align 1, !tbaa !9
  %99 = load ptr, ptr %6, align 8, !tbaa !10
  %100 = getelementptr inbounds %struct.sb_vec, ptr %99, i32 0, i32 2
  store i8 %98, ptr %100, align 8, !tbaa !15
  %101 = load ptr, ptr %6, align 8, !tbaa !10
  store ptr %101, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %102

102:                                              ; preds = %91, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %103

103:                                              ; preds = %102, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %104 = load ptr, ptr %3, align 8
  ret ptr %104
}

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #5

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { nounwind allocsize(0,1) "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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { nounwind allocsize(0,1) }

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


; 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.4 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [39 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @sb_vec_calloc(i64 noundef %0, i8 noundef signext %1) local_unnamed_addr #4 {
  switch i8 %1, label %3 [
    i8 114, label %12
    i8 99, label %12
  ]

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

12:                                               ; preds = %2, %2
  %13 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #8
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %14, label %23

14:                                               ; preds = %12
  %15 = load ptr, ptr @sb_error_log, align 8
  %.not17 = icmp eq ptr %15, null
  %16 = load ptr, ptr @stderr, align 8
  %17 = select i1 %.not17, ptr %16, ptr %15
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str.5) #6
  %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 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str.1) #6
  br label %37

23:                                               ; preds = %12
  %24 = tail call noalias ptr @calloc(i64 noundef %0, i64 noundef 8) #9
  %.not19 = icmp eq ptr %24, null
  br i1 %.not19, label %25, label %34

25:                                               ; preds = %23
  %26 = load ptr, ptr @sb_error_log, align 8
  %.not20 = icmp eq ptr %26, null
  %27 = load ptr, ptr @stderr, align 8
  %28 = select i1 %.not20, ptr %27, ptr %26
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str.6) #6
  %30 = load ptr, ptr @sb_error_log, align 8
  %.not21 = icmp eq ptr %30, null
  %31 = load ptr, ptr @stderr, align 8
  %32 = select i1 %.not21, ptr %31, ptr %30
  %33 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.1) #6
  tail call void @free(ptr noundef nonnull %13) #6
  br label %37

34:                                               ; preds = %23
  store i64 %0, ptr %13, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %24, ptr %35, align 8, !tbaa !11
  %36 = getelementptr inbounds i8, ptr %13, i64 16
  store i8 %1, ptr %36, align 8, !tbaa !12
  br label %37

37:                                               ; preds = %25, %34, %14
  %.1 = phi ptr [ null, %14 ], [ %13, %34 ], [ null, %25 ]
  ret ptr %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #5

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 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 #3 = { 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 #4 = { 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 #5 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { nounwind allocsize(0,1) }

!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, !10, i64 8, !8, i64 16}
!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 8}
!12 = !{!6, !8, i64 16}


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