; LLVM IR from mirohs/gc :: util (index_of)

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

%struct.String = type { ptr, i32, i32 }

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strstr(ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @index_of(ptr %0, i64 %1, ptr %2, i64 %3) #4 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.String, align 8
  %7 = alloca %struct.String, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  store ptr %0, ptr %13, align 8
  %14 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  store i64 %1, ptr %14, align 8
  %15 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 0
  store ptr %2, ptr %15, align 8
  %16 = getelementptr inbounds { ptr, i64 }, ptr %7, i32 0, i32 1
  store i64 %3, ptr %16, align 8
  %17 = getelementptr inbounds %struct.String, ptr %6, i32 0, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.String, ptr %7, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !5
  %21 = icmp slt i32 %18, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  br label %65

23:                                               ; preds = %4
  %24 = getelementptr inbounds %struct.String, ptr %6, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = zext i32 %26 to i64
  %28 = call ptr @llvm.stacksave.p0()
  store ptr %28, ptr %8, align 8
  %29 = alloca i8, i64 %27, align 16
  store i64 %27, ptr %9, align 8
  %30 = getelementptr inbounds %struct.String, ptr %7, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !5
  %32 = add nsw i32 %31, 1
  %33 = zext i32 %32 to i64
  %34 = alloca i8, i64 %33, align 16
  store i64 %33, ptr %10, align 8
  %35 = getelementptr inbounds %struct.String, ptr %6, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = getelementptr inbounds %struct.String, ptr %6, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !5
  %39 = sext i32 %38 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %29, ptr align 1 %36, i64 %39, i1 false)
  %40 = getelementptr inbounds %struct.String, ptr %7, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.String, ptr %7, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !5
  %44 = sext i32 %43 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %34, ptr align 1 %41, i64 %44, i1 false)
  %45 = getelementptr inbounds %struct.String, ptr %6, i32 0, i32 1
  %46 = load i32, ptr %45, align 8, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %29, i64 %47
  store i8 0, ptr %48, align 1, !tbaa !12
  %49 = getelementptr inbounds %struct.String, ptr %7, i32 0, i32 1
  %50 = load i32, ptr %49, align 8, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %34, i64 %51
  store i8 0, ptr %52, align 1, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %53 = call ptr @strstr(ptr noundef %29, ptr noundef %34) #6
  store ptr %53, ptr %11, align 8, !tbaa !13
  %54 = load ptr, ptr %11, align 8, !tbaa !13
  %55 = icmp eq ptr %54, null
  br i1 %55, label %56, label %57

56:                                               ; preds = %23
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %63

57:                                               ; preds = %23
  %58 = load ptr, ptr %11, align 8, !tbaa !13
  %59 = ptrtoint ptr %58 to i64
  %60 = ptrtoint ptr %29 to i64
  %61 = sub i64 %59, %60
  %62 = trunc i64 %61 to i32
  store i32 %62, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %63

63:                                               ; preds = %57, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  %64 = load ptr, ptr %8, align 8
  call void @llvm.stackrestore.p0(ptr %64)
  br label %65

65:                                               ; preds = %63, %22
  %66 = load i32, ptr %5, align 4
  ret i32 %66
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 #4 = { 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 #5 = { nounwind }
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, !10, i64 8}
!6 = !{!"String", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!7, !7, i64 0}


; 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

; Function Attrs: mustprogress nofree nounwind willreturn uwtable
define dso_local i32 @index_of(ptr nocapture readonly %0, i64 %1, ptr nocapture readonly %2, i64 %3) local_unnamed_addr #3 {
  %.sroa.27.8.extract.trunc = trunc i64 %1 to i32
  %.sroa.2.8.extract.trunc = trunc i64 %3 to i32
  %5 = icmp slt i32 %.sroa.27.8.extract.trunc, %.sroa.2.8.extract.trunc
  br i1 %5, label %24, label %6

6:                                                ; preds = %4
  %7 = add i64 %1, 1
  %8 = and i64 %7, 4294967295
  %9 = tail call ptr @llvm.stacksave.p0()
  %10 = alloca i8, i64 %8, align 16
  %11 = add i64 %3, 1
  %12 = and i64 %11, 4294967295
  %13 = alloca i8, i64 %12, align 16
  %sext = shl i64 %1, 32
  %14 = ashr exact i64 %sext, 32
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %10, ptr align 1 %0, i64 %14, i1 false)
  %sext13 = shl i64 %3, 32
  %15 = ashr exact i64 %sext13, 32
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %13, ptr align 1 %2, i64 %15, i1 false)
  %16 = getelementptr inbounds i8, ptr %10, i64 %14
  store i8 0, ptr %16, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %13, i64 %15
  store i8 0, ptr %17, align 1, !tbaa !5
  %18 = call ptr @strstr(ptr noundef nonnull dereferenceable(1) %10, ptr noundef nonnull dereferenceable(1) %13) #4
  %19 = icmp eq ptr %18, null
  %20 = ptrtoint ptr %18 to i64
  %21 = ptrtoint ptr %10 to i64
  %22 = sub i64 %20, %21
  %23 = trunc i64 %22 to i32
  %.0 = select i1 %19, i32 -1, i32 %23
  call void @llvm.stackrestore.p0(ptr %9)
  br label %24

24:                                               ; preds = %4, %6
  %.1 = phi i32 [ %.0, %6 ], [ -1, %4 ]
  ret i32 %.1
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #2 = { 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 #3 = { mustprogress nofree nounwind willreturn 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 = { 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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass