; LLVM IR from openxrlab/xrsfm :: 3rdparty/apriltag/common/string_util.ll (str_concat_private)

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

; 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
declare void @llvm.va_start.p0(ptr) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @_str_concat_private(ptr noundef %0, ...) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca [1 x %struct.__va_list_tag], align 16
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [1 x %struct.__va_list_tag], align 16
  %9 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #5
  %10 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %10)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %11, ptr %5, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %33, %1
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %36

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call i64 @strlen(ptr noundef %16) #6
  %18 = load i64, ptr %3, align 8, !tbaa !9
  %19 = add i64 %18, %17
  store i64 %19, ptr %3, align 8, !tbaa !9
  %20 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  %21 = getelementptr inbounds %struct.__va_list_tag, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 16
  %23 = icmp ule i32 %22, 40
  br i1 %23, label %24, label %29

24:                                               ; preds = %15
  %25 = getelementptr inbounds %struct.__va_list_tag, ptr %20, i32 0, i32 3
  %26 = load ptr, ptr %25, align 16
  %27 = getelementptr i8, ptr %26, i32 %22
  %28 = add i32 %22, 8
  store i32 %28, ptr %21, align 16
  br label %33

29:                                               ; preds = %15
  %30 = getelementptr inbounds %struct.__va_list_tag, ptr %20, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8
  %32 = getelementptr i8, ptr %31, i32 8
  store ptr %32, ptr %30, align 8
  br label %33

33:                                               ; preds = %29, %24
  %34 = phi ptr [ %27, %24 ], [ %31, %29 ]
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  store ptr %35, ptr %5, align 8, !tbaa !5
  br label %12, !llvm.loop !11

36:                                               ; preds = %12
  %37 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %37)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %38 = load i64, ptr %3, align 8, !tbaa !9
  %39 = mul i64 %38, 1
  %40 = add i64 %39, 1
  %41 = call noalias ptr @malloc(i64 noundef %40) #7
  store ptr %41, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %42, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #5
  %43 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %43)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %44, ptr %9, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %73, %36
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %76

48:                                               ; preds = %45
  br label %49

49:                                               ; preds = %53, %48
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = load i8, ptr %50, align 1, !tbaa !13
  %52 = icmp ne i8 %51, 0
  br i1 %52, label %53, label %59

53:                                               ; preds = %49
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %9, align 8, !tbaa !5
  %56 = load i8, ptr %54, align 1, !tbaa !13
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i32 1
  store ptr %58, ptr %7, align 8, !tbaa !5
  store i8 %56, ptr %57, align 1, !tbaa !13
  br label %49, !llvm.loop !14

59:                                               ; preds = %49
  %60 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  %61 = getelementptr inbounds %struct.__va_list_tag, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 16
  %63 = icmp ule i32 %62, 40
  br i1 %63, label %64, label %69

64:                                               ; preds = %59
  %65 = getelementptr inbounds %struct.__va_list_tag, ptr %60, i32 0, i32 3
  %66 = load ptr, ptr %65, align 16
  %67 = getelementptr i8, ptr %66, i32 %62
  %68 = add i32 %62, 8
  store i32 %68, ptr %61, align 16
  br label %73

69:                                               ; preds = %59
  %70 = getelementptr inbounds %struct.__va_list_tag, ptr %60, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8
  %72 = getelementptr i8, ptr %71, i32 8
  store ptr %72, ptr %70, align 8
  br label %73

73:                                               ; preds = %69, %64
  %74 = phi ptr [ %67, %64 ], [ %71, %69 ]
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  store ptr %75, ptr %9, align 8, !tbaa !5
  br label %45, !llvm.loop !15

76:                                               ; preds = %45
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 0, ptr %77, align 1, !tbaa !13
  %78 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %8, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %78)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret ptr %79
}

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

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


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

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

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

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

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

; 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: nofree nounwind uwtable
define dso_local noalias noundef ptr @_str_concat_private(ptr noundef readonly %0, ...) local_unnamed_addr #3 {
  %2 = alloca [1 x %struct.__va_list_tag], align 16
  %3 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  call void @llvm.va_start.p0(ptr nonnull %2)
  %.not21 = icmp eq ptr %0, null
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %.promoted = load i32, ptr %2, align 16
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  %5 = getelementptr inbounds i8, ptr %2, i64 16
  %6 = load ptr, ptr %5, align 16
  %.promoted24 = load ptr, ptr %4, align 8
  br label %7

7:                                                ; preds = %.lr.ph, %19
  %8 = phi ptr [ %.promoted24, %.lr.ph ], [ %20, %19 ]
  %.01423 = phi i64 [ 0, %.lr.ph ], [ %11, %19 ]
  %.01522 = phi ptr [ %0, %.lr.ph ], [ %23, %19 ]
  %9 = phi i32 [ %.promoted, %.lr.ph ], [ %21, %19 ]
  %10 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.01522) #6
  %11 = add i64 %10, %.01423
  %12 = icmp ult i32 %9, 41
  br i1 %12, label %13, label %17

13:                                               ; preds = %7
  %14 = zext nneg i32 %9 to i64
  %15 = getelementptr i8, ptr %6, i64 %14
  %16 = add nuw nsw i32 %9, 8
  store i32 %16, ptr %2, align 16
  br label %19

17:                                               ; preds = %7
  %18 = getelementptr i8, ptr %8, i64 8
  store ptr %18, ptr %4, align 8
  br label %19

19:                                               ; preds = %17, %13
  %20 = phi ptr [ %8, %13 ], [ %18, %17 ]
  %21 = phi i32 [ %16, %13 ], [ %9, %17 ]
  %22 = phi ptr [ %15, %13 ], [ %8, %17 ]
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %._crit_edge.loopexit, label %7, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %19
  %24 = add i64 %11, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.014.lcssa = phi i64 [ 1, %1 ], [ %24, %._crit_edge.loopexit ]
  call void @llvm.va_end.p0(ptr nonnull %2)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  %25 = call noalias ptr @malloc(i64 noundef %.014.lcssa) #7
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.va_start.p0(ptr nonnull %3)
  br i1 %.not21, label %._crit_edge34, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %._crit_edge
  %26 = getelementptr inbounds i8, ptr %3, i64 8
  %27 = getelementptr inbounds i8, ptr %3, i64 16
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %43
  %.033 = phi ptr [ %0, %.preheader.lr.ph ], [ %45, %43 ]
  %.01232 = phi ptr [ %25, %.preheader.lr.ph ], [ %.113.lcssa, %43 ]
  %28 = load i8, ptr %.033, align 1, !tbaa !11
  %.not2025 = icmp eq i8 %28, 0
  br i1 %.not2025, label %._crit_edge29, label %.lr.ph28

.lr.ph28:                                         ; preds = %.preheader, %.lr.ph28
  %29 = phi i8 [ %32, %.lr.ph28 ], [ %28, %.preheader ]
  %.127 = phi ptr [ %30, %.lr.ph28 ], [ %.033, %.preheader ]
  %.11326 = phi ptr [ %31, %.lr.ph28 ], [ %.01232, %.preheader ]
  %30 = getelementptr inbounds i8, ptr %.127, i64 1
  %31 = getelementptr inbounds i8, ptr %.11326, i64 1
  store i8 %29, ptr %.11326, align 1, !tbaa !11
  %32 = load i8, ptr %30, align 1, !tbaa !11
  %.not20 = icmp eq i8 %32, 0
  br i1 %.not20, label %._crit_edge29, label %.lr.ph28, !llvm.loop !12

._crit_edge29:                                    ; preds = %.lr.ph28, %.preheader
  %.113.lcssa = phi ptr [ %.01232, %.preheader ], [ %31, %.lr.ph28 ]
  %33 = load i32, ptr %3, align 16
  %34 = icmp ult i32 %33, 41
  br i1 %34, label %35, label %40

35:                                               ; preds = %._crit_edge29
  %36 = load ptr, ptr %27, align 16
  %37 = zext nneg i32 %33 to i64
  %38 = getelementptr i8, ptr %36, i64 %37
  %39 = add nuw nsw i32 %33, 8
  store i32 %39, ptr %3, align 16
  br label %43

40:                                               ; preds = %._crit_edge29
  %41 = load ptr, ptr %26, align 8
  %42 = getelementptr i8, ptr %41, i64 8
  store ptr %42, ptr %26, align 8
  br label %43

43:                                               ; preds = %40, %35
  %44 = phi ptr [ %38, %35 ], [ %41, %40 ]
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %.not19 = icmp eq ptr %45, null
  br i1 %.not19, label %._crit_edge34, label %.preheader, !llvm.loop !13

._crit_edge34:                                    ; preds = %43, %._crit_edge
  %.012.lcssa = phi ptr [ %25, %._crit_edge ], [ %.113.lcssa, %43 ]
  store i8 0, ptr %.012.lcssa, align 1, !tbaa !11
  call void @llvm.va_end.p0(ptr nonnull %3)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  ret ptr %25
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 = { nofree 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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