; LLVM IR from 0intro/wmii :: lib/libstuff/util (strcasestr)

; 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 @stuff_strcasestr(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  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 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 0
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %24

20:                                               ; preds = %2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = ptrtoint ptr %21 to i64
  %23 = inttoptr i64 %22 to ptr
  store ptr %23, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %96

24:                                               ; preds = %2
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call i64 @strlen(ptr noundef %25) #7
  %27 = sub i64 %26, 1
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %29 = call ptr @__ctype_tolower_loc() #8
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 0
  %33 = load i8, ptr %32, align 1, !tbaa !9
  %34 = sext i8 %33 to i32
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %30, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !10
  store i32 %37, ptr %10, align 4, !tbaa !10
  %38 = load i32, ptr %10, align 4, !tbaa !10
  store i32 %38, ptr %11, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  %39 = load i32, ptr %11, align 4, !tbaa !10
  store i32 %39, ptr %8, align 4, !tbaa !10
  br label %40

40:                                               ; preds = %92, %24
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  store i32 %43, ptr %7, align 4, !tbaa !10
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %95

45:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %46 = load i32, ptr %7, align 4, !tbaa !10
  %47 = call i1 @llvm.is.constant.i32(i32 %46)
  br i1 %47, label %48, label %66

48:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  %49 = load i32, ptr %7, align 4, !tbaa !10
  store i32 %49, ptr %13, align 4, !tbaa !10
  %50 = load i32, ptr %13, align 4, !tbaa !10
  %51 = icmp slt i32 %50, -128
  br i1 %51, label %55, label %52

52:                                               ; preds = %48
  %53 = load i32, ptr %13, align 4, !tbaa !10
  %54 = icmp sgt i32 %53, 255
  br i1 %54, label %55, label %57

55:                                               ; preds = %52, %48
  %56 = load i32, ptr %13, align 4, !tbaa !10
  br label %64

57:                                               ; preds = %52
  %58 = call ptr @__ctype_tolower_loc() #8
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = load i32, ptr %13, align 4, !tbaa !10
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %59, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !10
  br label %64

64:                                               ; preds = %57, %55
  %65 = phi i32 [ %56, %55 ], [ %63, %57 ]
  store i32 %65, ptr %12, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  br label %69

66:                                               ; preds = %45
  %67 = load i32, ptr %7, align 4, !tbaa !10
  %68 = call i32 @tolower(i32 noundef %67) #7
  store i32 %68, ptr %12, align 4, !tbaa !10
  br label %69

69:                                               ; preds = %66, %64
  %70 = load i32, ptr %12, align 4, !tbaa !10
  store i32 %70, ptr %14, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  %71 = load i32, ptr %14, align 4, !tbaa !10
  store i32 %71, ptr %7, align 4, !tbaa !10
  %72 = load i32, ptr %8, align 4, !tbaa !10
  %73 = load i32, ptr %7, align 4, !tbaa !10
  %74 = icmp eq i32 %72, %73
  br i1 %74, label %75, label %91

75:                                               ; preds = %69
  %76 = load i32, ptr %6, align 4, !tbaa !10
  %77 = icmp eq i32 %76, 0
  br i1 %77, label %87, label %78

78:                                               ; preds = %75
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds i8, ptr %79, i64 1
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %81, i64 1
  %83 = load i32, ptr %6, align 4, !tbaa !10
  %84 = sext i32 %83 to i64
  %85 = call i32 @strncasecmp(ptr noundef %80, ptr noundef %82, i64 noundef %84) #7
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %91, label %87

87:                                               ; preds = %78, %75
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = ptrtoint ptr %88 to i64
  %90 = inttoptr i64 %89 to ptr
  store ptr %90, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %96

91:                                               ; preds = %78, %69
  br label %92

92:                                               ; preds = %91
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds i8, ptr %93, i32 1
  store ptr %94, ptr %4, align 8, !tbaa !5
  br label %40, !llvm.loop !12

95:                                               ; preds = %40
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %96

96:                                               ; preds = %95, %87, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %97 = load ptr, ptr %3, align 8
  ret ptr %97
}

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

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_tolower_loc() #3

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

; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)
declare i1 @llvm.is.constant.i32(i32) #4

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @tolower(i32 noundef) #5

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncasecmp(ptr noundef, ptr noundef, i64 noundef) #2

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 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 #3 = { nounwind willreturn memory(none) "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 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
attributes #5 = { inlinehint nounwind willreturn memory(read) 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { nounwind willreturn memory(none) }

!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 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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 nounwind memory(read) uwtable
define dso_local noundef ptr @stuff_strcasestr(ptr noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i8, ptr %1, align 1, !tbaa !5
  %4 = icmp eq i8 %3, 0
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = tail call ptr @__ctype_tolower_loc() #5
  %7 = load ptr, ptr %6, align 8, !tbaa !8
  %8 = sext i8 %3 to i64
  %9 = getelementptr inbounds i32, ptr %7, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !10
  %11 = load i8, ptr %0, align 1, !tbaa !5
  %.not31 = icmp eq i8 %11, 0
  br i1 %.not31, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %12 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #6
  %13 = trunc i64 %12 to i32
  %14 = add i32 %13, -1
  %15 = icmp eq i32 %14, 0
  %16 = getelementptr inbounds i8, ptr %1, i64 1
  %17 = sext i32 %14 to i64
  br label %18

18:                                               ; preds = %.lr.ph, %27
  %19 = phi i8 [ %11, %.lr.ph ], [ %29, %27 ]
  %.02532 = phi ptr [ %0, %.lr.ph ], [ %28, %27 ]
  %20 = sext i8 %19 to i32
  %21 = tail call i32 @tolower(i32 noundef %20) #6
  %22 = icmp eq i32 %10, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %18
  br i1 %15, label %.loopexit, label %24

24:                                               ; preds = %23
  %25 = getelementptr inbounds i8, ptr %.02532, i64 1
  %26 = tail call i32 @strncasecmp(ptr noundef nonnull %25, ptr noundef nonnull %16, i64 noundef %17) #6
  %.not30 = icmp eq i32 %26, 0
  br i1 %.not30, label %.loopexit, label %27

27:                                               ; preds = %18, %24
  %28 = getelementptr inbounds i8, ptr %.02532, i64 1
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %.not = icmp eq i8 %29, 0
  br i1 %.not, label %.loopexit, label %18, !llvm.loop !12

.loopexit:                                        ; preds = %24, %23, %27, %5, %2
  %.0 = phi ptr [ %0, %2 ], [ null, %5 ], [ %.02532, %24 ], [ %.02532, %23 ], [ null, %27 ]
  ret ptr %.0
}

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_tolower_loc() local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @tolower(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @strncasecmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #4

attributes #0 = { nofree nounwind memory(read) 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 = { 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 #2 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #4 = { mustprogress nofree 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 #5 = { nounwind willreturn memory(none) }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerConstantIntrinsicsPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass