; LLVM IR from wrnlb666/yet-another-string-library-in-c :: yasli (str_strcmp)

; 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_t = type { i64, i64, [1 x i8] }

; 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: nounwind uwtable
define dso_local i32 @str_strcmp(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = 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 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %52, %2
  %9 = load i64, ptr %6, align 8, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.string_t, ptr %10, i32 0, i32 0
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp ule i64 %9, %12
  br i1 %13, label %14, label %20

14:                                               ; preds = %8
  %15 = load i64, ptr %6, align 8, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.string_t, ptr %16, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = icmp ule i64 %15, %18
  br label %20

20:                                               ; preds = %14, %8
  %21 = phi i1 [ false, %8 ], [ %19, %14 ]
  br i1 %21, label %23, label %22

22:                                               ; preds = %20
  store i32 2, ptr %7, align 4
  br label %55

23:                                               ; preds = %20
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.string_t, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = getelementptr inbounds [1 x i8], ptr %25, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = sext i8 %28 to i32
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.string_t, ptr %30, i32 0, i32 2
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = getelementptr inbounds [1 x i8], ptr %31, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !13
  %35 = sext i8 %34 to i32
  %36 = icmp ne i32 %29, %35
  br i1 %36, label %37, label %51

37:                                               ; preds = %23
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.string_t, ptr %38, i32 0, i32 2
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = getelementptr inbounds [1 x i8], ptr %39, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = sext i8 %42 to i32
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.string_t, ptr %44, i32 0, i32 2
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = getelementptr inbounds [1 x i8], ptr %45, i64 0, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !13
  %49 = sext i8 %48 to i32
  %50 = sub nsw i32 %43, %49
  store i32 %50, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %55

51:                                               ; preds = %23
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = add i64 %53, 1
  store i64 %54, ptr %6, align 8, !tbaa !9
  br label %8, !llvm.loop !14

55:                                               ; preds = %37, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %56 = load i32, ptr %7, align 4
  switch i32 %56, label %60 [
    i32 2, label %57
    i32 1, label %58
  ]

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

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

60:                                               ; preds = %55
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"string_t", !10, i64 0, !10, i64 8, !7, i64 16}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i32 @str_strcmp(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i64, ptr %0, align 8, !tbaa !5
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  br label %9

7:                                                ; preds = %10
  %8 = add i64 %.01421, 1
  %.not = icmp ugt i64 %8, %3
  br i1 %.not, label %.critedge, label %9, !llvm.loop !10

9:                                                ; preds = %2, %7
  %.01421 = phi i64 [ 0, %2 ], [ %8, %7 ]
  %.not18 = icmp ugt i64 %.01421, %4
  br i1 %.not18, label %.critedge, label %10

10:                                               ; preds = %9
  %11 = getelementptr inbounds [1 x i8], ptr %5, i64 0, i64 %.01421
  %12 = load i8, ptr %11, align 1, !tbaa !12
  %13 = getelementptr inbounds [1 x i8], ptr %6, i64 0, i64 %.01421
  %14 = load i8, ptr %13, align 1, !tbaa !12
  %.not19 = icmp eq i8 %12, %14
  br i1 %.not19, label %7, label %15

15:                                               ; preds = %10
  %16 = sext i8 %14 to i32
  %17 = sext i8 %12 to i32
  %18 = sub nsw i32 %17, %16
  br label %.critedge

.critedge:                                        ; preds = %9, %7, %15
  %switch = phi i32 [ %18, %15 ], [ 0, %7 ], [ 0, %9 ]
  ret i32 %switch
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: 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" }

!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, !7, i64 0}
!6 = !{!"string_t", !7, i64 0, !7, i64 8, !8, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!8, !8, i64 0}


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