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

; 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.3 = 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 @_ZN3stl6strcmpEPKcS1_(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %"class.stl::string_view", align 8
  %7 = alloca %"class.stl::source_location", align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %13

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br label %13

13:                                               ; preds = %10, %2
  %14 = phi i1 [ false, %2 ], [ %12, %10 ]
  call void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12) %6, ptr noundef null) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #3
  call void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind writable sret(%"class.stl::source_location") align 8 %7, ptr noundef @.str, ptr noundef @.str.3, i32 noundef 26, i32 noundef 0) #3
  %15 = getelementptr inbounds { ptr, i32 }, ptr %6, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8
  %17 = getelementptr inbounds { ptr, i32 }, ptr %6, i32 0, i32 1
  %18 = load i32, ptr %17, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %14, ptr %16, i32 %18, ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #3
  br label %19

19:                                               ; preds = %34, %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %32

24:                                               ; preds = %19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = sext i8 %29 to i32
  %31 = icmp eq i32 %27, %30
  br label %32

32:                                               ; preds = %24, %19
  %33 = phi i1 [ false, %19 ], [ %31, %24 ]
  br i1 %33, label %34, label %39

34:                                               ; preds = %32
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i32 1
  store ptr %36, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 1
  store ptr %38, ptr %5, align 8, !tbaa !5
  br label %19, !llvm.loop !10

39:                                               ; preds = %32
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !9
  %42 = sext i8 %41 to i32
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = sext i8 %44 to i32
  %46 = icmp ne i32 %42, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %39
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i8, ptr %48, align 1, !tbaa !9
  %50 = sext i8 %49 to i32
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = load i8, ptr %51, align 1, !tbaa !9
  %53 = sext i8 %52 to i32
  %54 = icmp sgt i32 %50, %53
  %55 = zext i1 %54 to i64
  %56 = select i1 %54, i32 1, i32 -1
  store i32 %56, ptr %3, align 4
  br label %58

57:                                               ; preds = %39
  store i32 0, ptr %3, align 4
  br label %58

58:                                               ; preds = %57, %47
  %59 = load i32, ptr %3, align 4
  ret i32 %59
}

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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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.3 = 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 range(i32 -1, 2) i32 @_ZN3stl6strcmpEPKcS1_(ptr noundef readonly %0, ptr noundef readonly %1) local_unnamed_addr #1 {
  %3 = alloca %"class.stl::string_view", align 8
  %4 = alloca %"class.stl::source_location", align 8
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %1, null
  %7 = and i1 %5, %6
  call void @_ZN3stl11string_viewC2EPKc(ptr noundef nonnull align 8 dereferenceable(12) %3, ptr noundef null) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  call void @_ZN3stl15source_location7currentEPKcS2_jj(ptr dead_on_unwind nonnull writable sret(%"class.stl::source_location") align 8 %4, ptr noundef nonnull @.str, ptr noundef nonnull @.str.3, i32 noundef 26, i32 noundef 0) #3
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  %10 = load i32, ptr %9, align 8
  call void @_ZN3dbg6AssertEbN3stl11string_viewERKNS0_15source_locationE(i1 noundef zeroext %7, ptr %8, i32 %10, ptr noundef nonnull align 8 dereferenceable(24) %4) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  %11 = load i8, ptr %0, align 1, !tbaa !5
  %.not17 = icmp eq i8 %11, 0
  br i1 %.not17, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %15
  %12 = phi i8 [ %18, %15 ], [ %11, %2 ]
  %.019 = phi ptr [ %17, %15 ], [ %1, %2 ]
  %.01118 = phi ptr [ %16, %15 ], [ %0, %2 ]
  %13 = load i8, ptr %.019, align 1, !tbaa !5
  %14 = icmp eq i8 %12, %13
  br i1 %14, label %15, label %.critedge

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %.01118, i64 1
  %17 = getelementptr inbounds i8, ptr %.019, i64 1
  %18 = load i8, ptr %16, align 1, !tbaa !5
  %.not = icmp eq i8 %18, 0
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !8

.critedge:                                        ; preds = %.lr.ph, %15, %2
  %.0.lcssa = phi ptr [ %1, %2 ], [ %17, %15 ], [ %.019, %.lr.ph ]
  %.lcssa = phi i8 [ 0, %2 ], [ 0, %15 ], [ %12, %.lr.ph ]
  %19 = load i8, ptr %.0.lcssa, align 1, !tbaa !5
  %.not16 = icmp eq i8 %.lcssa, %19
  %20 = icmp sgt i8 %.lcssa, %19
  %21 = select i1 %20, i32 1, i32 -1
  %.012 = select i1 %.not16, i32 0, i32 %21
  ret i32 %.012
}

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 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple 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