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

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

@.str.1 = external hidden unnamed_addr constant [1 x i8], align 1

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

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

declare i32 @balloc(ptr noundef, i32 noundef) #1

declare ptr @bfromcstr(ptr noundef) #1

declare i32 @bdestroy(ptr noundef) #1

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

11:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %95

12:                                               ; preds = %1
  store i32 0, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %46, %12
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = sext i8 %18 to i32
  %20 = icmp ne i32 %19, 58
  br i1 %20, label %21, label %49

21:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %22, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = sext i8 %26 to i32
  %28 = sub nsw i32 %27, 48
  store i32 %28, ptr %8, align 4, !tbaa !9
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = icmp ugt i32 %29, 9
  br i1 %30, label %37, label %31

31:                                               ; preds = %21
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = sub nsw i32 2147483647, %33
  %35 = sdiv i32 %34, 10
  %36 = icmp sgt i32 %32, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %31, %21
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %43

38:                                               ; preds = %31
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = mul nsw i32 %39, 10
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = add i32 %40, %41
  store i32 %42, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  br label %43

43:                                               ; preds = %38, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %44 = load i32, ptr %7, align 4
  switch i32 %44, label %95 [
    i32 0, label %45
  ]

45:                                               ; preds = %43
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %4, align 4, !tbaa !9
  br label %13, !llvm.loop !12

49:                                               ; preds = %13
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = add nsw i32 %52, %53
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %50, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !11
  %58 = sext i8 %57 to i32
  %59 = icmp ne i32 %58, 44
  br i1 %59, label %60, label %61

60:                                               ; preds = %49
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %95

61:                                               ; preds = %49
  %62 = call ptr @bfromcstr(ptr noundef @.str.1)
  store ptr %62, ptr %6, align 8, !tbaa !5
  %63 = icmp eq ptr null, %62
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %95

65:                                               ; preds = %61
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  %69 = call i32 @balloc(ptr noundef %66, i32 noundef %68)
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %74

71:                                               ; preds = %65
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = call i32 @bdestroy(ptr noundef %72)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %95

74:                                               ; preds = %65
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.tagbstring, ptr %75, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !14
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = load i32, ptr %4, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i8, ptr %78, i64 %80
  %82 = getelementptr inbounds i8, ptr %81, i64 1
  %83 = load i32, ptr %5, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %77, ptr align 1 %82, i64 %84, i1 false)
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.tagbstring, ptr %85, i32 0, i32 2
  %87 = load ptr, ptr %86, align 8, !tbaa !14
  %88 = load i32, ptr %5, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds i8, ptr %87, i64 %89
  store i8 0, ptr %90, align 1, !tbaa !11
  %91 = load i32, ptr %5, align 4, !tbaa !9
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.tagbstring, ptr %92, i32 0, i32 1
  store i32 %91, ptr %93, align 4, !tbaa !16
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %94, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %95

95:                                               ; preds = %74, %71, %64, %60, %43, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %96 = load ptr, ptr %2, align 8
  ret ptr %96
}

; 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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #2 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !6, i64 8}
!15 = !{!"tagbstring", !10, i64 0, !10, i64 4, !6, i64 8}
!16 = !{!15, !10, i64 4}


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

@.str.1 = external hidden unnamed_addr constant [1 x i8], align 1

declare i32 @balloc(ptr noundef, i32 noundef) local_unnamed_addr #0

declare ptr @bfromcstr(ptr noundef) local_unnamed_addr #0

declare i32 @bdestroy(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @bNetStr2Bstr(ptr noundef readonly %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.thread, label %.preheader

.preheader:                                       ; preds = %1
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %.not43 = icmp eq i8 %3, 58
  br i1 %.not43, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %12
  %indvars.iv = phi i64 [ %indvars.iv.next, %12 ], [ 0, %.preheader ]
  %4 = phi i8 [ %16, %12 ], [ %3, %.preheader ]
  %.02944 = phi i32 [ %14, %12 ], [ 0, %.preheader ]
  %5 = sext i8 %4 to i32
  %6 = add nsw i32 %5, -48
  %7 = icmp ugt i32 %6, 9
  br i1 %7, label %.thread, label %8

8:                                                ; preds = %.lr.ph
  %9 = sub nuw i32 -2147483601, %5
  %10 = udiv i32 %9, 10
  %11 = icmp sgt i32 %.02944, %10
  br i1 %11, label %.thread, label %12

12:                                               ; preds = %8
  %13 = mul nsw i32 %.02944, 10
  %14 = add i32 %6, %13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %.not = icmp eq i8 %16, 58
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !8

._crit_edge.loopexit:                             ; preds = %12
  %17 = trunc nuw i64 %indvars.iv.next to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.lcssa42 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %._crit_edge.loopexit ]
  %.029.lcssa = phi i32 [ 0, %.preheader ], [ %14, %._crit_edge.loopexit ]
  %.028.lcssa = phi i32 [ 0, %.preheader ], [ %17, %._crit_edge.loopexit ]
  %18 = getelementptr inbounds i8, ptr %0, i64 %.lcssa42
  %19 = add i32 %.029.lcssa, 1
  %20 = add i32 %19, %.028.lcssa
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %.not35 = icmp eq i8 %23, 44
  br i1 %.not35, label %24, label %.thread

24:                                               ; preds = %._crit_edge
  %25 = tail call ptr @bfromcstr(ptr noundef nonnull @.str.1) #3
  %26 = icmp eq ptr %25, null
  br i1 %26, label %.thread, label %27

27:                                               ; preds = %24
  %28 = tail call i32 @balloc(ptr noundef nonnull %25, i32 noundef %19) #3
  %.not36 = icmp eq i32 %28, 0
  br i1 %.not36, label %31, label %29

29:                                               ; preds = %27
  %30 = tail call i32 @bdestroy(ptr noundef nonnull %25) #3
  br label %.thread

31:                                               ; preds = %27
  %32 = getelementptr inbounds i8, ptr %25, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !10
  %34 = getelementptr inbounds i8, ptr %18, i64 1
  %35 = sext i32 %.029.lcssa to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %33, ptr nonnull align 1 %34, i64 %35, i1 false)
  %36 = load ptr, ptr %32, align 8, !tbaa !10
  %37 = getelementptr inbounds i8, ptr %36, i64 %35
  store i8 0, ptr %37, align 1, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %25, i64 4
  store i32 %.029.lcssa, ptr %38, align 4, !tbaa !14
  br label %.thread

.thread:                                          ; preds = %.lr.ph, %8, %24, %._crit_edge, %1, %31, %29
  %.2 = phi ptr [ null, %29 ], [ %25, %31 ], [ null, %1 ], [ null, %._crit_edge ], [ null, %24 ], [ null, %8 ], [ null, %.lr.ph ]
  ret ptr %.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) #2

attributes #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 = { 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !13, i64 8}
!11 = !{!"tagbstring", !12, i64 0, !12, i64 4, !13, i64 8}
!12 = !{!"int", !6, i64 0}
!13 = !{!"any pointer", !6, i64 0}
!14 = !{!11, !12, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass