; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (1408)

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @contains(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %49, %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %50

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %14, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %15, ptr %7, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %43, %13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = sext i8 %18 to i32
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %36

21:                                               ; preds = %16
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = sext i8 %23 to i32
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %36

26:                                               ; preds = %21
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr %6, align 8, !tbaa !5
  %29 = load i8, ptr %27, align 1, !tbaa !9
  %30 = sext i8 %29 to i32
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i32 1
  store ptr %32, ptr %7, align 8, !tbaa !5
  %33 = load i8, ptr %31, align 1, !tbaa !9
  %34 = sext i8 %33 to i32
  %35 = icmp eq i32 %30, %34
  br label %36

36:                                               ; preds = %26, %21, %16
  %37 = phi i1 [ false, %21 ], [ false, %16 ], [ %35, %26 ]
  br i1 %37, label %38, label %44

38:                                               ; preds = %36
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = icmp ne i8 %40, 0
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %47

43:                                               ; preds = %38
  br label %16, !llvm.loop !10

44:                                               ; preds = %36
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i32 1
  store ptr %46, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %8, align 4
  br label %47

47:                                               ; preds = %44, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %48 = load i32, ptr %8, align 4
  switch i32 %48, label %53 [
    i32 0, label %49
    i32 1, label %51
  ]

49:                                               ; preds = %47
  br label %9, !llvm.loop !12

50:                                               ; preds = %9
  store i1 false, ptr %3, align 1
  br label %51

51:                                               ; preds = %50, %47
  %52 = load i1, ptr %3, align 1
  ret i1 %52

53:                                               ; preds = %47
  unreachable
}

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


; 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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @contains(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %0, align 1, !tbaa !5
  %.not28.not = icmp eq i8 %3, 0
  br i1 %.not28.not, label %.thread, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %.pre.pre = load i8, ptr %1, align 1, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %13
  %4 = phi i8 [ %15, %13 ], [ %3, %.preheader.preheader ]
  %.01329 = phi ptr [ %14, %13 ], [ %0, %.preheader.preheader ]
  br label %6

thread-pre-split:                                 ; preds = %10
  %5 = getelementptr inbounds i8, ptr %.01126, i64 1
  %.pr = load i8, ptr %5, align 1, !tbaa !5
  %.not17 = icmp eq i8 %.pr, 0
  br i1 %.not17, label %13, label %6

6:                                                ; preds = %.preheader, %thread-pre-split
  %7 = phi i8 [ %.pre.pre, %.preheader ], [ %12, %thread-pre-split ]
  %.01027 = phi ptr [ %1, %.preheader ], [ %11, %thread-pre-split ]
  %.01126 = phi ptr [ %.01329, %.preheader ], [ %5, %thread-pre-split ]
  %8 = phi i8 [ %4, %.preheader ], [ %.pr, %thread-pre-split ]
  %9 = icmp eq i8 %8, %7
  br i1 %9, label %10, label %13

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %.01027, i64 1
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %.not19 = icmp eq i8 %12, 0
  br i1 %.not19, label %.thread, label %thread-pre-split, !llvm.loop !8

13:                                               ; preds = %thread-pre-split, %6
  %14 = getelementptr inbounds i8, ptr %.01329, i64 1
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %.not.not = icmp eq i8 %15, 0
  br i1 %.not.not, label %.thread, label %.preheader

.thread:                                          ; preds = %13, %10, %2
  %.not25 = phi i1 [ false, %2 ], [ true, %10 ], [ false, %13 ]
  ret i1 %.not25
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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"}


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