; 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 @bsplitscb(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) #3

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

; Function Attrs: nounwind uwtable
define dso_local ptr @bsplits(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.genBstrList, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  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 %33

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

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

20:                                               ; preds = %15
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %33

23:                                               ; preds = %20
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.tagbstring, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %33, label %28

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.tagbstring, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = icmp ne ptr %31, null
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %28
  %35 = call noalias ptr @malloc(i64 noundef 16) #5
  %36 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  store ptr %35, ptr %36, align 8, !tbaa !13
  %37 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !13
  %39 = icmp ne ptr %38, null
  br i1 %39, label %41, label %40

40:                                               ; preds = %34
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %80

41:                                               ; preds = %34
  %42 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = getelementptr inbounds %struct.bstrList, ptr %43, i32 0, i32 1
  store i32 4, ptr %44, align 4, !tbaa !15
  %45 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !13
  %47 = getelementptr inbounds %struct.bstrList, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !15
  %49 = sext i32 %48 to i64
  %50 = mul i64 %49, 8
  %51 = call noalias ptr @malloc(i64 noundef %50) #5
  %52 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = getelementptr inbounds %struct.bstrList, ptr %53, i32 0, i32 2
  store ptr %51, ptr %54, align 8, !tbaa !17
  %55 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !13
  %57 = getelementptr inbounds %struct.bstrList, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !17
  %59 = icmp ne ptr %58, null
  br i1 %59, label %63, label %60

60:                                               ; preds = %41
  %61 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  call void @free(ptr noundef %62) #4
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %80

63:                                               ; preds = %41
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 0
  store ptr %64, ptr %65, align 8, !tbaa !18
  %66 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = getelementptr inbounds %struct.bstrList, ptr %67, i32 0, i32 0
  store i32 0, ptr %68, align 8, !tbaa !19
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = call i32 @bsplitscb(ptr noundef %69, ptr noundef %70, i32 noundef 0, ptr noundef @bscb, ptr noundef %6)
  %72 = icmp slt i32 %71, 0
  br i1 %72, label %73, label %77

73:                                               ; preds = %63
  %74 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %75 = load ptr, ptr %74, align 8, !tbaa !13
  %76 = call i32 @bstrListDestroy(ptr noundef %75)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %80

77:                                               ; preds = %63
  %78 = getelementptr inbounds %struct.genBstrList, ptr %6, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !13
  store ptr %79, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %80

80:                                               ; preds = %77, %73, %60, %40, %33
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  %81 = load ptr, ptr %3, align 8
  ret ptr %81
}

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 = !{!10, !11, i64 4}
!10 = !{!"tagbstring", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !6, i64 8}
!14 = !{!"genBstrList", !6, i64 0, !6, i64 8}
!15 = !{!16, !11, i64 4}
!16 = !{!"bstrList", !11, i64 0, !11, i64 4, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = !{!14, !6, i64 0}
!19 = !{!16, !11, 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 @bsplitscb(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local ptr @bsplits(ptr noundef %0, ptr noundef %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 %34, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %34, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp ne ptr %10, null
  %12 = icmp ne ptr %1, null
  %or.cond = and i1 %12, %11
  br i1 %or.cond, label %13, label %34

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %1, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 0
  br i1 %16, label %34, label %17

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %.not14 = icmp eq ptr %19, null
  br i1 %.not14, label %34, label %20

20:                                               ; preds = %17
  %21 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #5
  %22 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %21, ptr %22, align 8, !tbaa !12
  %.not15 = icmp eq ptr %21, null
  br i1 %.not15, label %34, label %23

23:                                               ; preds = %20
  %24 = getelementptr inbounds i8, ptr %21, i64 4
  store i32 4, ptr %24, align 4, !tbaa !14
  %25 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #5
  %26 = getelementptr inbounds i8, ptr %21, i64 8
  store ptr %25, ptr %26, align 8, !tbaa !16
  %.not16 = icmp eq ptr %25, null
  br i1 %.not16, label %27, label %28

27:                                               ; preds = %23
  tail call void @free(ptr noundef nonnull %21) #4
  br label %34

28:                                               ; preds = %23
  store ptr %0, ptr %3, align 8, !tbaa !17
  store i32 0, ptr %21, align 8, !tbaa !18
  %29 = call i32 @bsplitscb(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef 0, ptr noundef nonnull @bscb, ptr noundef nonnull %3)
  %30 = icmp slt i32 %29, 0
  %31 = load ptr, ptr %22, align 8, !tbaa !12
  br i1 %30, label %32, label %34

32:                                               ; preds = %28
  %33 = call i32 @bstrListDestroy(ptr noundef %31)
  br label %34

34:                                               ; preds = %28, %20, %2, %4, %8, %13, %17, %32, %27
  %.0 = phi ptr [ null, %32 ], [ null, %27 ], [ null, %17 ], [ null, %13 ], [ null, %8 ], [ null, %4 ], [ null, %2 ], [ null, %20 ], [ %31, %28 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret ptr %.0
}

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, !7, i64 4}
!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, !10, i64 8}
!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,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass