; LLVM IR from Water-Melon/Melon :: src (mln_string)

; 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.mln_string_t = type { ptr, i64, 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: nounwind uwtable
define dso_local i32 @mln_string_strseqcmp(ptr noundef nonnull %0, ptr noundef nonnull %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %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 4, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.mln_string_t, ptr %8, i32 0, i32 1
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.mln_string_t, ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = icmp ugt i64 %10, %13
  br i1 %14, label %15, label %39

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.mln_string_t, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

21:                                               ; preds = %15
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mln_string_t, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mln_string_t, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mln_string_t, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = call i32 @memcmp(ptr noundef %24, ptr noundef %27, i64 noundef %30) #4
  store i32 %31, ptr %6, align 4, !tbaa !13
  %32 = load i32, ptr %6, align 4, !tbaa !13
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %21
  %35 = load i32, ptr %6, align 4, !tbaa !13
  br label %37

36:                                               ; preds = %21
  br label %37

37:                                               ; preds = %36, %34
  %38 = phi i32 [ %35, %34 ], [ 1, %36 ]
  store i32 %38, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

39:                                               ; preds = %2
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mln_string_t, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mln_string_t, ptr %43, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = icmp ult i64 %42, %45
  br i1 %46, label %47, label %71

47:                                               ; preds = %39
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mln_string_t, ptr %48, i32 0, i32 1
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = icmp eq i64 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %47
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

53:                                               ; preds = %47
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.mln_string_t, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !12
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.mln_string_t, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !12
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mln_string_t, ptr %60, i32 0, i32 1
  %62 = load i64, ptr %61, align 8, !tbaa !9
  %63 = call i32 @memcmp(ptr noundef %56, ptr noundef %59, i64 noundef %62) #4
  store i32 %63, ptr %6, align 4, !tbaa !13
  %64 = load i32, ptr %6, align 4, !tbaa !13
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %68

66:                                               ; preds = %53
  %67 = load i32, ptr %6, align 4, !tbaa !13
  br label %69

68:                                               ; preds = %53
  br label %69

69:                                               ; preds = %68, %66
  %70 = phi i32 [ %67, %66 ], [ -1, %68 ]
  store i32 %70, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

71:                                               ; preds = %39
  br label %72

72:                                               ; preds = %71
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.mln_string_t, ptr %73, i32 0, i32 1
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = icmp eq i64 %75, 0
  br i1 %76, label %77, label %78

77:                                               ; preds = %72
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

78:                                               ; preds = %72
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.mln_string_t, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !12
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.mln_string_t, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !12
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.mln_string_t, ptr %85, i32 0, i32 1
  %87 = load i64, ptr %86, align 8, !tbaa !9
  %88 = call i32 @memcmp(ptr noundef %81, ptr noundef %84, i64 noundef %87) #4
  store i32 %88, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %89

89:                                               ; preds = %78, %77, %69, %52, %37, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %90 = load i32, ptr %3, align 4
  ret i32 %90
}

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

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 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 }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 16, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !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 nofree nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @mln_string_strseqcmp(ptr nocapture noundef nonnull readonly %0, ptr nocapture noundef nonnull readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp ugt i64 %4, %6
  br i1 %7, label %8, label %15

8:                                                ; preds = %2
  %9 = icmp eq i64 %6, 0
  br i1 %9, label %29, label %10

10:                                               ; preds = %8
  %11 = load ptr, ptr %0, align 8, !tbaa !11
  %12 = load ptr, ptr %1, align 8, !tbaa !11
  %13 = tail call i32 @memcmp(ptr noundef %11, ptr noundef %12, i64 noundef %6) #3
  %14 = tail call i32 @llvm.umax.i32(i32 %13, i32 1)
  br label %29

15:                                               ; preds = %2
  %16 = icmp ult i64 %4, %6
  %17 = icmp eq i64 %4, 0
  br i1 %16, label %18, label %24

18:                                               ; preds = %15
  br i1 %17, label %29, label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %0, align 8, !tbaa !11
  %21 = load ptr, ptr %1, align 8, !tbaa !11
  %22 = tail call i32 @memcmp(ptr noundef %20, ptr noundef %21, i64 noundef %4) #3
  %.not = icmp eq i32 %22, 0
  %23 = select i1 %.not, i32 -1, i32 %22
  br label %29

24:                                               ; preds = %15
  br i1 %17, label %29, label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %0, align 8, !tbaa !11
  %27 = load ptr, ptr %1, align 8, !tbaa !11
  %28 = tail call i32 @memcmp(ptr noundef %26, ptr noundef %27, i64 noundef %4) #3
  br label %29

29:                                               ; preds = %24, %18, %8, %25, %19, %10
  %.0 = phi i32 [ %14, %10 ], [ %23, %19 ], [ %28, %25 ], [ 1, %8 ], [ 1, %18 ], [ 0, %24 ]
  ret i32 %.0
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #2

attributes #0 = { mustprogress nofree nounwind willreturn memory(read, inaccessiblemem: none) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 16, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}


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