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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @balloc(ptr noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @bfromcstralloc(i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @bdestroy(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @bassign(ptr noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #3

; Function Attrs: nounwind
declare i32 @vsnprintf(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @bassignformat(ptr noundef %0, ptr noundef %1, ...) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [1 x %struct.__va_list_tag], align 16
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = 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 24, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %39

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %39

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

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 !12
  %25 = icmp sle i32 %24, 0
  br i1 %25, label %39, label %26

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

31:                                               ; preds = %26
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tagbstring, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !13
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.tagbstring, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !12
  %38 = icmp sgt i32 %34, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %31, %26, %21, %16, %13, %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %122

40:                                               ; preds = %31
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call i64 @strlen(ptr noundef %41) #6
  %43 = mul i64 2, %42
  %44 = trunc i64 %43 to i32
  store i32 %44, ptr %8, align 4, !tbaa !14
  %45 = load i32, ptr %8, align 4, !tbaa !14
  %46 = icmp slt i32 %45, 16
  br i1 %46, label %47, label %48

47:                                               ; preds = %40
  store i32 16, ptr %8, align 4, !tbaa !14
  br label %48

48:                                               ; preds = %47, %40
  %49 = load i32, ptr %8, align 4, !tbaa !14
  %50 = add nsw i32 %49, 2
  %51 = call ptr @bfromcstralloc(i32 noundef %50, ptr noundef @.str)
  store ptr %51, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %62, label %54

54:                                               ; preds = %48
  store i32 1, ptr %8, align 4, !tbaa !14
  %55 = load i32, ptr %8, align 4, !tbaa !14
  %56 = add nsw i32 %55, 2
  %57 = call ptr @bfromcstralloc(i32 noundef %56, ptr noundef @.str)
  store ptr %57, ptr %7, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %61, label %60

60:                                               ; preds = %54
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %122

61:                                               ; preds = %54
  br label %62

62:                                               ; preds = %61, %48
  br label %63

63:                                               ; preds = %114, %62
  br label %64

64:                                               ; preds = %63
  %65 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %6, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %65)
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.tagbstring, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !9
  %69 = load i32, ptr %8, align 4, !tbaa !14
  %70 = add nsw i32 %69, 1
  %71 = sext i32 %70 to i64
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %6, i64 0, i64 0
  %74 = call i32 @vsnprintf(ptr noundef %68, i64 noundef %71, ptr noundef %72, ptr noundef %73) #5
  store i32 %74, ptr %9, align 4, !tbaa !14
  %75 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %6, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %75)
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.tagbstring, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !9
  %79 = load i32, ptr %8, align 4, !tbaa !14
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i8, ptr %78, i64 %80
  store i8 0, ptr %81, align 1, !tbaa !15
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.tagbstring, ptr %82, i32 0, i32 2
  %84 = load ptr, ptr %83, align 8, !tbaa !9
  %85 = call i64 @strlen(ptr noundef %84) #6
  %86 = trunc i64 %85 to i32
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.tagbstring, ptr %87, i32 0, i32 1
  store i32 %86, ptr %88, align 4, !tbaa !13
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.tagbstring, ptr %89, i32 0, i32 1
  %91 = load i32, ptr %90, align 4, !tbaa !13
  %92 = load i32, ptr %8, align 4, !tbaa !14
  %93 = icmp slt i32 %91, %92
  br i1 %93, label %94, label %95

94:                                               ; preds = %64
  br label %115

95:                                               ; preds = %64
  %96 = load i32, ptr %9, align 4, !tbaa !14
  %97 = load i32, ptr %8, align 4, !tbaa !14
  %98 = icmp sgt i32 %96, %97
  br i1 %98, label %99, label %101

99:                                               ; preds = %95
  %100 = load i32, ptr %9, align 4, !tbaa !14
  store i32 %100, ptr %8, align 4, !tbaa !14
  br label %105

101:                                              ; preds = %95
  %102 = load i32, ptr %8, align 4, !tbaa !14
  %103 = load i32, ptr %8, align 4, !tbaa !14
  %104 = add nsw i32 %103, %102
  store i32 %104, ptr %8, align 4, !tbaa !14
  br label %105

105:                                              ; preds = %101, %99
  %106 = load ptr, ptr %7, align 8, !tbaa !5
  %107 = load i32, ptr %8, align 4, !tbaa !14
  %108 = add nsw i32 %107, 2
  %109 = call i32 @balloc(ptr noundef %106, i32 noundef %108)
  %110 = icmp ne i32 0, %109
  br i1 %110, label %111, label %114

111:                                              ; preds = %105
  %112 = load ptr, ptr %7, align 8, !tbaa !5
  %113 = call i32 @bdestroy(ptr noundef %112)
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %122

114:                                              ; preds = %105
  br label %63

115:                                              ; preds = %94
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  %117 = load ptr, ptr %7, align 8, !tbaa !5
  %118 = call i32 @bassign(ptr noundef %116, ptr noundef %117)
  store i32 %118, ptr %9, align 4, !tbaa !14
  %119 = load ptr, ptr %7, align 8, !tbaa !5
  %120 = call i32 @bdestroy(ptr noundef %119)
  %121 = load i32, ptr %9, align 4, !tbaa !14
  store i32 %121, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %122

122:                                              ; preds = %115, %111, %60, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #5
  %123 = load i32, ptr %3, align 4
  ret i32 %123
}

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 willreturn memory(read) "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 nosync nounwind willreturn }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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, !6, i64 8}
!10 = !{!"tagbstring", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!11, !11, 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"

%struct.__va_list_tag = type { i32, i32, ptr, ptr }

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @balloc(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @bfromcstralloc(i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @bassign(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #3

; Function Attrs: nofree nounwind
declare noundef i32 @vsnprintf(ptr nocapture noundef, i64 noundef, ptr nocapture noundef readonly, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @bassignformat(ptr noundef %0, ptr noundef readonly %1, ...) local_unnamed_addr #0 {
  %3 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #6
  %4 = icmp ne ptr %0, null
  %5 = icmp ne ptr %1, null
  %or.cond = and i1 %4, %5
  br i1 %or.cond, label %6, label %45

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

9:                                                ; preds = %6
  %10 = load i32, ptr %0, align 8, !tbaa !11
  %11 = icmp slt i32 %10, 1
  br i1 %11, label %45, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 4
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %or.cond47 = icmp ugt i32 %14, %10
  br i1 %or.cond47, label %45, label %15

15:                                               ; preds = %12
  %16 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #7
  %.tr = trunc i64 %16 to i32
  %17 = shl i32 %.tr, 1
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %17, i32 16)
  %18 = add nuw nsw i32 %spec.store.select, 2
  %19 = tail call ptr @bfromcstralloc(i32 noundef %18, ptr noundef nonnull @.str)
  %.not44 = icmp eq ptr %19, null
  br i1 %.not44, label %20, label %22

20:                                               ; preds = %15
  %21 = tail call ptr @bfromcstralloc(i32 noundef 3, ptr noundef nonnull @.str)
  %.not45 = icmp eq ptr %21, null
  br i1 %.not45, label %45, label %22

22:                                               ; preds = %20, %15
  %.035 = phi ptr [ %19, %15 ], [ %21, %20 ]
  %.0 = phi i32 [ %spec.store.select, %15 ], [ 1, %20 ]
  %23 = getelementptr inbounds i8, ptr %.035, i64 8
  %24 = getelementptr inbounds i8, ptr %.035, i64 4
  br label %25

25:                                               ; preds = %37, %22
  %.1 = phi i32 [ %.0, %22 ], [ %.2, %37 ]
  call void @llvm.va_start.p0(ptr nonnull %3)
  %26 = load ptr, ptr %23, align 8, !tbaa !5
  %27 = add nsw i32 %.1, 1
  %28 = sext i32 %27 to i64
  %29 = call i32 @vsnprintf(ptr noundef %26, i64 noundef %28, ptr noundef nonnull %1, ptr noundef nonnull %3) #6
  call void @llvm.va_end.p0(ptr nonnull %3)
  %30 = load ptr, ptr %23, align 8, !tbaa !5
  %31 = sext i32 %.1 to i64
  %32 = getelementptr inbounds i8, ptr %30, i64 %31
  store i8 0, ptr %32, align 1, !tbaa !13
  %33 = load ptr, ptr %23, align 8, !tbaa !5
  %34 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %33) #7
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %24, align 4, !tbaa !12
  %36 = icmp sgt i32 %.1, %35
  br i1 %36, label %42, label %37

37:                                               ; preds = %25
  %38 = icmp sgt i32 %29, %.1
  %39 = shl nsw i32 %.1, 1
  %.2 = select i1 %38, i32 %29, i32 %39
  %40 = add nsw i32 %.2, 2
  %41 = call i32 @balloc(ptr noundef nonnull %.035, i32 noundef %40)
  %.not46 = icmp eq i32 %41, 0
  br i1 %.not46, label %25, label %.sink.split

42:                                               ; preds = %25
  %43 = call i32 @bassign(ptr noundef nonnull %0, ptr noundef nonnull %.035)
  br label %.sink.split

.sink.split:                                      ; preds = %37, %42
  %.036.ph = phi i32 [ %43, %42 ], [ -1, %37 ]
  %44 = call i32 @bdestroy(ptr noundef nonnull %.035)
  br label %45

45:                                               ; preds = %.sink.split, %20, %2, %6, %9, %12
  %.036 = phi i32 [ -1, %12 ], [ -1, %9 ], [ -1, %6 ], [ -1, %2 ], [ -1, %20 ], [ %.036.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #6
  ret i32 %.036
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #5

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 nosync nounwind willreturn }
attributes #4 = { nofree 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 0}
!12 = !{!6, !7, i64 4}
!13 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass