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

; 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: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; 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) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @str_appended_cstrs(ptr noundef %0, ...) #5 {
  %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) #6
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #6
  %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) #6
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.string_t, ptr %15, i32 0, i32 2
  %17 = getelementptr inbounds [1 x i8], ptr %16, i64 0, i64 0
  store ptr %17, ptr %7, align 8, !tbaa !5
  br label %18

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

21:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  br label %44

22:                                               ; preds = %18
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call i64 @strlen(ptr noundef %23) #7
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = add i64 %25, %24
  store i64 %26, ptr %6, align 8, !tbaa !9
  br label %27

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

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

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

41:                                               ; preds = %37, %32
  %42 = phi ptr [ %35, %32 ], [ %39, %37 ]
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  store ptr %43, ptr %7, align 8, !tbaa !5
  br label %18, !llvm.loop !11

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

48:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.string_t, ptr %49, i32 0, i32 2
  %51 = getelementptr inbounds [1 x i8], ptr %50, i64 0, i64 0
  store ptr %51, ptr %10, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %82, %48
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %56, label %55

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

56:                                               ; preds = %52
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.string_t, ptr %57, i32 0, i32 2
  %59 = getelementptr inbounds [1 x i8], ptr %58, i64 0, i64 0
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = getelementptr inbounds i8, ptr %59, i64 %60
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = call ptr @strcpy(ptr noundef %61, ptr noundef %62) #6
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = call i64 @strlen(ptr noundef %64) #7
  %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 = %56
  %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 %52, !llvm.loop !13

85:                                               ; preds = %55
  %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) #6
  br label %90

88:                                               ; preds = %44
  %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) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #6
  %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 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 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 #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, !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 = distinct !{!13, !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 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 nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

; 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 #4

; Function Attrs: nounwind uwtable
define dso_local ptr @str_appended_cstrs(ptr nocapture noundef readonly %0, ...) local_unnamed_addr #5 {
  %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) #6
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #6
  call void @llvm.va_start.p0(ptr nonnull %2)
  call void @llvm.va_copy.p0(ptr nonnull %3, ptr nonnull %2)
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %.promoted = load i32, ptr %2, align 16
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  %8 = load ptr, ptr %7, align 16
  %.promoted20 = load ptr, ptr %6, align 8
  br label %13

9:                                                ; preds = %25
  call void @llvm.va_end.p0(ptr nonnull %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  store ptr null, ptr %4, align 8, !tbaa !5
  %10 = call zeroext i1 @str_resize(ptr noundef nonnull %4, i64 noundef %17)
  br i1 %10, label %.preheader, label %52

.preheader:                                       ; preds = %9
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  %12 = getelementptr inbounds i8, ptr %3, i64 16
  br label %32

13:                                               ; preds = %1, %25
  %14 = phi ptr [ %.promoted20, %1 ], [ %26, %25 ]
  %.01219 = phi ptr [ %5, %1 ], [ %29, %25 ]
  %.01318 = phi i64 [ 0, %1 ], [ %17, %25 ]
  %15 = phi i32 [ %.promoted, %1 ], [ %27, %25 ]
  %16 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.01219) #7
  %17 = add i64 %16, %.01318
  %18 = icmp ult i32 %15, 41
  br i1 %18, label %19, label %23

19:                                               ; preds = %13
  %20 = zext nneg i32 %15 to i64
  %21 = getelementptr i8, ptr %8, i64 %20
  %22 = add nuw nsw i32 %15, 8
  store i32 %22, ptr %2, align 16
  br label %25

23:                                               ; preds = %13
  %24 = getelementptr i8, ptr %14, i64 8
  store ptr %24, ptr %6, align 8
  br label %25

25:                                               ; preds = %23, %19
  %26 = phi ptr [ %14, %19 ], [ %24, %23 ]
  %27 = phi i32 [ %22, %19 ], [ %15, %23 ]
  %28 = phi ptr [ %21, %19 ], [ %14, %23 ]
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %.not = icmp eq ptr %29, null
  br i1 %.not, label %9, label %13, !llvm.loop !9

30:                                               ; preds = %49
  call void @llvm.va_end.p0(ptr nonnull %3)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  br label %53

32:                                               ; preds = %.preheader, %49
  %.022 = phi ptr [ %5, %.preheader ], [ %51, %49 ]
  %.01121 = phi i64 [ 0, %.preheader ], [ %38, %49 ]
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  %35 = getelementptr inbounds i8, ptr %34, i64 %.01121
  %36 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %35, ptr noundef nonnull dereferenceable(1) %.022) #6
  %37 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.022) #7
  %38 = add i64 %37, %.01121
  %39 = load i32, ptr %3, align 16
  %40 = icmp ult i32 %39, 41
  br i1 %40, label %41, label %46

41:                                               ; preds = %32
  %42 = load ptr, ptr %12, align 16
  %43 = zext nneg i32 %39 to i64
  %44 = getelementptr i8, ptr %42, i64 %43
  %45 = add nuw nsw i32 %39, 8
  store i32 %45, ptr %3, align 16
  br label %49

46:                                               ; preds = %32
  %47 = load ptr, ptr %11, align 8
  %48 = getelementptr i8, ptr %47, i64 8
  store ptr %48, ptr %11, align 8
  br label %49

49:                                               ; preds = %46, %41
  %50 = phi ptr [ %44, %41 ], [ %47, %46 ]
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %.not17 = icmp eq ptr %51, null
  br i1 %.not17, label %30, label %32, !llvm.loop !11

52:                                               ; preds = %9
  call void @llvm.va_end.p0(ptr nonnull %3)
  br label %53

53:                                               ; preds = %52, %30
  %.014 = phi ptr [ %31, %30 ], [ null, %52 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #6
  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: 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 = { 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 #5 = { 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 #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, !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 = distinct !{!11, !10}


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