; LLVM IR from caryll/otfcc :: dep/extern (sds)

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden signext i8 @sdsReqType(i64 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @sdsHdrSize(i8 noundef signext) #1

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @sdssetlen(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @sdsMakeRoomFor(ptr noundef %0, i64 noundef %1) #5 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call i64 @sdsavail(ptr noundef %15)
  store i64 %16, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #7
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 -1
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = sext i8 %19 to i32
  %21 = and i32 %20, 7
  %22 = trunc i32 %21 to i8
  store i8 %22, ptr %12, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = load i64, ptr %5, align 8, !tbaa !9
  %25 = icmp uge i64 %23, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %2
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %27, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %111

28:                                               ; preds = %2
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i64 @sdslen(ptr noundef %29)
  store i64 %30, ptr %9, align 8, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i8, ptr %12, align 1, !tbaa !11
  %33 = call i32 @sdsHdrSize(i8 noundef signext %32)
  %34 = sext i32 %33 to i64
  %35 = sub i64 0, %34
  %36 = getelementptr inbounds i8, ptr %31, i64 %35
  store ptr %36, ptr %6, align 8, !tbaa !5
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = load i64, ptr %5, align 8, !tbaa !9
  %39 = add i64 %37, %38
  store i64 %39, ptr %10, align 8, !tbaa !9
  %40 = load i64, ptr %10, align 8, !tbaa !9
  %41 = icmp ult i64 %40, 1048576
  br i1 %41, label %42, label %45

42:                                               ; preds = %28
  %43 = load i64, ptr %10, align 8, !tbaa !9
  %44 = mul i64 %43, 2
  store i64 %44, ptr %10, align 8, !tbaa !9
  br label %48

45:                                               ; preds = %28
  %46 = load i64, ptr %10, align 8, !tbaa !9
  %47 = add i64 %46, 1048576
  store i64 %47, ptr %10, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %45, %42
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = call signext i8 @sdsReqType(i64 noundef %49)
  store i8 %50, ptr %11, align 1, !tbaa !11
  %51 = load i8, ptr %11, align 1, !tbaa !11
  %52 = sext i8 %51 to i32
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %48
  store i8 1, ptr %11, align 1, !tbaa !11
  br label %55

55:                                               ; preds = %54, %48
  %56 = load i8, ptr %11, align 1, !tbaa !11
  %57 = call i32 @sdsHdrSize(i8 noundef signext %56)
  store i32 %57, ptr %13, align 4, !tbaa !12
  %58 = load i8, ptr %12, align 1, !tbaa !11
  %59 = sext i8 %58 to i32
  %60 = load i8, ptr %11, align 1, !tbaa !11
  %61 = sext i8 %60 to i32
  %62 = icmp eq i32 %59, %61
  br i1 %62, label %63, label %79

63:                                               ; preds = %55
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load i32, ptr %13, align 4, !tbaa !12
  %66 = sext i32 %65 to i64
  %67 = load i64, ptr %10, align 8, !tbaa !9
  %68 = add i64 %66, %67
  %69 = add i64 %68, 1
  %70 = call ptr @realloc(ptr noundef %64, i64 noundef %69) #8
  store ptr %70, ptr %7, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = icmp eq ptr %71, null
  br i1 %72, label %73, label %74

73:                                               ; preds = %63
  store ptr null, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %111

74:                                               ; preds = %63
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = load i32, ptr %13, align 4, !tbaa !12
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i8, ptr %75, i64 %77
  store ptr %78, ptr %4, align 8, !tbaa !5
  br label %107

79:                                               ; preds = %55
  %80 = load i32, ptr %13, align 4, !tbaa !12
  %81 = sext i32 %80 to i64
  %82 = load i64, ptr %10, align 8, !tbaa !9
  %83 = add i64 %81, %82
  %84 = add i64 %83, 1
  %85 = call noalias ptr @malloc(i64 noundef %84) #9
  store ptr %85, ptr %7, align 8, !tbaa !5
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = icmp eq ptr %86, null
  br i1 %87, label %88, label %89

88:                                               ; preds = %79
  store ptr null, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %111

89:                                               ; preds = %79
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = load i32, ptr %13, align 4, !tbaa !12
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds i8, ptr %90, i64 %92
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = load i64, ptr %9, align 8, !tbaa !9
  %96 = add i64 %95, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %93, ptr align 1 %94, i64 %96, i1 false)
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %97) #7
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = load i32, ptr %13, align 4, !tbaa !12
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i8, ptr %98, i64 %100
  store ptr %101, ptr %4, align 8, !tbaa !5
  %102 = load i8, ptr %11, align 1, !tbaa !11
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = getelementptr inbounds i8, ptr %103, i64 -1
  store i8 %102, ptr %104, align 1, !tbaa !11
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = load i64, ptr %9, align 8, !tbaa !9
  call void @sdssetlen(ptr noundef %105, i64 noundef %106)
  br label %107

107:                                              ; preds = %89, %74
  %108 = load ptr, ptr %4, align 8, !tbaa !5
  %109 = load i64, ptr %10, align 8, !tbaa !9
  call void @sdssetalloc(ptr noundef %108, i64 noundef %109)
  %110 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %110, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %111

111:                                              ; preds = %107, %88, %73, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %112 = load ptr, ptr %3, align 8
  ret ptr %112
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdsavail(ptr noundef) #1

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #6

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @sdssetalloc(ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 #6 = { nounwind allocsize(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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(1) }
attributes #9 = { 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 = !{!"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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}


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

; Function Attrs: inlinehint nounwind uwtable
declare hidden signext i8 @sdsReqType(i64 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @sdsHdrSize(i8 noundef signext) local_unnamed_addr #0

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) local_unnamed_addr #0

; 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: inlinehint nounwind uwtable
declare hidden void @sdssetlen(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @sdsMakeRoomFor(ptr noundef %0, i64 noundef %1) local_unnamed_addr #4 {
  %3 = tail call i64 @sdsavail(ptr noundef %0)
  %.not = icmp ult i64 %3, %1
  br i1 %.not, label %4, label %36

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 -1
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = and i8 %6, 7
  %8 = tail call i64 @sdslen(ptr noundef nonnull %0)
  %9 = tail call i32 @sdsHdrSize(i8 noundef signext %7)
  %10 = sext i32 %9 to i64
  %11 = sub nsw i64 0, %10
  %12 = getelementptr inbounds i8, ptr %0, i64 %11
  %13 = add i64 %8, %1
  %14 = icmp ult i64 %13, 1048576
  %15 = shl nuw nsw i64 %13, 1
  %16 = add i64 %13, 1048576
  %.042 = select i1 %14, i64 %15, i64 %16
  %17 = tail call signext i8 @sdsReqType(i64 noundef %.042)
  %spec.store.select = tail call i8 @llvm.umax.i8(i8 %17, i8 1)
  %18 = tail call i32 @sdsHdrSize(i8 noundef signext %spec.store.select)
  %19 = icmp eq i8 %7, %spec.store.select
  %20 = sext i32 %18 to i64
  %21 = add i64 %.042, 1
  %22 = add i64 %21, %20
  br i1 %19, label %23, label %28

23:                                               ; preds = %4
  %24 = tail call ptr @realloc(ptr noundef nonnull %12, i64 noundef %22) #7
  %25 = icmp eq ptr %24, null
  br i1 %25, label %36, label %26

26:                                               ; preds = %23
  %27 = getelementptr inbounds i8, ptr %24, i64 %20
  br label %35

28:                                               ; preds = %4
  %29 = tail call noalias ptr @malloc(i64 noundef %22) #8
  %30 = icmp eq ptr %29, null
  br i1 %30, label %36, label %31

31:                                               ; preds = %28
  %32 = getelementptr inbounds i8, ptr %29, i64 %20
  %33 = add i64 %8, 1
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %32, ptr nonnull align 1 %0, i64 %33, i1 false)
  tail call void @free(ptr noundef nonnull %12) #9
  %34 = getelementptr inbounds i8, ptr %32, i64 -1
  store i8 %spec.store.select, ptr %34, align 1, !tbaa !5
  tail call void @sdssetlen(ptr noundef nonnull %32, i64 noundef %8)
  br label %35

35:                                               ; preds = %31, %26
  %.041 = phi ptr [ %27, %26 ], [ %32, %31 ]
  tail call void @sdssetalloc(ptr noundef %.041, i64 noundef %.042)
  br label %36

36:                                               ; preds = %28, %23, %2, %35
  %.0 = phi ptr [ %.041, %35 ], [ %0, %2 ], [ null, %23 ], [ null, %28 ]
  ret ptr %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdsavail(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #5

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @sdssetalloc(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.umax.i8(i8, i8) #6

attributes #0 = { inlinehint 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 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 nounwind willreturn allockind("realloc") allocsize(1) 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 #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nounwind allocsize(1) }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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