; LLVM IR from facebook/redex :: libresource (Unicode)

; 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: mustprogress nounwind uwtable
declare dso_local i32 @strncmp16(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i64 @strlen16(ptr noundef) #1

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

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %15, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %48

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds i16, ptr %17, i32 1
  store ptr %18, ptr %5, align 8, !tbaa !5
  %19 = call i64 @strlen16(ptr noundef %18)
  store i64 %19, ptr %8, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %37, %16
  br label %21

21:                                               ; preds = %28, %20
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i16, ptr %22, align 2, !tbaa !9
  %24 = zext i16 %23 to i32
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %47

27:                                               ; preds = %21
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds i16, ptr %29, i32 1
  store ptr %30, ptr %4, align 8, !tbaa !5
  %31 = load i16, ptr %29, align 2, !tbaa !9
  %32 = zext i16 %31 to i32
  %33 = load i16, ptr %6, align 2, !tbaa !9
  %34 = zext i16 %33 to i32
  %35 = icmp ne i32 %32, %34
  br i1 %35, label %21, label %36, !llvm.loop !13

36:                                               ; preds = %28
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %8, align 8, !tbaa !11
  %41 = call i32 @strncmp16(ptr noundef %38, ptr noundef %39, i64 noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %20, label %43, !llvm.loop !15

43:                                               ; preds = %37
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds i16, ptr %44, i32 -1
  store ptr %45, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %46, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %47

47:                                               ; preds = %43, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %48

48:                                               ; preds = %47, %14
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  %49 = load ptr, ptr %3, align 8
  ret ptr %49
}

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


; 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: mustprogress nounwind uwtable
declare dso_local i32 @strncmp16(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i64 @strlen16(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @strstr16(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i16, ptr %1, align 2, !tbaa !5
  %4 = icmp eq i16 %3, 0
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 2
  %7 = tail call i64 @strlen16(ptr noundef nonnull %6)
  br label %8

8:                                                ; preds = %.backedge, %5
  %.113 = phi ptr [ %0, %5 ], [ %12, %.backedge ]
  %9 = load i16, ptr %.113, align 2, !tbaa !5
  %10 = icmp eq i16 %9, 0
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %.113, i64 2
  %.not = icmp eq i16 %9, %3
  br i1 %.not, label %13, label %.backedge

.backedge:                                        ; preds = %11, %13
  br label %8, !llvm.loop !9

13:                                               ; preds = %11
  %14 = tail call i32 @strncmp16(ptr noundef nonnull %12, ptr noundef nonnull %6, i64 noundef %7)
  %.not16 = icmp eq i32 %14, 0
  br i1 %.not16, label %.loopexit, label %.backedge

.loopexit:                                        ; preds = %13, %8, %2
  %.1 = phi ptr [ %0, %2 ], [ %.113, %13 ], [ null, %8 ]
  ret ptr %.1
}

attributes #0 = { mustprogress 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 = !{!"char16_t", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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