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

; 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 uwtable
define dso_local ptr @str_new_strings(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 i64, align 8
  %9 = alloca ptr, 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
  store ptr %15, ptr %7, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %39, %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) #6
  br label %42

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

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

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

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

39:                                               ; preds = %35, %30
  %40 = phi ptr [ %33, %30 ], [ %37, %35 ]
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  store ptr %41, ptr %7, align 8, !tbaa !5
  br label %16, !llvm.loop !11

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

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

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

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

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

64:                                               ; preds = %52
  %65 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %5, i64 0, i64 0
  %66 = getelementptr inbounds %struct.__va_list_tag, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 16
  %68 = icmp ule i32 %67, 40
  br i1 %68, label %69, label %74

69:                                               ; preds = %64
  %70 = getelementptr inbounds %struct.__va_list_tag, ptr %65, i32 0, i32 3
  %71 = load ptr, ptr %70, align 16
  %72 = getelementptr i8, ptr %71, i32 %67
  %73 = add i32 %67, 8
  store i32 %73, ptr %66, align 16
  br label %78

74:                                               ; preds = %64
  %75 = getelementptr inbounds %struct.__va_list_tag, ptr %65, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8
  %77 = getelementptr i8, ptr %76, i32 8
  store ptr %77, ptr %75, align 8
  br label %78

78:                                               ; preds = %74, %69
  %79 = phi ptr [ %72, %69 ], [ %76, %74 ]
  %80 = load ptr, ptr %79, align 8, !tbaa !5
  store ptr %80, ptr %10, align 8, !tbaa !5
  br label %48, !llvm.loop !13

81:                                               ; preds = %51
  %82 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %5, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %82)
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %83, ptr %2, align 8
  store i32 1, ptr %11, align 4
  br label %86

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

86:                                               ; preds = %84, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  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
  %87 = load ptr, ptr %2, align 8
  ret ptr %87
}

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

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 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 "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: nounwind uwtable
define dso_local ptr @str_new_strings(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) #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)
  %.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) #6
  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 %49

.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 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.01220) #7
  %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 !9

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

29:                                               ; preds = %.lr.ph25, %46
  %.024 = phi ptr [ %0, %.lr.ph25 ], [ %48, %46 ]
  %.01123 = phi i64 [ 0, %.lr.ph25 ], [ %35, %46 ]
  %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 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %32, ptr noundef nonnull dereferenceable(1) %.024) #6
  %34 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.024) #7
  %35 = add i64 %34, %.01123
  %36 = load i32, ptr %3, align 16
  %37 = icmp ult i32 %36, 41
  br i1 %37, label %38, label %43

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

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

46:                                               ; preds = %43, %38
  %47 = phi ptr [ %41, %38 ], [ %44, %43 ]
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %.not17 = icmp eq ptr %48, null
  br i1 %.not17, label %._crit_edge26, label %29, !llvm.loop !11

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

50:                                               ; preds = %49, %._crit_edge26
  %.014 = phi ptr [ %28, %._crit_edge26 ], [ null, %49 ]
  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
}

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

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 = { 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 = { 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 #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,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass