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

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

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

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

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.tagbstring, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !14
  %25 = icmp sle i32 %24, 0
  br i1 %25, label %37, label %26

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.tagbstring, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !14
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.tagbstring, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !13
  %33 = icmp slt i32 %29, %32
  br i1 %33, label %37, label %34

34:                                               ; preds = %26
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = icmp sle i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %34, %26, %21, %16, %11, %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %130

38:                                               ; preds = %34
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tagbstring, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !14
  %43 = icmp sge i32 %39, %42
  br i1 %43, label %44, label %129

44:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = call i32 @snapUpSize(i32 noundef %45)
  store i32 %46, ptr %6, align 4, !tbaa !9
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.tagbstring, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !14
  %50 = icmp sle i32 %46, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %44
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %126

52:                                               ; preds = %44
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.tagbstring, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !14
  %56 = mul nsw i32 7, %55
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.tagbstring, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !13
  %60 = mul nsw i32 8, %59
  %61 = icmp slt i32 %56, %60
  br i1 %61, label %62, label %85

62:                                               ; preds = %52
  br label %63

63:                                               ; preds = %91, %62
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.tagbstring, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !11
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = call ptr @realloc(ptr noundef %66, i64 noundef %68) #7
  store ptr %69, ptr %8, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = icmp eq ptr %70, null
  br i1 %71, label %72, label %84

72:                                               ; preds = %63
  %73 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %73, ptr %6, align 4, !tbaa !9
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.tagbstring, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !11
  %77 = load i32, ptr %6, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = call ptr @realloc(ptr noundef %76, i64 noundef %78) #7
  store ptr %79, ptr %8, align 8, !tbaa !5
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = icmp ne ptr %80, null
  br i1 %81, label %83, label %82

82:                                               ; preds = %72
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %126

83:                                               ; preds = %72
  br label %84

84:                                               ; preds = %83, %63
  br label %111

85:                                               ; preds = %52
  %86 = load i32, ptr %6, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = call noalias ptr @malloc(i64 noundef %87) #8
  store ptr %88, ptr %8, align 8, !tbaa !5
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = icmp ne ptr %89, null
  br i1 %90, label %92, label %91

91:                                               ; preds = %85
  br label %63

92:                                               ; preds = %85
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.tagbstring, ptr %93, i32 0, i32 1
  %95 = load i32, ptr %94, align 4, !tbaa !13
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %106

97:                                               ; preds = %92
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.tagbstring, ptr %99, i32 0, i32 2
  %101 = load ptr, ptr %100, align 8, !tbaa !11
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.tagbstring, ptr %102, i32 0, i32 1
  %104 = load i32, ptr %103, align 4, !tbaa !13
  %105 = sext i32 %104 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %98, ptr align 1 %101, i64 %105, i1 false)
  br label %106

106:                                              ; preds = %97, %92
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.tagbstring, ptr %107, i32 0, i32 2
  %109 = load ptr, ptr %108, align 8, !tbaa !11
  call void @free(ptr noundef %109) #6
  br label %110

110:                                              ; preds = %106
  br label %111

111:                                              ; preds = %110, %84
  %112 = load ptr, ptr %8, align 8, !tbaa !5
  %113 = load ptr, ptr %4, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.tagbstring, ptr %113, i32 0, i32 2
  store ptr %112, ptr %114, align 8, !tbaa !11
  %115 = load i32, ptr %6, align 4, !tbaa !9
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.tagbstring, ptr %116, i32 0, i32 0
  store i32 %115, ptr %117, align 8, !tbaa !14
  %118 = load ptr, ptr %4, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.tagbstring, ptr %118, i32 0, i32 2
  %120 = load ptr, ptr %119, align 8, !tbaa !11
  %121 = load ptr, ptr %4, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.tagbstring, ptr %121, i32 0, i32 1
  %123 = load i32, ptr %122, align 4, !tbaa !13
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds i8, ptr %120, i64 %124
  store i8 0, ptr %125, align 1, !tbaa !15
  store i32 0, ptr %7, align 4
  br label %126

126:                                              ; preds = %111, %82, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %127 = load i32, ptr %7, align 4
  switch i32 %127, label %130 [
    i32 0, label %128
  ]

128:                                              ; preds = %126
  br label %129

129:                                              ; preds = %128, %38
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %130

130:                                              ; preds = %129, %126, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %131 = load i32, ptr %3, align 4
  ret i32 %131
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @snapUpSize(i32 noundef) #0

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

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

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

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

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

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 = { 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 #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: readwrite) }
attributes #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(1) }
attributes #8 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"tagbstring", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 0}
!15 = !{!7, !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 noundef i32 @balloc(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %.thread, label %4

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

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

12:                                               ; preds = %8
  %13 = load i32, ptr %0, align 8, !tbaa !12
  %14 = icmp slt i32 %13, 1
  br i1 %14, label %.thread, label %15

15:                                               ; preds = %12
  %16 = icmp ult i32 %13, %10
  %17 = icmp slt i32 %1, 1
  %or.cond = or i1 %17, %16
  br i1 %or.cond, label %.thread, label %18

18:                                               ; preds = %15
  %.not = icmp ugt i32 %13, %1
  br i1 %.not, label %.thread, label %19

19:                                               ; preds = %18
  %20 = tail call i32 @snapUpSize(i32 noundef %1)
  %21 = load i32, ptr %0, align 8, !tbaa !12
  %.not48 = icmp sgt i32 %20, %21
  br i1 %.not48, label %22, label %.thread

22:                                               ; preds = %19
  %23 = mul nsw i32 %21, 7
  %24 = load i32, ptr %9, align 4, !tbaa !11
  %25 = shl nsw i32 %24, 3
  %26 = icmp slt i32 %23, %25
  %.pre54 = sext i32 %20 to i64
  br i1 %26, label %._crit_edge, label %34

._crit_edge:                                      ; preds = %22, %34
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = tail call ptr @realloc(ptr noundef %27, i64 noundef %.pre54) #5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %40

30:                                               ; preds = %._crit_edge
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = zext nneg i32 %1 to i64
  %33 = tail call ptr @realloc(ptr noundef %31, i64 noundef %32) #5
  %.not51 = icmp eq ptr %33, null
  br i1 %.not51, label %.thread, label %40

34:                                               ; preds = %22
  %35 = tail call noalias ptr @malloc(i64 noundef %.pre54) #6
  %.not49 = icmp eq ptr %35, null
  br i1 %.not49, label %._crit_edge, label %36

36:                                               ; preds = %34
  %.not50 = icmp eq i32 %24, 0
  %.pre = load ptr, ptr %5, align 8, !tbaa !5
  br i1 %.not50, label %39, label %37

37:                                               ; preds = %36
  %38 = sext i32 %24 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %35, ptr align 1 %.pre, i64 %38, i1 false)
  br label %39

39:                                               ; preds = %37, %36
  tail call void @free(ptr noundef %.pre) #7
  br label %40

40:                                               ; preds = %39, %30, %._crit_edge
  %.036 = phi i32 [ %1, %30 ], [ %20, %._crit_edge ], [ %20, %39 ]
  %.0 = phi ptr [ %33, %30 ], [ %28, %._crit_edge ], [ %35, %39 ]
  store ptr %.0, ptr %5, align 8, !tbaa !5
  store i32 %.036, ptr %0, align 8, !tbaa !12
  %41 = load i32, ptr %9, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %.0, i64 %42
  store i8 0, ptr %43, align 1, !tbaa !13
  br label %.thread

.thread:                                          ; preds = %30, %19, %18, %40, %2, %4, %8, %12, %15
  %.1 = phi i32 [ -1, %15 ], [ -1, %12 ], [ -1, %8 ], [ -1, %4 ], [ -1, %2 ], [ 0, %40 ], [ 0, %18 ], [ -1, %30 ], [ 0, %19 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @snapUpSize(i32 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 #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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { 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 #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: readwrite) }
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 allocsize(1) }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { 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, !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 = !{!6, !7, i64 0}
!13 = !{!8, !8, i64 0}


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