; 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 ptr @bfromcstr(ptr noundef) #1

declare i32 @bconchar(ptr noundef, i8 noundef signext) #1

declare i32 @bdestroy(ptr noundef) #1

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

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, 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 %20, label %15

15:                                               ; preds = %10
  %16 = load ptr, ptr %3, 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 eq ptr %18, null
  br i1 %19, label %20, label %21

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

21:                                               ; preds = %15
  %22 = call ptr @bfromcstr(ptr noundef @.str.1)
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %84

25:                                               ; preds = %21
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %26

26:                                               ; preds = %79, %25
  %27 = load i32, ptr %4, align 4, !tbaa !13
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.tagbstring, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp slt i32 %27, %30
  br i1 %31, label %32, label %82

32:                                               ; preds = %26
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.tagbstring, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !12
  %36 = load i32, ptr %4, align 4, !tbaa !13
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !14
  %40 = zext i8 %39 to i32
  %41 = add nsw i32 %40, 42
  %42 = trunc i32 %41 to i8
  store i8 %42, ptr %6, align 1, !tbaa !14
  %43 = load i8, ptr %6, align 1, !tbaa !14
  %44 = zext i8 %43 to i32
  %45 = icmp eq i32 %44, 61
  br i1 %45, label %58, label %46

46:                                               ; preds = %32
  %47 = load i8, ptr %6, align 1, !tbaa !14
  %48 = zext i8 %47 to i32
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %58, label %50

50:                                               ; preds = %46
  %51 = load i8, ptr %6, align 1, !tbaa !14
  %52 = zext i8 %51 to i32
  %53 = icmp eq i32 %52, 13
  br i1 %53, label %58, label %54

54:                                               ; preds = %50
  %55 = load i8, ptr %6, align 1, !tbaa !14
  %56 = zext i8 %55 to i32
  %57 = icmp eq i32 %56, 10
  br i1 %57, label %58, label %70

58:                                               ; preds = %54, %50, %46, %32
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = call i32 @bconchar(ptr noundef %59, i8 noundef signext 61)
  %61 = icmp sgt i32 0, %60
  br i1 %61, label %62, label %65

62:                                               ; preds = %58
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = call i32 @bdestroy(ptr noundef %63)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %84

65:                                               ; preds = %58
  %66 = load i8, ptr %6, align 1, !tbaa !14
  %67 = zext i8 %66 to i32
  %68 = add nsw i32 %67, 64
  %69 = trunc i32 %68 to i8
  store i8 %69, ptr %6, align 1, !tbaa !14
  br label %70

70:                                               ; preds = %65, %54
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load i8, ptr %6, align 1, !tbaa !14
  %73 = call i32 @bconchar(ptr noundef %71, i8 noundef signext %72)
  %74 = icmp sgt i32 0, %73
  br i1 %74, label %75, label %78

75:                                               ; preds = %70
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = call i32 @bdestroy(ptr noundef %76)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %84

78:                                               ; preds = %70
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %4, align 4, !tbaa !13
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %4, align 4, !tbaa !13
  br label %26, !llvm.loop !15

82:                                               ; preds = %26
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %83, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %84

84:                                               ; preds = %82, %75, %62, %24, %20
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %85 = load ptr, ptr %2, align 8
  ret ptr %85
}

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 = { 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, !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 = !{!11, !11, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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 ptr @bfromcstr(ptr noundef) local_unnamed_addr #0

declare i32 @bconchar(ptr noundef, i8 noundef signext) local_unnamed_addr #0

declare i32 @bdestroy(ptr noundef) local_unnamed_addr #0

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

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 0
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = icmp eq ptr %9, null
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %7
  %12 = tail call ptr @bfromcstr(ptr noundef nonnull @.str.1) #2
  %13 = icmp eq ptr %12, null
  br i1 %13, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %11
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %.loopexit

16:                                               ; preds = %29
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next, %18
  br i1 %19, label %.lr.ph, label %.loopexit, !llvm.loop !12

.lr.ph:                                           ; preds = %.preheader, %16
  %indvars.iv = phi i64 [ %indvars.iv.next, %16 ], [ 0, %.preheader ]
  %20 = load ptr, ptr %8, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %20, i64 %indvars.iv
  %22 = load i8, ptr %21, align 1, !tbaa !14
  %23 = add i8 %22, 42
  switch i8 %22, label %29 [
    i8 19, label %24
    i8 -29, label %24
    i8 -32, label %24
    i8 -42, label %24
  ]

24:                                               ; preds = %.lr.ph, %.lr.ph, %.lr.ph, %.lr.ph
  %25 = tail call i32 @bconchar(ptr noundef nonnull %12, i8 noundef signext 61) #2
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %.loopexit.sink.split, label %27

27:                                               ; preds = %24
  %28 = or disjoint i8 %23, 64
  br label %29

29:                                               ; preds = %.lr.ph, %27
  %.0 = phi i8 [ %28, %27 ], [ %23, %.lr.ph ]
  %30 = tail call i32 @bconchar(ptr noundef nonnull %12, i8 noundef signext %.0) #2
  %31 = icmp slt i32 %30, 0
  br i1 %31, label %.loopexit.sink.split, label %16

.loopexit.sink.split:                             ; preds = %29, %24
  %32 = tail call i32 @bdestroy(ptr noundef nonnull %12) #2
  br label %.loopexit

.loopexit:                                        ; preds = %16, %.loopexit.sink.split, %.preheader, %11, %1, %3, %7
  %.027 = phi ptr [ null, %7 ], [ null, %3 ], [ null, %1 ], [ null, %11 ], [ %12, %.preheader ], [ null, %.loopexit.sink.split ], [ %12, %16 ]
  ret ptr %.027
}

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 = { 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, !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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!8, !8, i64 0}


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