; LLVM IR from Zhuagenborn/Tiny-x86-OS :: src/kernel/stl/cstring.ll (ZN3stl6memcmpEPKvS1_j)

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

%"class.stl::source_location" = type { ptr, ptr, i32, i32 }
%"class.stl::string_view" = type <{ ptr, i32, [4 x i8] }>

@.str = external hidden unnamed_addr constant [84 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind
declare void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext, ptr, i32, ptr noundef nonnull align 8 dereferenceable(24)) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind noalias writable sret(%"class.stl::source_location") align 8, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3stl6memcmpEPKvS1_j(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %"class.stl::string_view", align 8
  %9 = alloca %"class.stl::source_location", align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %19

16:                                               ; preds = %3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br label %19

19:                                               ; preds = %16, %3
  %20 = phi i1 [ false, %3 ], [ %18, %16 ]
  call void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12) %8, ptr noundef null) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #3
  call void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind writable sret(%"class.stl::source_location") align 8 %9, ptr noundef @.str, ptr noundef @.str.6, i32 noundef 54, i32 noundef 0) #3
  %21 = getelementptr inbounds { ptr, i32 }, ptr %8, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8
  %23 = getelementptr inbounds { ptr, i32 }, ptr %8, i32 0, i32 1
  %24 = load i32, ptr %23, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %20, ptr %22, i32 %24, ptr noundef nonnull align 8 dereferenceable(24) %9) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %58, %19
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = icmp ne i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 2, ptr %11, align 4
  br label %61

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11
  store i8 %35, ptr %12, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #3
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11
  store i8 %40, ptr %13, align 1, !tbaa !11
  %41 = load i8, ptr %12, align 1, !tbaa !11
  %42 = zext i8 %41 to i32
  %43 = load i8, ptr %13, align 1, !tbaa !11
  %44 = zext i8 %43 to i32
  %45 = icmp ne i32 %42, %44
  br i1 %45, label %46, label %54

46:                                               ; preds = %30
  %47 = load i8, ptr %12, align 1, !tbaa !11
  %48 = zext i8 %47 to i32
  %49 = load i8, ptr %13, align 1, !tbaa !11
  %50 = zext i8 %49 to i32
  %51 = icmp sgt i32 %48, %50
  %52 = zext i1 %51 to i64
  %53 = select i1 %51, i32 1, i32 -1
  store i32 %53, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %55

54:                                               ; preds = %30
  store i32 0, ptr %11, align 4
  br label %55

55:                                               ; preds = %54, %46
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  %56 = load i32, ptr %11, align 4
  switch i32 %56, label %61 [
    i32 0, label %57
  ]

57:                                               ; preds = %55
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = add i32 %59, 1
  store i32 %60, ptr %10, align 4, !tbaa !9
  br label %25, !llvm.loop !12

61:                                               ; preds = %55, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %62 = load i32, ptr %11, align 4
  switch i32 %62, label %66 [
    i32 2, label %63
    i32 1, label %64
  ]

63:                                               ; preds = %61
  store i32 0, ptr %4, align 4
  br label %64

64:                                               ; preds = %63, %61
  %65 = load i32, ptr %4, align 4
  ret i32 %65

66:                                               ; preds = %61
  unreachable
}

attributes #0 = { nounwind "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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !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"

%"class.stl::source_location" = type { ptr, ptr, i32, i32 }
%"class.stl::string_view" = type <{ ptr, i32, [4 x i8] }>

@.str = external hidden unnamed_addr constant [84 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind
declare void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext, ptr, i32, ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind noalias writable sret(%"class.stl::source_location") align 8, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3stl6memcmpEPKvS1_j(ptr noundef readonly %0, ptr noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %"class.stl::string_view", align 8
  %5 = alloca %"class.stl::source_location", align 8
  %6 = icmp ne ptr %0, null
  %7 = icmp ne ptr %1, null
  %8 = and i1 %6, %7
  call void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12) %4, ptr noundef null) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  call void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind nonnull writable sret(%"class.stl::source_location") align 8 %5, ptr noundef nonnull @.str, ptr noundef nonnull @.str.6, i32 noundef 54, i32 noundef 0) #3
  %9 = load ptr, ptr %4, align 8
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  %11 = load i32, ptr %10, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %8, ptr %9, i32 %11, ptr noundef nonnull align 8 dereferenceable(24) %5) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  %.not25 = icmp eq i32 %2, 0
  br i1 %.not25, label %.split.loop.exit, label %.lr.ph

12:                                               ; preds = %.lr.ph
  %13 = add nuw i32 %.01526, 1
  %.not = icmp eq i32 %13, %2
  br i1 %.not, label %.split.loop.exit, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %3, %12
  %.01526 = phi i32 [ %13, %12 ], [ 0, %3 ]
  %14 = zext i32 %.01526 to i64
  %15 = getelementptr inbounds i8, ptr %0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !7
  %17 = getelementptr inbounds i8, ptr %1, i64 %14
  %18 = load i8, ptr %17, align 1, !tbaa !7
  %.not20 = icmp eq i8 %16, %18
  br i1 %.not20, label %12, label %.split.loop.exit21

.split.loop.exit21:                               ; preds = %.lr.ph
  %19 = icmp ugt i8 %16, %18
  %20 = select i1 %19, i32 1, i32 -1
  br label %.split.loop.exit

.split.loop.exit:                                 ; preds = %12, %3, %.split.loop.exit21
  %spec.select = phi i32 [ %20, %.split.loop.exit21 ], [ 0, %3 ], [ 0, %12 ]
  ret i32 %spec.select
}

attributes #0 = { nounwind "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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}


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