; LLVM IR from rociodellasala/TP3_SO :: Kernel (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"

; Function Attrs: nounwind uwtable
declare dso_local i32 @strlen(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @strcat(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i32 @strlen(ptr noundef %9)
  store i32 %10, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call i32 @strlen(ptr noundef %11)
  store i32 %12, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %27, %2
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %30

17:                                               ; preds = %13
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %18, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %17
  br label %30

26:                                               ; preds = %17
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %5, align 4, !tbaa !9
  br label %13, !llvm.loop !12

30:                                               ; preds = %25, %13
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %47, %30
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %50

35:                                               ; preds = %31
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  store i8 %40, ptr %44, align 1, !tbaa !11
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %35
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !9
  br label %31, !llvm.loop !14

50:                                               ; preds = %31
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  store i8 0, ptr %54, align 1, !tbaa !11
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret ptr %55
}

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 = { 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"

; Function Attrs: nounwind uwtable
declare dso_local i32 @strlen(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @strcat(ptr noundef returned %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = ptrtoint ptr %1 to i64
  %4 = ptrtoint ptr %0 to i64
  %5 = tail call i32 @strlen(ptr noundef %0)
  %6 = tail call i32 @strlen(ptr noundef %1)
  %7 = icmp sgt i32 %5, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %5 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %11
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %11 ]
  %8 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %._crit_edge.loopexit.split.loop.exit, label %11

11:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge.loopexit.split.loop.exit:             ; preds = %.lr.ph
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %11, %._crit_edge.loopexit.split.loop.exit, %2
  %.0.lcssa = phi i32 [ 0, %2 ], [ %12, %._crit_edge.loopexit.split.loop.exit ], [ %5, %11 ]
  %13 = icmp sgt i32 %6, 0
  br i1 %13, label %.lr.ph24.preheader, label %._crit_edge25

.lr.ph24.preheader:                               ; preds = %._crit_edge
  %14 = zext i32 %.0.lcssa to i64
  %wide.trip.count35 = zext nneg i32 %6 to i64
  %min.iters.check = icmp ult i32 %6, 32
  br i1 %min.iters.check, label %.lr.ph24.preheader42, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph24.preheader
  %15 = add i64 %4, %14
  %16 = sub i64 %15, %3
  %diff.check = icmp ult i64 %16, 32
  br i1 %diff.check, label %.lr.ph24.preheader42, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count35, 2147483616
  %ind.end = add nuw nsw i64 %n.vec, %14
  %invariant.gep = getelementptr i8, ptr %0, i64 %14
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %17 = getelementptr inbounds i8, ptr %1, i64 %index
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %wide.load = load <16 x i8>, ptr %17, align 1, !tbaa !5
  %wide.load41 = load <16 x i8>, ptr %18, align 1, !tbaa !5
  %gep = getelementptr i8, ptr %invariant.gep, i64 %index
  %19 = getelementptr inbounds i8, ptr %gep, i64 16
  store <16 x i8> %wide.load, ptr %gep, align 1, !tbaa !5
  store <16 x i8> %wide.load41, ptr %19, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %20 = icmp eq i64 %index.next, %n.vec
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count35
  br i1 %cmp.n, label %._crit_edge25.loopexit, label %.lr.ph24.preheader42

.lr.ph24.preheader42:                             ; preds = %middle.block, %vector.memcheck, %.lr.ph24.preheader
  %indvars.iv30.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph24.preheader ], [ %n.vec, %middle.block ]
  %indvars.iv28.ph = phi i64 [ %14, %vector.memcheck ], [ %14, %.lr.ph24.preheader ], [ %ind.end, %middle.block ]
  %xtraiter = and i64 %wide.trip.count35, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph24.prol.loopexit, label %.lr.ph24.prol

.lr.ph24.prol:                                    ; preds = %.lr.ph24.preheader42, %.lr.ph24.prol
  %indvars.iv30.prol = phi i64 [ %indvars.iv.next31.prol, %.lr.ph24.prol ], [ %indvars.iv30.ph, %.lr.ph24.preheader42 ]
  %indvars.iv28.prol = phi i64 [ %indvars.iv.next29.prol, %.lr.ph24.prol ], [ %indvars.iv28.ph, %.lr.ph24.preheader42 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph24.prol ], [ 0, %.lr.ph24.preheader42 ]
  %21 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv30.prol
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv28.prol
  store i8 %22, ptr %23, align 1, !tbaa !5
  %indvars.iv.next29.prol = add nuw nsw i64 %indvars.iv28.prol, 1
  %indvars.iv.next31.prol = add nuw nsw i64 %indvars.iv30.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph24.prol.loopexit, label %.lr.ph24.prol, !llvm.loop !13

.lr.ph24.prol.loopexit:                           ; preds = %.lr.ph24.prol, %.lr.ph24.preheader42
  %indvars.iv.next29.lcssa43.unr = phi i64 [ poison, %.lr.ph24.preheader42 ], [ %indvars.iv.next29.prol, %.lr.ph24.prol ]
  %indvars.iv30.unr = phi i64 [ %indvars.iv30.ph, %.lr.ph24.preheader42 ], [ %indvars.iv.next31.prol, %.lr.ph24.prol ]
  %indvars.iv28.unr = phi i64 [ %indvars.iv28.ph, %.lr.ph24.preheader42 ], [ %indvars.iv.next29.prol, %.lr.ph24.prol ]
  %24 = sub nsw i64 %indvars.iv30.ph, %wide.trip.count35
  %25 = icmp ugt i64 %24, -4
  br i1 %25, label %._crit_edge25.loopexit, label %.lr.ph24.preheader42.new

.lr.ph24.preheader42.new:                         ; preds = %.lr.ph24.prol.loopexit
  %invariant.gep46 = getelementptr i8, ptr %1, i64 1
  %invariant.gep48 = getelementptr i8, ptr %0, i64 1
  %invariant.gep50 = getelementptr i8, ptr %1, i64 2
  %invariant.gep52 = getelementptr i8, ptr %0, i64 2
  %invariant.gep54 = getelementptr i8, ptr %1, i64 3
  %invariant.gep56 = getelementptr i8, ptr %0, i64 3
  br label %.lr.ph24

.lr.ph24:                                         ; preds = %.lr.ph24, %.lr.ph24.preheader42.new
  %indvars.iv30 = phi i64 [ %indvars.iv30.unr, %.lr.ph24.preheader42.new ], [ %indvars.iv.next31.3, %.lr.ph24 ]
  %indvars.iv28 = phi i64 [ %indvars.iv28.unr, %.lr.ph24.preheader42.new ], [ %indvars.iv.next29.3, %.lr.ph24 ]
  %26 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv30
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv28
  store i8 %27, ptr %28, align 1, !tbaa !5
  %gep47 = getelementptr i8, ptr %invariant.gep46, i64 %indvars.iv30
  %29 = load i8, ptr %gep47, align 1, !tbaa !5
  %gep49 = getelementptr i8, ptr %invariant.gep48, i64 %indvars.iv28
  store i8 %29, ptr %gep49, align 1, !tbaa !5
  %gep51 = getelementptr i8, ptr %invariant.gep50, i64 %indvars.iv30
  %30 = load i8, ptr %gep51, align 1, !tbaa !5
  %gep53 = getelementptr i8, ptr %invariant.gep52, i64 %indvars.iv28
  store i8 %30, ptr %gep53, align 1, !tbaa !5
  %gep55 = getelementptr i8, ptr %invariant.gep54, i64 %indvars.iv30
  %31 = load i8, ptr %gep55, align 1, !tbaa !5
  %gep57 = getelementptr i8, ptr %invariant.gep56, i64 %indvars.iv28
  store i8 %31, ptr %gep57, align 1, !tbaa !5
  %indvars.iv.next29.3 = add nuw nsw i64 %indvars.iv28, 4
  %indvars.iv.next31.3 = add nuw nsw i64 %indvars.iv30, 4
  %exitcond36.not.3 = icmp eq i64 %indvars.iv.next31.3, %wide.trip.count35
  br i1 %exitcond36.not.3, label %._crit_edge25.loopexit, label %.lr.ph24, !llvm.loop !15

._crit_edge25.loopexit:                           ; preds = %.lr.ph24.prol.loopexit, %.lr.ph24, %middle.block
  %indvars.iv.next29.lcssa = phi i64 [ %ind.end, %middle.block ], [ %indvars.iv.next29.lcssa43.unr, %.lr.ph24.prol.loopexit ], [ %indvars.iv.next29.3, %.lr.ph24 ]
  %32 = trunc nuw i64 %indvars.iv.next29.lcssa to i32
  br label %._crit_edge25

._crit_edge25:                                    ; preds = %._crit_edge25.loopexit, %._crit_edge
  %.1.lcssa = phi i32 [ %.0.lcssa, %._crit_edge ], [ %32, %._crit_edge25.loopexit ]
  %33 = zext nneg i32 %.1.lcssa to i64
  %34 = getelementptr inbounds i8, ptr %0, i64 %33
  store i8 0, ptr %34, align 1, !tbaa !5
  ret ptr %0
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9, !11, !12}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !9, !11}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass