; LLVM IR from russellsayshi/CeeBeeServer :: main (mstringcat)

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

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

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

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @mstringcat(i32 noundef %0, ...) #5 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca [1 x %struct.__va_list_tag], align 16
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #6
  %15 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %15)
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  %18 = call ptr @llvm.stacksave.p0()
  store ptr %18, ptr %5, align 8
  %19 = alloca i64, i64 %17, align 16
  store i64 %17, ptr %6, align 8
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = alloca ptr, i64 %21, align 16
  store i64 %21, ptr %7, align 8
  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 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %60, %1
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %63

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %29 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  %30 = getelementptr inbounds %struct.__va_list_tag, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 16
  %32 = icmp ule i32 %31, 40
  br i1 %32, label %33, label %38

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

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

42:                                               ; preds = %38, %33
  %43 = phi ptr [ %36, %33 ], [ %40, %38 ]
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  store ptr %44, ptr %10, align 8, !tbaa !11
  %45 = load ptr, ptr %10, align 8, !tbaa !11
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds ptr, ptr %22, i64 %47
  store ptr %45, ptr %48, align 8, !tbaa !11
  %49 = load ptr, ptr %10, align 8, !tbaa !11
  %50 = call i64 @strlen(ptr noundef %49) #7
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i64, ptr %19, i64 %52
  store i64 %50, ptr %53, align 8, !tbaa !9
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i64, ptr %19, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = load i64, ptr %8, align 8, !tbaa !9
  %59 = add i64 %58, %57
  store i64 %59, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %60

60:                                               ; preds = %42
  %61 = load i32, ptr %9, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %9, align 4, !tbaa !5
  br label %23, !llvm.loop !13

63:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = add i64 %64, 1
  %66 = call noalias ptr @malloc(i64 noundef %65) #8
  store ptr %66, ptr %11, align 8, !tbaa !11
  %67 = load ptr, ptr %11, align 8, !tbaa !11
  %68 = icmp eq ptr %67, null
  br i1 %68, label %69, label %71

69:                                               ; preds = %63
  %70 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %70)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %102

71:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %72 = load ptr, ptr %11, align 8, !tbaa !11
  store ptr %72, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %95, %71
  %74 = load i32, ptr %14, align 4, !tbaa !5
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = icmp slt i32 %74, %75
  br i1 %76, label %78, label %77

77:                                               ; preds = %73
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  br label %98

78:                                               ; preds = %73
  %79 = load ptr, ptr %13, align 8, !tbaa !11
  %80 = load i32, ptr %14, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds ptr, ptr %22, i64 %81
  %83 = load ptr, ptr %82, align 8, !tbaa !11
  %84 = load i32, ptr %14, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds i64, ptr %19, i64 %85
  %87 = load i64, ptr %86, align 8, !tbaa !9
  %88 = call ptr @strncpy(ptr noundef %79, ptr noundef %83, i64 noundef %87) #6
  %89 = load i32, ptr %14, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i64, ptr %19, i64 %90
  %92 = load i64, ptr %91, align 8, !tbaa !9
  %93 = load ptr, ptr %13, align 8, !tbaa !11
  %94 = getelementptr inbounds i8, ptr %93, i64 %92
  store ptr %94, ptr %13, align 8, !tbaa !11
  br label %95

95:                                               ; preds = %78
  %96 = load i32, ptr %14, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %14, align 4, !tbaa !5
  br label %73, !llvm.loop !15

98:                                               ; preds = %77
  %99 = load ptr, ptr %13, align 8, !tbaa !11
  store i8 0, ptr %99, align 1, !tbaa !16
  %100 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %4, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %100)
  %101 = load ptr, ptr %11, align 8, !tbaa !11
  store ptr %101, ptr %2, align 8
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  br label %102

102:                                              ; preds = %98, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %103 = load ptr, ptr %5, align 8
  call void @llvm.stackrestore.p0(ptr %103)
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #6
  %104 = load ptr, ptr %2, align 8
  ret ptr %104
}

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

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

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


; 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 nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

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

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

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

; Function Attrs: nofree nounwind uwtable
define dso_local noundef ptr @mstringcat(i32 noundef %0, ...) local_unnamed_addr #5 {
  %2 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #6
  call void @llvm.va_start.p0(ptr nonnull %2)
  %3 = zext i32 %0 to i64
  %4 = call ptr @llvm.stacksave.p0()
  %5 = alloca i64, i64 %3, align 16
  %6 = alloca ptr, i64 %3, align 16
  %7 = icmp sgt i32 %0, 0
  br i1 %7, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %1
  %.promoted = load i32, ptr %2, align 16
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = getelementptr inbounds i8, ptr %2, i64 16
  %10 = load ptr, ptr %9, align 16
  %.promoted34 = load ptr, ptr %8, align 8
  br label %16

._crit_edge:                                      ; preds = %26
  %11 = add i64 %34, 1
  %12 = call noalias ptr @malloc(i64 noundef %11) #7
  %13 = icmp eq ptr %12, null
  br i1 %13, label %42, label %.preheader

._crit_edge.thread:                               ; preds = %1
  %14 = call noalias dereferenceable_or_null(1) ptr @malloc(i64 noundef 1) #7
  %15 = icmp eq ptr %14, null
  br i1 %15, label %42, label %._crit_edge38

.preheader:                                       ; preds = %._crit_edge
  br i1 %7, label %.lr.ph37, label %._crit_edge38

16:                                               ; preds = %.lr.ph, %26
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %26 ]
  %17 = phi ptr [ %.promoted34, %.lr.ph ], [ %27, %26 ]
  %.02733 = phi i64 [ 0, %.lr.ph ], [ %34, %26 ]
  %18 = phi i32 [ %.promoted, %.lr.ph ], [ %28, %26 ]
  %19 = icmp ult i32 %18, 41
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = zext nneg i32 %18 to i64
  %22 = getelementptr i8, ptr %10, i64 %21
  %23 = add nuw nsw i32 %18, 8
  store i32 %23, ptr %2, align 16
  br label %26

24:                                               ; preds = %16
  %25 = getelementptr i8, ptr %17, i64 8
  store ptr %25, ptr %8, align 8
  br label %26

26:                                               ; preds = %24, %20
  %27 = phi ptr [ %17, %20 ], [ %25, %24 ]
  %28 = phi i32 [ %23, %20 ], [ %18, %24 ]
  %29 = phi ptr [ %22, %20 ], [ %17, %24 ]
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv
  store ptr %30, ptr %31, align 8, !tbaa !5
  %32 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %30) #8
  %33 = getelementptr inbounds i64, ptr %5, i64 %indvars.iv
  store i64 %32, ptr %33, align 8, !tbaa !9
  %34 = add i64 %32, %.02733
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %3
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !11

._crit_edge38:                                    ; preds = %.lr.ph37, %._crit_edge.thread, %.preheader
  %35 = phi ptr [ %12, %.preheader ], [ %14, %._crit_edge.thread ], [ %12, %.lr.ph37 ]
  %.025.lcssa = phi ptr [ %12, %.preheader ], [ %14, %._crit_edge.thread ], [ %41, %.lr.ph37 ]
  store i8 0, ptr %.025.lcssa, align 1, !tbaa !13
  br label %42

.lr.ph37:                                         ; preds = %.preheader, %.lr.ph37
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %.lr.ph37 ], [ 0, %.preheader ]
  %.02535 = phi ptr [ %41, %.lr.ph37 ], [ %12, %.preheader ]
  %36 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv42
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds i64, ptr %5, i64 %indvars.iv42
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = call ptr @strncpy(ptr noundef %.02535, ptr noundef %37, i64 noundef %39) #6
  %41 = getelementptr inbounds i8, ptr %.02535, i64 %39
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %exitcond46.not = icmp eq i64 %indvars.iv.next43, %3
  br i1 %exitcond46.not, label %._crit_edge38, label %.lr.ph37, !llvm.loop !14

42:                                               ; preds = %._crit_edge, %._crit_edge.thread, %._crit_edge38
  %43 = phi ptr [ %35, %._crit_edge38 ], [ null, %._crit_edge.thread ], [ null, %._crit_edge ]
  call void @llvm.va_end.p0(ptr nonnull %2)
  call void @llvm.stackrestore.p0(ptr %4)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #6
  ret ptr %43
}

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 #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 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { 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 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}


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