; LLVM IR from wrnlb666/yet-another-string-library-in-c :: yasli (str_appendeds)

; 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.string_t = type { i64, i64, [1 x i8] }

; 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

; 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: inlinehint nounwind uwtable
declare hidden zeroext i1 @str_resize(ptr noundef, i64 noundef) #2

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #3

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

16:                                               ; preds = %40, %1
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %43

20:                                               ; preds = %16
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.string_t, ptr %21, i32 0, i32 0
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = add i64 %24, %23
  store i64 %25, ptr %6, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %20
  %27 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  %28 = getelementptr inbounds %struct.__va_list_tag, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 16
  %30 = icmp ule i32 %29, 40
  br i1 %30, label %31, label %36

31:                                               ; preds = %26
  %32 = getelementptr inbounds %struct.__va_list_tag, ptr %27, i32 0, i32 3
  %33 = load ptr, ptr %32, align 16
  %34 = getelementptr i8, ptr %33, i32 %29
  %35 = add i32 %29, 8
  store i32 %35, ptr %28, align 16
  br label %40

36:                                               ; preds = %26
  %37 = getelementptr inbounds %struct.__va_list_tag, ptr %27, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8
  %39 = getelementptr i8, ptr %38, i32 8
  store ptr %39, ptr %37, align 8
  br label %40

40:                                               ; preds = %36, %31
  %41 = phi ptr [ %34, %31 ], [ %38, %36 ]
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  store ptr %42, ptr %7, align 8, !tbaa !5
  br label %16, !llvm.loop !13

43:                                               ; preds = %19
  %44 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %44)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store ptr null, ptr %8, align 8, !tbaa !5
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = call zeroext i1 @str_resize(ptr noundef %8, i64 noundef %45)
  br i1 %46, label %47, label %88

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %48, ptr %10, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %82, %47
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %85

53:                                               ; preds = %49
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.string_t, ptr %54, i32 0, i32 2
  %56 = getelementptr inbounds [1 x i8], ptr %55, i64 0, i64 0
  %57 = load i64, ptr %9, align 8, !tbaa !9
  %58 = getelementptr inbounds i8, ptr %56, i64 %57
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.string_t, ptr %59, i32 0, i32 2
  %61 = getelementptr inbounds [1 x i8], ptr %60, i64 0, i64 0
  %62 = call ptr @strcpy(ptr noundef %58, ptr noundef %61) #5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.string_t, ptr %63, i32 0, i32 0
  %65 = load i64, ptr %64, align 8, !tbaa !11
  %66 = load i64, ptr %9, align 8, !tbaa !9
  %67 = add i64 %66, %65
  store i64 %67, ptr %9, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %53
  %69 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %5, i64 0, i64 0
  %70 = getelementptr inbounds %struct.__va_list_tag, ptr %69, i32 0, i32 0
  %71 = load i32, ptr %70, align 16
  %72 = icmp ule i32 %71, 40
  br i1 %72, label %73, label %78

73:                                               ; preds = %68
  %74 = getelementptr inbounds %struct.__va_list_tag, ptr %69, i32 0, i32 3
  %75 = load ptr, ptr %74, align 16
  %76 = getelementptr i8, ptr %75, i32 %71
  %77 = add i32 %71, 8
  store i32 %77, ptr %70, align 16
  br label %82

78:                                               ; preds = %68
  %79 = getelementptr inbounds %struct.__va_list_tag, ptr %69, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8
  %81 = getelementptr i8, ptr %80, i32 8
  store ptr %81, ptr %79, align 8
  br label %82

82:                                               ; preds = %78, %73
  %83 = phi ptr [ %76, %73 ], [ %80, %78 ]
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  store ptr %84, ptr %10, align 8, !tbaa !5
  br label %49, !llvm.loop !15

85:                                               ; preds = %52
  %86 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %5, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %86)
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %87, ptr %2, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %90

88:                                               ; preds = %43
  %89 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %5, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %89)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %11, align 4
  br label %90

90:                                               ; preds = %88, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #5
  %91 = load ptr, ptr %2, align 8
  ret ptr %91
}

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


; 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 memory(argmem: readwrite)
declare void @llvm.lifetime.end.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: inlinehint nounwind uwtable
declare hidden zeroext i1 @str_resize(ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @str_appendeds(ptr noundef readonly %0, ...) local_unnamed_addr #4 {
  %2 = alloca [1 x %struct.__va_list_tag], align 16
  %3 = alloca [1 x %struct.__va_list_tag], align 16
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.va_start.p0(ptr nonnull %2)
  call void @llvm.va_copy.p0(ptr nonnull %3, ptr nonnull %2)
  %.not18 = icmp eq ptr %0, null
  br i1 %.not18, label %._crit_edge, label %.lr.ph

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

._crit_edge:                                      ; preds = %23, %1
  %.013.lcssa = phi i64 [ 0, %1 ], [ %15, %23 ]
  call void @llvm.va_end.p0(ptr nonnull %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  store ptr null, ptr %4, align 8, !tbaa !5
  %8 = call zeroext i1 @str_resize(ptr noundef nonnull %4, i64 noundef %.013.lcssa)
  br i1 %8, label %.preheader, label %50

.preheader:                                       ; preds = %._crit_edge
  br i1 %.not18, label %._crit_edge26, label %.lr.ph25

.lr.ph25:                                         ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  %10 = getelementptr inbounds i8, ptr %3, i64 16
  br label %29

11:                                               ; preds = %.lr.ph, %23
  %12 = phi ptr [ %.promoted21, %.lr.ph ], [ %24, %23 ]
  %.01220 = phi ptr [ %0, %.lr.ph ], [ %27, %23 ]
  %.01319 = phi i64 [ 0, %.lr.ph ], [ %15, %23 ]
  %13 = phi i32 [ %.promoted, %.lr.ph ], [ %25, %23 ]
  %14 = load i64, ptr %.01220, align 8, !tbaa !9
  %15 = add i64 %14, %.01319
  %16 = icmp ult i32 %13, 41
  br i1 %16, label %17, label %21

17:                                               ; preds = %11
  %18 = zext nneg i32 %13 to i64
  %19 = getelementptr i8, ptr %7, i64 %18
  %20 = add nuw nsw i32 %13, 8
  store i32 %20, ptr %2, align 16
  br label %23

21:                                               ; preds = %11
  %22 = getelementptr i8, ptr %12, i64 8
  store ptr %22, ptr %5, align 8
  br label %23

23:                                               ; preds = %21, %17
  %24 = phi ptr [ %12, %17 ], [ %22, %21 ]
  %25 = phi i32 [ %20, %17 ], [ %13, %21 ]
  %26 = phi ptr [ %19, %17 ], [ %12, %21 ]
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %.not = icmp eq ptr %27, null
  br i1 %.not, label %._crit_edge, label %11, !llvm.loop !12

._crit_edge26:                                    ; preds = %47, %.preheader
  call void @llvm.va_end.p0(ptr nonnull %3)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  br label %51

29:                                               ; preds = %.lr.ph25, %47
  %.024 = phi ptr [ %0, %.lr.ph25 ], [ %49, %47 ]
  %.01123 = phi i64 [ 0, %.lr.ph25 ], [ %36, %47 ]
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  %32 = getelementptr inbounds i8, ptr %31, i64 %.01123
  %33 = getelementptr inbounds i8, ptr %.024, i64 16
  %34 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %32, ptr noundef nonnull dereferenceable(1) %33) #5
  %35 = load i64, ptr %.024, align 8, !tbaa !9
  %36 = add i64 %35, %.01123
  %37 = load i32, ptr %3, align 16
  %38 = icmp ult i32 %37, 41
  br i1 %38, label %39, label %44

39:                                               ; preds = %29
  %40 = load ptr, ptr %10, align 16
  %41 = zext nneg i32 %37 to i64
  %42 = getelementptr i8, ptr %40, i64 %41
  %43 = add nuw nsw i32 %37, 8
  store i32 %43, ptr %3, align 16
  br label %47

44:                                               ; preds = %29
  %45 = load ptr, ptr %9, align 8
  %46 = getelementptr i8, ptr %45, i64 8
  store ptr %46, ptr %9, align 8
  br label %47

47:                                               ; preds = %44, %39
  %48 = phi ptr [ %42, %39 ], [ %45, %44 ]
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %.not17 = icmp eq ptr %49, null
  br i1 %.not17, label %._crit_edge26, label %29, !llvm.loop !14

50:                                               ; preds = %._crit_edge
  call void @llvm.va_end.p0(ptr nonnull %3)
  br label %51

51:                                               ; preds = %50, %._crit_edge26
  %.014 = phi ptr [ %28, %._crit_edge26 ], [ null, %50 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #5
  ret ptr %.014
}

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


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