; 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 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [39 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @sb_vec_malloc(i64 noundef %0, i8 noundef signext %1) #0 {
  %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) #5
  %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) #5
  call void @abort() #6
  unreachable

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

37:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %38 = call noalias ptr @malloc(i64 noundef 24) #7
  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.2) #5
  %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) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %104

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

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

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

75:                                               ; preds = %70
  %76 = load ptr, ptr @stderr, align 8, !tbaa !10
  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.3) #5
  %80 = load ptr, ptr @sb_error_log, align 8, !tbaa !10
  %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 !10
  br label %86

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

90:                                               ; preds = %67
  br label %91

91:                                               ; preds = %90
  br label %92

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

103:                                              ; preds = %92, %86
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %104

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

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

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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { nounwind allocsize(0) }

!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 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [39 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @sb_vec_malloc(i64 noundef %0, i8 noundef signext %1) local_unnamed_addr #0 {
  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) #5
  %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) #5
  tail call void @abort() #6
  unreachable

12:                                               ; preds = %2, %2
  %13 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #7
  %.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.2) #5
  %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) #5
  br label %38

23:                                               ; preds = %12
  %24 = shl i64 %0, 3
  %25 = tail call noalias ptr @malloc(i64 noundef %24) #7
  %.not19 = icmp eq ptr %25, null
  br i1 %.not19, label %26, label %35

26:                                               ; preds = %23
  %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.3) #5
  %31 = load ptr, ptr @sb_error_log, align 8
  %.not21 = icmp eq ptr %31, null
  %32 = load ptr, ptr @stderr, align 8
  %33 = select i1 %.not21, ptr %32, ptr %31
  %34 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str.1) #5
  tail call void @free(ptr noundef nonnull %13) #5
  br label %38

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

38:                                               ; preds = %26, %35, %14
  %.1 = phi ptr [ null, %14 ], [ %13, %35 ], [ null, %26 ]
  ret ptr %.1
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

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

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 = { 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 #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 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { nounwind allocsize(0) }

!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