; LLVM IR from OpenFAST/openfast :: modules/map/src/bstring (bstrlib)

; 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.genBstrList = type { ptr, ptr }
%struct.tagbstring = type { i32, i32, ptr }
%struct.bstrList = type { i32, i32, ptr }

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

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

; Function Attrs: nounwind
declare void @free(ptr 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: nounwind uwtable
declare dso_local i32 @bstrListDestroy(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @bsplitcb(ptr noundef, i8 noundef zeroext, i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @bsplit(ptr noundef %0, i8 noundef zeroext %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca %struct.genBstrList, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %20

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.tagbstring, ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !10
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %20

15:                                               ; preds = %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.tagbstring, ptr %16, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %15, %10, %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %67

21:                                               ; preds = %15
  %22 = call noalias ptr @malloc(i64 noundef 16) #5
  %23 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  store ptr %22, ptr %23, align 8, !tbaa !14
  %24 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = icmp ne ptr %25, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %67

28:                                               ; preds = %21
  %29 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = getelementptr inbounds %struct.bstrList, ptr %30, i32 0, i32 1
  store i32 4, ptr %31, align 4, !tbaa !16
  %32 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = getelementptr inbounds %struct.bstrList, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !16
  %36 = sext i32 %35 to i64
  %37 = mul i64 %36, 8
  %38 = call noalias ptr @malloc(i64 noundef %37) #5
  %39 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = getelementptr inbounds %struct.bstrList, ptr %40, i32 0, i32 2
  store ptr %38, ptr %41, align 8, !tbaa !18
  %42 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = getelementptr inbounds %struct.bstrList, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !18
  %46 = icmp ne ptr %45, null
  br i1 %46, label %50, label %47

47:                                               ; preds = %28
  %48 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  call void @free(ptr noundef %49) #4
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %67

50:                                               ; preds = %28
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 0
  store ptr %51, ptr %52, align 8, !tbaa !19
  %53 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = getelementptr inbounds %struct.bstrList, ptr %54, i32 0, i32 0
  store i32 0, ptr %55, align 8, !tbaa !20
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i8, ptr %5, align 1, !tbaa !9
  %58 = call i32 @bsplitcb(ptr noundef %56, i8 noundef zeroext %57, i32 noundef 0, ptr noundef @bscb, ptr noundef %6)
  %59 = icmp slt i32 %58, 0
  br i1 %59, label %60, label %64

60:                                               ; preds = %50
  %61 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = call i32 @bstrListDestroy(ptr noundef %62)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %67

64:                                               ; preds = %50
  %65 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  store ptr %66, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %67

67:                                               ; preds = %64, %60, %47, %27, %20
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  %68 = load ptr, ptr %3, align 8
  ret ptr %68
}

; Function Attrs: nounwind uwtable
declare hidden i32 @bscb(ptr noundef, i32 noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { nounwind }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 8}
!11 = !{!"tagbstring", !12, i64 0, !12, i64 4, !6, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !12, i64 4}
!14 = !{!15, !6, i64 8}
!15 = !{!"genBstrList", !6, i64 0, !6, i64 8}
!16 = !{!17, !12, i64 4}
!17 = !{!"bstrList", !12, i64 0, !12, i64 4, !6, i64 8}
!18 = !{!17, !6, i64 8}
!19 = !{!15, !6, i64 0}
!20 = !{!17, !12, 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"

%struct.genBstrList = type { ptr, ptr }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @bstrListDestroy(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @bsplitcb(ptr noundef, i8 noundef zeroext, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @bsplit(ptr noundef %0, i8 noundef zeroext %1) local_unnamed_addr #3 {
  %3 = alloca %struct.genBstrList, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %25, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not8 = icmp eq ptr %6, null
  br i1 %.not8, label %25, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %25, label %11

11:                                               ; preds = %7
  %12 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  %13 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %12, ptr %13, align 8, !tbaa !12
  %.not9 = icmp eq ptr %12, null
  br i1 %.not9, label %25, label %14

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %12, i64 4
  store i32 4, ptr %15, align 4, !tbaa !14
  %16 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #5
  %17 = getelementptr inbounds i8, ptr %12, i64 8
  store ptr %16, ptr %17, align 8, !tbaa !16
  %.not10 = icmp eq ptr %16, null
  br i1 %.not10, label %18, label %19

18:                                               ; preds = %14
  tail call void @free(ptr noundef nonnull %12) #4
  br label %25

19:                                               ; preds = %14
  store ptr %0, ptr %3, align 8, !tbaa !17
  store i32 0, ptr %12, align 8, !tbaa !18
  %20 = call i32 @bsplitcb(ptr noundef nonnull %0, i8 noundef zeroext %1, i32 noundef 0, ptr noundef nonnull @bscb, ptr noundef nonnull %3)
  %21 = icmp slt i32 %20, 0
  %22 = load ptr, ptr %13, align 8, !tbaa !12
  br i1 %21, label %23, label %25

23:                                               ; preds = %19
  %24 = call i32 @bstrListDestroy(ptr noundef %22)
  br label %25

25:                                               ; preds = %19, %11, %2, %4, %7, %23, %18
  %.0 = phi ptr [ null, %23 ], [ null, %18 ], [ null, %7 ], [ null, %4 ], [ null, %2 ], [ null, %11 ], [ %22, %19 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @bscb(ptr noundef, i32 noundef, i32 noundef) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = { nounwind }
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, !10, i64 8}
!6 = !{!"tagbstring", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!13, !10, i64 8}
!13 = !{!"genBstrList", !10, i64 0, !10, i64 8}
!14 = !{!15, !7, i64 4}
!15 = !{!"bstrList", !7, i64 0, !7, i64 4, !10, i64 8}
!16 = !{!15, !10, i64 8}
!17 = !{!13, !10, i64 0}
!18 = !{!15, !7, i64 0}


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