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

%struct.sdshdr8 = type { i8, i8, i8, [0 x i8] }
%struct.sdshdr16 = type <{ i16, i16, i8, [0 x i8] }>
%struct.sdshdr32 = type <{ i32, i32, i8, [0 x i8] }>
%struct.sdshdr64 = type <{ i64, i64, i8, [0 x i8] }>

; Function Attrs: nounwind uwtable
define dso_local ptr @sdsnewlen(ptr noundef %0, i64 noundef %1) #0 {
  %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 i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  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) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #6
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = call signext i8 @sdsReqType(i64 noundef %16)
  store i8 %17, ptr %8, align 1, !tbaa !11
  %18 = load i8, ptr %8, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %25

21:                                               ; preds = %2
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i8 1, ptr %8, align 1, !tbaa !11
  br label %25

25:                                               ; preds = %24, %21, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %26 = load i8, ptr %8, align 1, !tbaa !11
  %27 = call i32 @sdsHdrSize(i8 noundef signext %26)
  store i32 %27, ptr %9, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %28 = load i32, ptr %9, align 4, !tbaa !12
  %29 = sext i32 %28 to i64
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = add i64 %29, %30
  %32 = add i64 %31, 1
  %33 = call noalias ptr @malloc(i64 noundef %32) #7
  store ptr %33, ptr %6, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %43, label %36

36:                                               ; preds = %25
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !12
  %39 = sext i32 %38 to i64
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = add i64 %39, %40
  %42 = add i64 %41, 1
  call void @llvm.memset.p0.i64(ptr align 1 %37, i8 0, i64 %42, i1 false)
  br label %43

43:                                               ; preds = %36, %25
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %129

47:                                               ; preds = %43
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !12
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %48, i64 %50
  store ptr %51, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 -1
  store ptr %53, ptr %10, align 8, !tbaa !5
  %54 = load i8, ptr %8, align 1, !tbaa !11
  %55 = sext i8 %54 to i32
  switch i32 %55, label %114 [
    i32 0, label %56
    i32 1, label %64
    i32 2, label %77
    i32 3, label %90
    i32 4, label %103
  ]

56:                                               ; preds = %47
  %57 = load i8, ptr %8, align 1, !tbaa !11
  %58 = sext i8 %57 to i64
  %59 = load i64, ptr %5, align 8, !tbaa !9
  %60 = shl i64 %59, 3
  %61 = or i64 %58, %60
  %62 = trunc i64 %61 to i8
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 %62, ptr %63, align 1, !tbaa !11
  br label %114

64:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i64 -3
  store ptr %66, ptr %12, align 8, !tbaa !5
  %67 = load i64, ptr %5, align 8, !tbaa !9
  %68 = trunc i64 %67 to i8
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.sdshdr8, ptr %69, i32 0, i32 0
  store i8 %68, ptr %70, align 1, !tbaa !11
  %71 = load i64, ptr %5, align 8, !tbaa !9
  %72 = trunc i64 %71 to i8
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.sdshdr8, ptr %73, i32 0, i32 1
  store i8 %72, ptr %74, align 1, !tbaa !11
  %75 = load i8, ptr %8, align 1, !tbaa !11
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 %75, ptr %76, align 1, !tbaa !11
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %114

77:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i64 -5
  store ptr %79, ptr %13, align 8, !tbaa !5
  %80 = load i64, ptr %5, align 8, !tbaa !9
  %81 = trunc i64 %80 to i16
  %82 = load ptr, ptr %13, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.sdshdr16, ptr %82, i32 0, i32 0
  store i16 %81, ptr %83, align 1, !tbaa !14
  %84 = load i64, ptr %5, align 8, !tbaa !9
  %85 = trunc i64 %84 to i16
  %86 = load ptr, ptr %13, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.sdshdr16, ptr %86, i32 0, i32 1
  store i16 %85, ptr %87, align 1, !tbaa !14
  %88 = load i8, ptr %8, align 1, !tbaa !11
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 %88, ptr %89, align 1, !tbaa !11
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  br label %114

90:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = getelementptr inbounds i8, ptr %91, i64 -9
  store ptr %92, ptr %14, align 8, !tbaa !5
  %93 = load i64, ptr %5, align 8, !tbaa !9
  %94 = trunc i64 %93 to i32
  %95 = load ptr, ptr %14, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.sdshdr32, ptr %95, i32 0, i32 0
  store i32 %94, ptr %96, align 1, !tbaa !12
  %97 = load i64, ptr %5, align 8, !tbaa !9
  %98 = trunc i64 %97 to i32
  %99 = load ptr, ptr %14, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.sdshdr32, ptr %99, i32 0, i32 1
  store i32 %98, ptr %100, align 1, !tbaa !12
  %101 = load i8, ptr %8, align 1, !tbaa !11
  %102 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 %101, ptr %102, align 1, !tbaa !11
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  br label %114

103:                                              ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = getelementptr inbounds i8, ptr %104, i64 -17
  store ptr %105, ptr %15, align 8, !tbaa !5
  %106 = load i64, ptr %5, align 8, !tbaa !9
  %107 = load ptr, ptr %15, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.sdshdr64, ptr %107, i32 0, i32 0
  store i64 %106, ptr %108, align 1, !tbaa !9
  %109 = load i64, ptr %5, align 8, !tbaa !9
  %110 = load ptr, ptr %15, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.sdshdr64, ptr %110, i32 0, i32 1
  store i64 %109, ptr %111, align 1, !tbaa !9
  %112 = load i8, ptr %8, align 1, !tbaa !11
  %113 = load ptr, ptr %10, align 8, !tbaa !5
  store i8 %112, ptr %113, align 1, !tbaa !11
  store i32 2, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  br label %114

114:                                              ; preds = %103, %90, %77, %64, %56, %47
  %115 = load i64, ptr %5, align 8, !tbaa !9
  %116 = icmp ne i64 %115, 0
  br i1 %116, label %117, label %124

117:                                              ; preds = %114
  %118 = load ptr, ptr %4, align 8, !tbaa !5
  %119 = icmp ne ptr %118, null
  br i1 %119, label %120, label %124

120:                                              ; preds = %117
  %121 = load ptr, ptr %7, align 8, !tbaa !5
  %122 = load ptr, ptr %4, align 8, !tbaa !5
  %123 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %121, ptr align 1 %122, i64 %123, i1 false)
  br label %124

124:                                              ; preds = %120, %117, %114
  %125 = load ptr, ptr %7, align 8, !tbaa !5
  %126 = load i64, ptr %5, align 8, !tbaa !9
  %127 = getelementptr inbounds i8, ptr %125, i64 %126
  store i8 0, ptr %127, align 1, !tbaa !11
  %128 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %128, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %129

129:                                              ; preds = %124, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %130 = load ptr, ptr %3, align 8
  ret ptr %130
}

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

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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

; 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) #5

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 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 = !{!"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}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !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: nounwind uwtable
define dso_local noalias ptr @sdsnewlen(ptr noundef readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call signext i8 @sdsReqType(i64 noundef %1)
  %4 = icmp eq i8 %3, 0
  %5 = icmp eq i64 %1, 0
  %or.cond = and i1 %5, %4
  %spec.store.select = select i1 %or.cond, i8 1, i8 %3
  %6 = tail call i32 @sdsHdrSize(i8 noundef signext %spec.store.select)
  %7 = sext i32 %6 to i64
  %8 = add i64 %1, 1
  %9 = add i64 %8, %7
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #5
  %11 = icmp ne ptr %0, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %2
  tail call void @llvm.memset.p0.i64(ptr align 1 %10, i8 0, i64 %9, i1 false)
  br label %13

13:                                               ; preds = %12, %2
  %14 = icmp eq ptr %10, null
  br i1 %14, label %40, label %15

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %10, i64 %7
  %17 = getelementptr inbounds i8, ptr %16, i64 -1
  switch i8 %spec.store.select, label %35 [
    i8 0, label %18
    i8 1, label %20
    i8 2, label %24
    i8 3, label %28
    i8 4, label %32
  ]

18:                                               ; preds = %15
  %.tr = trunc i64 %1 to i8
  %19 = shl i8 %.tr, 3
  br label %.sink.split

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %16, i64 -3
  %22 = trunc i64 %1 to i8
  store i8 %22, ptr %21, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %16, i64 -2
  store i8 %22, ptr %23, align 1, !tbaa !5
  br label %.sink.split

24:                                               ; preds = %15
  %25 = getelementptr inbounds i8, ptr %16, i64 -5
  %26 = trunc i64 %1 to i16
  store i16 %26, ptr %25, align 1, !tbaa !8
  %27 = getelementptr inbounds i8, ptr %16, i64 -3
  store i16 %26, ptr %27, align 1, !tbaa !8
  br label %.sink.split

28:                                               ; preds = %15
  %29 = getelementptr inbounds i8, ptr %16, i64 -9
  %30 = trunc i64 %1 to i32
  store i32 %30, ptr %29, align 1, !tbaa !10
  %31 = getelementptr inbounds i8, ptr %16, i64 -5
  store i32 %30, ptr %31, align 1, !tbaa !10
  br label %.sink.split

32:                                               ; preds = %15
  %33 = getelementptr inbounds i8, ptr %16, i64 -17
  store i64 %1, ptr %33, align 1, !tbaa !12
  %34 = getelementptr inbounds i8, ptr %16, i64 -9
  store i64 %1, ptr %34, align 1, !tbaa !12
  br label %.sink.split

.sink.split:                                      ; preds = %18, %20, %24, %28, %32
  %.sink = phi i8 [ 4, %32 ], [ 3, %28 ], [ 2, %24 ], [ 1, %20 ], [ %19, %18 ]
  store i8 %.sink, ptr %17, align 1, !tbaa !5
  br label %35

35:                                               ; preds = %.sink.split, %15
  %36 = icmp ne i64 %1, 0
  %or.cond3 = and i1 %11, %36
  br i1 %or.cond3, label %37, label %38

37:                                               ; preds = %35
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %16, ptr nonnull align 1 %0, i64 %1, i1 false)
  br label %38

38:                                               ; preds = %37, %35
  %39 = getelementptr inbounds i8, ptr %16, i64 %1
  store i8 0, ptr %39, align 1, !tbaa !5
  br label %40

40:                                               ; preds = %13, %38
  %.0 = phi ptr [ %16, %38 ], [ null, %13 ]
  ret ptr %.0
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @sdsHdrSize(i8 noundef signext) 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 nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; 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) #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 = { 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 = { 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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !6, i64 0}


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