; LLVM IR from Water-Melon/Melon :: src (mln_string)

; 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.mln_string_t = type { ptr, i64, i32 }

; 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

declare ptr @mln_alloc_m(ptr noundef, i64 noundef) #1

declare void @mln_alloc_free(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @mln_string_pool_strcat(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call ptr @mln_alloc_m(ptr noundef %11, i64 noundef 24)
  store ptr %12, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %117

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mln_string_t, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.mln_string_t, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = add i64 %19, %22
  store i64 %23, ptr %10, align 8, !tbaa !12
  %24 = load i64, ptr %10, align 8, !tbaa !12
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %47

26:                                               ; preds = %16
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mln_string_t, ptr %27, i32 0, i32 0
  store ptr null, ptr %28, align 8, !tbaa !13
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mln_string_t, ptr %29, i32 0, i32 1
  store i64 0, ptr %30, align 8, !tbaa !9
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mln_string_t, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8
  %34 = and i32 %33, -2
  %35 = or i32 %34, 0
  store i32 %35, ptr %32, align 8
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mln_string_t, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 8
  %39 = and i32 %38, -3
  %40 = or i32 %39, 2
  store i32 %40, ptr %37, align 8
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.mln_string_t, ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 8
  %44 = and i32 %43, 3
  %45 = or i32 %44, 4
  store i32 %45, ptr %42, align 8
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %46, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %116

47:                                               ; preds = %16
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load i64, ptr %10, align 8, !tbaa !12
  %50 = add i64 %49, 1
  %51 = call ptr @mln_alloc_m(ptr noundef %48, i64 noundef %50)
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.mln_string_t, ptr %52, i32 0, i32 0
  store ptr %51, ptr %53, align 8, !tbaa !13
  %54 = icmp eq ptr %51, null
  br i1 %54, label %55, label %57

55:                                               ; preds = %47
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  call void @mln_alloc_free(ptr noundef %56)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %116

57:                                               ; preds = %47
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mln_string_t, ptr %58, i32 0, i32 1
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = icmp ugt i64 %60, 0
  br i1 %61, label %62, label %72

62:                                               ; preds = %57
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.mln_string_t, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !13
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mln_string_t, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !13
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mln_string_t, ptr %69, i32 0, i32 1
  %71 = load i64, ptr %70, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %65, ptr align 1 %68, i64 %71, i1 false)
  br label %72

72:                                               ; preds = %62, %57
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.mln_string_t, ptr %73, i32 0, i32 1
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = icmp ugt i64 %75, 0
  br i1 %76, label %77, label %91

77:                                               ; preds = %72
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.mln_string_t, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !13
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.mln_string_t, ptr %81, i32 0, i32 1
  %83 = load i64, ptr %82, align 8, !tbaa !9
  %84 = getelementptr inbounds i8, ptr %80, i64 %83
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.mln_string_t, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !13
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.mln_string_t, ptr %88, i32 0, i32 1
  %90 = load i64, ptr %89, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %84, ptr align 1 %87, i64 %90, i1 false)
  br label %91

91:                                               ; preds = %77, %72
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.mln_string_t, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !13
  %95 = load i64, ptr %10, align 8, !tbaa !12
  %96 = getelementptr inbounds i8, ptr %94, i64 %95
  store i8 0, ptr %96, align 1, !tbaa !14
  %97 = load i64, ptr %10, align 8, !tbaa !12
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.mln_string_t, ptr %98, i32 0, i32 1
  store i64 %97, ptr %99, align 8, !tbaa !9
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.mln_string_t, ptr %100, i32 0, i32 2
  %102 = load i32, ptr %101, align 8
  %103 = and i32 %102, -2
  %104 = or i32 %103, 0
  store i32 %104, ptr %101, align 8
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.mln_string_t, ptr %105, i32 0, i32 2
  %107 = load i32, ptr %106, align 8
  %108 = and i32 %107, -3
  %109 = or i32 %108, 2
  store i32 %109, ptr %106, align 8
  %110 = load ptr, ptr %8, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.mln_string_t, ptr %110, i32 0, i32 2
  %112 = load i32, ptr %111, align 8
  %113 = and i32 %112, 3
  %114 = or i32 %113, 4
  store i32 %114, ptr %111, align 8
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %115, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %116

116:                                              ; preds = %91, %55, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %117

117:                                              ; preds = %116, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %118 = load ptr, ptr %4, align 8
  ret ptr %118
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 8}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 16, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!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"

declare ptr @mln_alloc_m(ptr noundef, i64 noundef) local_unnamed_addr #0

declare void @mln_alloc_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @mln_string_pool_strcat(ptr noundef nonnull %0, ptr nocapture noundef nonnull readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #2 {
  %4 = tail call ptr @mln_alloc_m(ptr noundef nonnull %0, i64 noundef 24) #4
  %5 = icmp eq ptr %4, null
  br i1 %5, label %35, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %2, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = add i64 %10, %8
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %6
  %14 = getelementptr inbounds i8, ptr %4, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, i8 0, i64 16, i1 false)
  store i32 6, ptr %14, align 8
  br label %35

15:                                               ; preds = %6
  %16 = add i64 %11, 1
  %17 = tail call ptr @mln_alloc_m(ptr noundef nonnull %0, i64 noundef %16) #4
  store ptr %17, ptr %4, align 8, !tbaa !11
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  tail call void @mln_alloc_free(ptr noundef nonnull %4) #4
  br label %35

20:                                               ; preds = %15
  %21 = load i64, ptr %7, align 8, !tbaa !5
  %.not = icmp eq i64 %21, 0
  br i1 %.not, label %24, label %22

22:                                               ; preds = %20
  %23 = load ptr, ptr %1, align 8, !tbaa !11
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %17, ptr align 1 %23, i64 %21, i1 false)
  %.pre38.pre = load ptr, ptr %4, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %22, %20
  %.pre38 = phi ptr [ %.pre38.pre, %22 ], [ %17, %20 ]
  %25 = load i64, ptr %9, align 8, !tbaa !5
  %.not37 = icmp eq i64 %25, 0
  br i1 %.not37, label %30, label %26

26:                                               ; preds = %24
  %27 = load i64, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.pre38, i64 %27
  %29 = load ptr, ptr %2, align 8, !tbaa !11
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %28, ptr align 1 %29, i64 %25, i1 false)
  %.pre = load ptr, ptr %4, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %26, %24
  %31 = phi ptr [ %.pre, %26 ], [ %.pre38, %24 ]
  %32 = getelementptr inbounds i8, ptr %31, i64 %11
  store i8 0, ptr %32, align 1, !tbaa !12
  %33 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 %11, ptr %33, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %4, i64 16
  store i32 6, ptr %34, align 8
  br label %35

35:                                               ; preds = %13, %19, %30, %3
  %.1 = phi ptr [ null, %3 ], [ %4, %13 ], [ null, %19 ], [ %4, %30 ]
  ret ptr %.1
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 16, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass