; LLVM IR from nde-jesu/Doom_Nukem :: libft/srcs/control (ft_strnstr)

; 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
define dso_local ptr @ft_strnstr(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 -1, ptr %8, align 8, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = call i64 @ft_strlen(ptr noundef %12)
  store i64 %13, ptr %10, align 8, !tbaa !9
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %17, label %15

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %16, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %69

17:                                               ; preds = %3
  br label %18

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

26:                                               ; preds = %18
  %27 = load i64, ptr %8, align 8, !tbaa !9
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = icmp ult i64 %27, %28
  br label %30

30:                                               ; preds = %26, %18
  %31 = phi i1 [ false, %18 ], [ %29, %26 ]
  br i1 %31, label %32, label %68

32:                                               ; preds = %30
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %64, %32
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %34, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = add i64 %40, %41
  %43 = getelementptr inbounds i8, ptr %39, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = sext i8 %44 to i32
  %46 = icmp eq i32 %38, %45
  br i1 %46, label %47, label %53

47:                                               ; preds = %33
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = add i64 %48, %49
  %51 = load i64, ptr %7, align 8, !tbaa !9
  %52 = icmp ult i64 %50, %51
  br label %53

53:                                               ; preds = %47, %33
  %54 = phi i1 [ false, %33 ], [ %52, %47 ]
  br i1 %54, label %55, label %67

55:                                               ; preds = %53
  %56 = load i64, ptr %9, align 8, !tbaa !9
  %57 = load i64, ptr %10, align 8, !tbaa !9
  %58 = sub i64 %57, 1
  %59 = icmp eq i64 %56, %58
  br i1 %59, label %60, label %64

60:                                               ; preds = %55
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load i64, ptr %8, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %61, i64 %62
  store ptr %63, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %69

64:                                               ; preds = %55
  %65 = load i64, ptr %9, align 8, !tbaa !9
  %66 = add i64 %65, 1
  store i64 %66, ptr %9, align 8, !tbaa !9
  br label %33, !llvm.loop !12

67:                                               ; preds = %53
  br label %18, !llvm.loop !14

68:                                               ; preds = %30
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %69

69:                                               ; preds = %68, %60, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %70 = load ptr, ptr %4, align 8
  ret ptr %70
}

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

declare i64 @ft_strlen(ptr noundef) #2

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

!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 = !{!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
define dso_local ptr @ft_strnstr(ptr noundef readonly %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i64 @ft_strlen(ptr noundef %1) #2
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %.loopexit23, label %.critedge.preheader

.critedge.preheader:                              ; preds = %3
  %5 = load i8, ptr %0, align 1, !tbaa !5
  %6 = icmp ne i8 %5, 0
  %7 = icmp ne i64 %2, 0
  %8 = and i1 %6, %7
  br i1 %8, label %.preheader.lr.ph, label %.loopexit23

.preheader.lr.ph:                                 ; preds = %.critedge.preheader
  %9 = load i8, ptr %1, align 1, !tbaa !5
  %10 = add i64 %4, -1
  br label %.preheader

.critedge.loopexit:                               ; preds = %20, %.preheader
  %11 = add nuw i64 %18, 1
  %12 = getelementptr inbounds i8, ptr %0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = icmp ne i8 %13, 0
  %15 = icmp ult i64 %11, %2
  %16 = and i1 %14, %15
  br i1 %16, label %.preheader, label %.loopexit23, !llvm.loop !8

.preheader:                                       ; preds = %.preheader.lr.ph, %.critedge.loopexit
  %17 = phi i8 [ %5, %.preheader.lr.ph ], [ %13, %.critedge.loopexit ]
  %18 = phi i64 [ 0, %.preheader.lr.ph ], [ %11, %.critedge.loopexit ]
  %19 = icmp eq i8 %9, %17
  br i1 %19, label %.lr.ph, label %.critedge.loopexit

20:                                               ; preds = %.lr.ph
  %21 = add nuw i64 %.01925, 1
  %22 = getelementptr inbounds i8, ptr %1, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = add nuw i64 %21, %18
  %25 = getelementptr inbounds i8, ptr %0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = icmp eq i8 %23, %26
  %28 = icmp ult i64 %24, %2
  %or.cond = and i1 %28, %27
  br i1 %or.cond, label %.lr.ph, label %.critedge.loopexit, !llvm.loop !10

.lr.ph:                                           ; preds = %.preheader, %20
  %.01925 = phi i64 [ %21, %20 ], [ 0, %.preheader ]
  %29 = icmp eq i64 %.01925, %10
  br i1 %29, label %.loopexit23.loopexit, label %20

.loopexit23.loopexit:                             ; preds = %.lr.ph
  %30 = getelementptr inbounds i8, ptr %0, i64 %18
  br label %.loopexit23

.loopexit23:                                      ; preds = %.critedge.loopexit, %.loopexit23.loopexit, %.critedge.preheader, %3
  %.0 = phi ptr [ %0, %3 ], [ null, %.critedge.preheader ], [ %30, %.loopexit23.loopexit ], [ null, %.critedge.loopexit ]
  ret ptr %.0
}

declare i64 @ft_strlen(ptr noundef) local_unnamed_addr #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 = { "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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


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