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

; 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_appends(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 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
  %11 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %11)
  %12 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %5, i64 0, i64 0
  %13 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_copy.p0(ptr %12, ptr %13)
  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
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %14, 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
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.string_t, ptr %46, i32 0, i32 0
  %48 = load i64, ptr %47, align 8, !tbaa !11
  store i64 %48, ptr %8, align 8, !tbaa !9
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = call zeroext i1 @str_resize(ptr noundef %49, i64 noundef %50)
  br i1 %51, label %52, label %110

52:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %53 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %5, i64 0, i64 0
  %54 = getelementptr inbounds %struct.__va_list_tag, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 16
  %56 = icmp ule i32 %55, 40
  br i1 %56, label %57, label %62

57:                                               ; preds = %52
  %58 = getelementptr inbounds %struct.__va_list_tag, ptr %53, i32 0, i32 3
  %59 = load ptr, ptr %58, align 16
  %60 = getelementptr i8, ptr %59, i32 %55
  %61 = add i32 %55, 8
  store i32 %61, ptr %54, align 16
  br label %66

62:                                               ; preds = %52
  %63 = getelementptr inbounds %struct.__va_list_tag, ptr %53, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8
  %65 = getelementptr i8, ptr %64, i32 8
  store ptr %65, ptr %63, align 8
  br label %66

66:                                               ; preds = %62, %57
  %67 = phi ptr [ %60, %57 ], [ %64, %62 ]
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  store ptr %68, ptr %9, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %103, %66
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %73, label %72

72:                                               ; preds = %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %106

73:                                               ; preds = %69
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.string_t, ptr %75, i32 0, i32 2
  %77 = getelementptr inbounds [1 x i8], ptr %76, i64 0, i64 0
  %78 = load i64, ptr %8, align 8, !tbaa !9
  %79 = getelementptr inbounds i8, ptr %77, i64 %78
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.string_t, ptr %80, i32 0, i32 2
  %82 = getelementptr inbounds [1 x i8], ptr %81, i64 0, i64 0
  %83 = call ptr @strcpy(ptr noundef %79, ptr noundef %82) #5
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.string_t, ptr %84, i32 0, i32 0
  %86 = load i64, ptr %85, align 8, !tbaa !11
  %87 = load i64, ptr %8, align 8, !tbaa !9
  %88 = add i64 %87, %86
  store i64 %88, ptr %8, align 8, !tbaa !9
  br label %89

89:                                               ; preds = %73
  %90 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %5, i64 0, i64 0
  %91 = getelementptr inbounds %struct.__va_list_tag, ptr %90, i32 0, i32 0
  %92 = load i32, ptr %91, align 16
  %93 = icmp ule i32 %92, 40
  br i1 %93, label %94, label %99

94:                                               ; preds = %89
  %95 = getelementptr inbounds %struct.__va_list_tag, ptr %90, i32 0, i32 3
  %96 = load ptr, ptr %95, align 16
  %97 = getelementptr i8, ptr %96, i32 %92
  %98 = add i32 %92, 8
  store i32 %98, ptr %91, align 16
  br label %103

99:                                               ; preds = %89
  %100 = getelementptr inbounds %struct.__va_list_tag, ptr %90, i32 0, i32 2
  %101 = load ptr, ptr %100, align 8
  %102 = getelementptr i8, ptr %101, i32 8
  store ptr %102, ptr %100, align 8
  br label %103

103:                                              ; preds = %99, %94
  %104 = phi ptr [ %97, %94 ], [ %101, %99 ]
  %105 = load ptr, ptr %104, align 8, !tbaa !5
  store ptr %105, ptr %9, align 8, !tbaa !5
  br label %69, !llvm.loop !15

106:                                              ; preds = %72
  %107 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %5, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %107)
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = load ptr, ptr %108, align 8, !tbaa !5
  store ptr %109, ptr %2, align 8
  store i32 1, ptr %10, align 4
  br label %112

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

112:                                              ; preds = %110, %106
  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
  %113 = load ptr, ptr %2, align 8
  ret ptr %113
}

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_appends(ptr noundef %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
  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)
  %.01522 = load ptr, ptr %0, align 8, !tbaa !5
  %.not23 = icmp eq ptr %.01522, null
  br i1 %.not23, 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
  %.promoted26 = load ptr, ptr %4, align 8
  br label %10

._crit_edge:                                      ; preds = %22, %1
  %.016.lcssa = phi i64 [ 0, %1 ], [ %14, %22 ]
  call void @llvm.va_end.p0(ptr nonnull %2)
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = call zeroext i1 @str_resize(ptr noundef nonnull %0, i64 noundef %.016.lcssa)
  br i1 %9, label %26, label %64

10:                                               ; preds = %.lr.ph, %22
  %11 = phi ptr [ %.promoted26, %.lr.ph ], [ %23, %22 ]
  %.01525 = phi ptr [ %.01522, %.lr.ph ], [ %.015, %22 ]
  %.01624 = phi i64 [ 0, %.lr.ph ], [ %14, %22 ]
  %12 = phi i32 [ %.promoted, %.lr.ph ], [ %24, %22 ]
  %13 = load i64, ptr %.01525, align 8, !tbaa !9
  %14 = add i64 %13, %.01624
  %15 = icmp ult i32 %12, 41
  br i1 %15, label %16, label %20

16:                                               ; preds = %10
  %17 = zext nneg i32 %12 to i64
  %18 = getelementptr i8, ptr %6, i64 %17
  %19 = add nuw nsw i32 %12, 8
  store i32 %19, ptr %2, align 16
  br label %22

20:                                               ; preds = %10
  %21 = getelementptr i8, ptr %11, i64 8
  store ptr %21, ptr %4, align 8
  br label %22

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

26:                                               ; preds = %._crit_edge
  %27 = load i32, ptr %3, align 16
  %28 = icmp ult i32 %27, 41
  br i1 %28, label %29, label %35

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %3, i64 16
  %31 = load ptr, ptr %30, align 16
  %32 = zext nneg i32 %27 to i64
  %33 = getelementptr i8, ptr %31, i64 %32
  %34 = add nuw nsw i32 %27, 8
  store i32 %34, ptr %3, align 16
  br label %39

35:                                               ; preds = %26
  %36 = getelementptr inbounds i8, ptr %3, i64 8
  %37 = load ptr, ptr %36, align 8
  %38 = getelementptr i8, ptr %37, i64 8
  store ptr %38, ptr %36, align 8
  br label %39

39:                                               ; preds = %35, %29
  %40 = phi ptr [ %33, %29 ], [ %37, %35 ]
  %.027 = load ptr, ptr %40, align 8, !tbaa !5
  %.not2128 = icmp eq ptr %.027, null
  br i1 %.not2128, label %._crit_edge33, label %.lr.ph32

.lr.ph32:                                         ; preds = %39
  %41 = getelementptr inbounds i8, ptr %3, i64 8
  %42 = getelementptr inbounds i8, ptr %3, i64 16
  br label %44

._crit_edge33:                                    ; preds = %62, %39
  call void @llvm.va_end.p0(ptr nonnull %3)
  %43 = load ptr, ptr %0, align 8, !tbaa !5
  br label %65

44:                                               ; preds = %.lr.ph32, %62
  %.030 = phi ptr [ %.027, %.lr.ph32 ], [ %.0, %62 ]
  %.01429 = phi i64 [ %8, %.lr.ph32 ], [ %51, %62 ]
  %45 = load ptr, ptr %0, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 16
  %47 = getelementptr inbounds i8, ptr %46, i64 %.01429
  %48 = getelementptr inbounds i8, ptr %.030, i64 16
  %49 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %47, ptr noundef nonnull dereferenceable(1) %48) #5
  %50 = load i64, ptr %.030, align 8, !tbaa !9
  %51 = add i64 %50, %.01429
  %52 = load i32, ptr %3, align 16
  %53 = icmp ult i32 %52, 41
  br i1 %53, label %54, label %59

54:                                               ; preds = %44
  %55 = load ptr, ptr %42, align 16
  %56 = zext nneg i32 %52 to i64
  %57 = getelementptr i8, ptr %55, i64 %56
  %58 = add nuw nsw i32 %52, 8
  store i32 %58, ptr %3, align 16
  br label %62

59:                                               ; preds = %44
  %60 = load ptr, ptr %41, align 8
  %61 = getelementptr i8, ptr %60, i64 8
  store ptr %61, ptr %41, align 8
  br label %62

62:                                               ; preds = %59, %54
  %63 = phi ptr [ %57, %54 ], [ %60, %59 ]
  %.0 = load ptr, ptr %63, align 8, !tbaa !5
  %.not21 = icmp eq ptr %.0, null
  br i1 %.not21, label %._crit_edge33, label %44, !llvm.loop !14

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

65:                                               ; preds = %64, %._crit_edge33
  %.017 = phi ptr [ %43, %._crit_edge33 ], [ null, %64 ]
  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 %.017
}

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,ReassociatePass,SROAPass,SimplifyCFGPass