; LLVM IR from NOAA-PMEL/Ferret :: fer/ccr (c_strcat)

; 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"

@STRING_MISSING_VALUE = external global ptr, align 8
@.str = external hidden unnamed_addr constant [69 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @c_strcat_(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %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 i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %22

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %18 = icmp ne ptr %16, %17
  br i1 %18, label %19, label %22

19:                                               ; preds = %14
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  call void @FerMem_Free(ptr noundef %21, ptr noundef @.str, i32 noundef 56)
  br label %22

22:                                               ; preds = %19, %14, %3
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %31, label %26

26:                                               ; preds = %22
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %30 = icmp eq ptr %28, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %26, %22
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %37

32:                                               ; preds = %26
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = call i64 @strlen(ptr noundef %34) #6
  %36 = trunc i64 %35 to i32
  store i32 %36, ptr %9, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %32, %31
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %46, label %41

41:                                               ; preds = %37
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %45 = icmp eq ptr %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %41, %37
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %52

47:                                               ; preds = %41
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = call i64 @strlen(ptr noundef %49) #6
  %51 = trunc i64 %50 to i32
  store i32 %51, ptr %10, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %47, %46
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = add nsw i32 %53, %54
  %56 = add nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = mul i64 1, %57
  %59 = call ptr @FerMem_Malloc(i64 noundef %58, ptr noundef @.str, i32 noundef 68)
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %59, ptr %60, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = icmp eq ptr %62, null
  br i1 %63, label %64, label %65

64:                                               ; preds = %52
  call void @abort() #7
  unreachable

65:                                               ; preds = %52
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  store ptr %67, ptr %8, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %93

71:                                               ; preds = %65
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %75 = icmp ne ptr %73, %74
  br i1 %75, label %76, label %93

76:                                               ; preds = %71
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = load ptr, ptr %77, align 8, !tbaa !5
  store ptr %78, ptr %7, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %84, %76
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load i8, ptr %80, align 1, !tbaa !11
  %82 = sext i8 %81 to i32
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %92

84:                                               ; preds = %79
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load i8, ptr %85, align 1, !tbaa !11
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 %86, ptr %87, align 1, !tbaa !11
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds i8, ptr %88, i32 1
  store ptr %89, ptr %7, align 8, !tbaa !5
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = getelementptr inbounds i8, ptr %90, i32 1
  store ptr %91, ptr %8, align 8, !tbaa !5
  br label %79, !llvm.loop !12

92:                                               ; preds = %79
  br label %93

93:                                               ; preds = %92, %71, %65
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = load ptr, ptr %94, align 8, !tbaa !5
  %96 = icmp ne ptr %95, null
  br i1 %96, label %97, label %119

97:                                               ; preds = %93
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = load ptr, ptr %98, align 8, !tbaa !5
  %100 = load ptr, ptr @STRING_MISSING_VALUE, align 8, !tbaa !5
  %101 = icmp ne ptr %99, %100
  br i1 %101, label %102, label %119

102:                                              ; preds = %97
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = load ptr, ptr %103, align 8, !tbaa !5
  store ptr %104, ptr %7, align 8, !tbaa !5
  br label %105

105:                                              ; preds = %110, %102
  %106 = load ptr, ptr %7, align 8, !tbaa !5
  %107 = load i8, ptr %106, align 1, !tbaa !11
  %108 = sext i8 %107 to i32
  %109 = icmp ne i32 %108, 0
  br i1 %109, label %110, label %118

110:                                              ; preds = %105
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  %112 = load i8, ptr %111, align 1, !tbaa !11
  %113 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 %112, ptr %113, align 1, !tbaa !11
  %114 = load ptr, ptr %7, align 8, !tbaa !5
  %115 = getelementptr inbounds i8, ptr %114, i32 1
  store ptr %115, ptr %7, align 8, !tbaa !5
  %116 = load ptr, ptr %8, align 8, !tbaa !5
  %117 = getelementptr inbounds i8, ptr %116, i32 1
  store ptr %117, ptr %8, align 8, !tbaa !5
  br label %105, !llvm.loop !14

118:                                              ; preds = %105
  br label %119

119:                                              ; preds = %118, %97, %93
  %120 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 0, ptr %120, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare void @FerMem_Free(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

declare ptr @FerMem_Malloc(i64 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: noreturn nounwind
declare void @abort() #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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


; 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"

@STRING_MISSING_VALUE = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [69 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @c_strcat_(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  %5 = load ptr, ptr @STRING_MISSING_VALUE, align 8
  %.not40 = icmp eq ptr %4, %5
  %or.cond = select i1 %.not, i1 true, i1 %.not40
  br i1 %or.cond, label %7, label %6

6:                                                ; preds = %3
  tail call void @FerMem_Free(ptr noundef nonnull %4, ptr noundef nonnull @.str, i32 noundef 56) #4
  %.pre = load ptr, ptr @STRING_MISSING_VALUE, align 8
  br label %7

7:                                                ; preds = %6, %3
  %8 = phi ptr [ %.pre, %6 ], [ %5, %3 ]
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  %11 = icmp eq ptr %9, %8
  %or.cond48 = select i1 %10, i1 true, i1 %11
  br i1 %or.cond48, label %14, label %12

12:                                               ; preds = %7
  %13 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %9) #5
  br label %14

14:                                               ; preds = %7, %12
  %.030 = phi i64 [ %13, %12 ], [ 0, %7 ]
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  %17 = icmp eq ptr %15, %8
  %or.cond50 = select i1 %16, i1 true, i1 %17
  br i1 %or.cond50, label %20, label %18

18:                                               ; preds = %14
  %19 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %15) #5
  br label %20

20:                                               ; preds = %14, %18
  %.0 = phi i64 [ %19, %18 ], [ 0, %14 ]
  %21 = add i64 %.0, %.030
  %22 = shl i64 %21, 32
  %sext = add i64 %22, 4294967296
  %23 = ashr exact i64 %sext, 32
  %24 = tail call ptr @FerMem_Malloc(i64 noundef %23, ptr noundef nonnull @.str, i32 noundef 68) #4
  store ptr %24, ptr %2, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %20
  tail call void @abort() #6
  unreachable

27:                                               ; preds = %20
  %28 = load ptr, ptr %0, align 8, !tbaa !5
  %.not41 = icmp eq ptr %28, null
  %29 = load ptr, ptr @STRING_MISSING_VALUE, align 8
  %.not42 = icmp eq ptr %28, %29
  %or.cond51 = select i1 %.not41, i1 true, i1 %.not42
  br i1 %or.cond51, label %.loopexit54, label %.preheader53

.preheader53:                                     ; preds = %27
  %30 = load i8, ptr %28, align 1, !tbaa !9
  %.not4355 = icmp eq i8 %30, 0
  br i1 %.not4355, label %.loopexit54, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader53, %.lr.ph
  %31 = phi i8 [ %34, %.lr.ph ], [ %30, %.preheader53 ]
  %.03157 = phi ptr [ %33, %.lr.ph ], [ %24, %.preheader53 ]
  %.03256 = phi ptr [ %32, %.lr.ph ], [ %28, %.preheader53 ]
  store i8 %31, ptr %.03157, align 1, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %.03256, i64 1
  %33 = getelementptr inbounds i8, ptr %.03157, i64 1
  %34 = load i8, ptr %32, align 1, !tbaa !9
  %.not43 = icmp eq i8 %34, 0
  br i1 %.not43, label %.loopexit54.loopexit, label %.lr.ph, !llvm.loop !10

.loopexit54.loopexit:                             ; preds = %.lr.ph
  %.pre64 = load ptr, ptr @STRING_MISSING_VALUE, align 8
  br label %.loopexit54

.loopexit54:                                      ; preds = %.loopexit54.loopexit, %.preheader53, %27
  %35 = phi ptr [ %29, %27 ], [ %29, %.preheader53 ], [ %.pre64, %.loopexit54.loopexit ]
  %.1 = phi ptr [ %24, %27 ], [ %24, %.preheader53 ], [ %33, %.loopexit54.loopexit ]
  %36 = load ptr, ptr %1, align 8, !tbaa !5
  %.not44 = icmp eq ptr %36, null
  %.not45 = icmp eq ptr %36, %35
  %or.cond52 = select i1 %.not44, i1 true, i1 %.not45
  br i1 %or.cond52, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.loopexit54
  %37 = load i8, ptr %36, align 1, !tbaa !9
  %.not4658 = icmp eq i8 %37, 0
  br i1 %.not4658, label %.loopexit, label %.lr.ph61

.lr.ph61:                                         ; preds = %.preheader, %.lr.ph61
  %38 = phi i8 [ %41, %.lr.ph61 ], [ %37, %.preheader ]
  %.260 = phi ptr [ %40, %.lr.ph61 ], [ %.1, %.preheader ]
  %.13359 = phi ptr [ %39, %.lr.ph61 ], [ %36, %.preheader ]
  store i8 %38, ptr %.260, align 1, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %.13359, i64 1
  %40 = getelementptr inbounds i8, ptr %.260, i64 1
  %41 = load i8, ptr %39, align 1, !tbaa !9
  %.not46 = icmp eq i8 %41, 0
  br i1 %.not46, label %.loopexit, label %.lr.ph61, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph61, %.preheader, %.loopexit54
  %.3 = phi ptr [ %.1, %.loopexit54 ], [ %.1, %.preheader ], [ %40, %.lr.ph61 ]
  store i8 0, ptr %.3, align 1, !tbaa !9
  ret void
}

declare void @FerMem_Free(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

declare ptr @FerMem_Malloc(i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #3

attributes #0 = { 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 #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 = { 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 #3 = { noreturn 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 }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { noreturn 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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