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

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

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

12:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %57

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call i64 @strlen(ptr noundef %14) #6
  %16 = mul i64 2, %15
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %7, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 16
  br i1 %18, label %19, label %20

19:                                               ; preds = %13
  store i32 16, ptr %7, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %19, %13
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = add nsw i32 %21, 2
  %23 = call ptr @bfromcstralloc(i32 noundef %22, ptr noundef @.str.1)
  store ptr %23, ptr %6, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %51, %20
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = add nsw i32 %27, 2
  %29 = call i32 @balloc(ptr noundef %26, i32 noundef %28)
  %30 = icmp ne i32 0, %29
  br i1 %30, label %31, label %34

31:                                               ; preds = %25
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call i32 @bdestroy(ptr noundef %32)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %57

34:                                               ; preds = %25
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.tagbstring, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call i64 @strftime(ptr noundef %37, i64 noundef %40, ptr noundef %41, ptr noundef %42) #5
  store i64 %43, ptr %8, align 8, !tbaa !13
  %44 = load i64, ptr %8, align 8, !tbaa !13
  %45 = icmp ugt i64 %44, 0
  br i1 %45, label %46, label %51

46:                                               ; preds = %34
  %47 = load i64, ptr %8, align 8, !tbaa !13
  %48 = trunc i64 %47 to i32
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.tagbstring, ptr %49, i32 0, i32 1
  store i32 %48, ptr %50, align 4, !tbaa !15
  br label %55

51:                                               ; preds = %34
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = add nsw i32 %53, %52
  store i32 %54, ptr %7, align 4, !tbaa !9
  br label %24

55:                                               ; preds = %46
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %56, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %57

57:                                               ; preds = %55, %31, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %58 = load ptr, ptr %3, align 8
  ret ptr %58
}

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

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

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 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 #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, !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 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !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 i32 @bdestroy(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @bStrfTime(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %24, label %4

4:                                                ; preds = %2
  %5 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #5
  %.tr = trunc i64 %5 to i32
  %6 = shl i32 %.tr, 1
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %6, i32 16)
  %7 = add nuw nsw i32 %spec.store.select, 2
  %8 = tail call ptr @bfromcstralloc(i32 noundef %7, ptr noundef nonnull @.str.1) #6
  %9 = tail call i32 @balloc(ptr noundef %8, i32 noundef %7) #6
  %.not20 = icmp eq i32 %9, 0
  br i1 %.not20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %10 = getelementptr inbounds i8, ptr %8, i64 8
  br label %16

11:                                               ; preds = %16
  %12 = shl nsw i32 %.01621, 1
  %13 = or disjoint i32 %12, 2
  %14 = tail call i32 @balloc(ptr noundef nonnull %8, i32 noundef %13) #6
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %16, label %._crit_edge

._crit_edge:                                      ; preds = %11, %4
  %15 = tail call i32 @bdestroy(ptr noundef %8) #6
  br label %24

16:                                               ; preds = %.lr.ph, %11
  %.01621 = phi i32 [ %spec.store.select, %.lr.ph ], [ %12, %11 ]
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = or disjoint i32 %.01621, 1
  %19 = sext i32 %18 to i64
  %20 = tail call i64 @strftime(ptr noundef %17, i64 noundef %19, ptr noundef nonnull %0, ptr noundef %1) #6
  %.not19 = icmp eq i64 %20, 0
  br i1 %.not19, label %11, label %21

21:                                               ; preds = %16
  %22 = trunc i64 %20 to i32
  %23 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 %22, ptr %23, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %2, %21, %._crit_edge
  %.0 = phi ptr [ null, %._crit_edge ], [ %8, %21 ], [ null, %2 ]
  ret ptr %.0
}

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

; Function Attrs: nounwind
declare i64 @strftime(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

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


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