; LLVM IR from clangen/musikcube :: src/3rdparty/src/sqlean/unicode (extension)

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

; 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 @sqlite3_unicode_collate(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr inttoptr (i64 1 to ptr), %12
  br i1 %13, label %14, label %27

14:                                               ; preds = %5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %14
  %21 = load i32, ptr %7, align 4, !tbaa !9
  br label %24

22:                                               ; preds = %14
  %23 = load i32, ptr %9, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %22, %20
  %25 = phi i32 [ %21, %20 ], [ %23, %22 ]
  %26 = call i32 @sqlite3StrNICmp(ptr noundef %15, ptr noundef %16, i32 noundef %25)
  store i32 %26, ptr %11, align 4, !tbaa !9
  br label %44

27:                                               ; preds = %5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = icmp eq ptr inttoptr (i64 4 to ptr), %28
  br i1 %29, label %30, label %43

30:                                               ; preds = %27
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %38

36:                                               ; preds = %30
  %37 = load i32, ptr %7, align 4, !tbaa !9
  br label %40

38:                                               ; preds = %30
  %39 = load i32, ptr %9, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %38, %36
  %41 = phi i32 [ %37, %36 ], [ %39, %38 ]
  %42 = call i32 @sqlite3StrNICmp16(ptr noundef %31, ptr noundef %32, i32 noundef %41)
  store i32 %42, ptr %11, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %40, %27
  br label %44

44:                                               ; preds = %43, %24
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = icmp eq i32 0, %45
  br i1 %46, label %47, label %51

47:                                               ; preds = %44
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = sub nsw i32 %48, %49
  store i32 %50, ptr %11, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %47, %44
  %52 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret i32 %52
}

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3StrNICmp(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3StrNICmp16(ptr noundef, ptr noundef, i32 noundef) #1

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 = !{!"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: nounwind uwtable
define dso_local i32 @sqlite3_unicode_collate(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %magicptr = ptrtoint ptr %0 to i64
  switch i64 %magicptr, label %.thread [
    i64 1, label %7
    i64 4, label %10
  ]

.thread:                                          ; preds = %5
  %6 = sub nsw i32 %1, %3
  br label %16

7:                                                ; preds = %5
  %8 = tail call i32 @llvm.smin.i32(i32 %1, i32 %3)
  %9 = tail call i32 @sqlite3StrNICmp(ptr noundef %2, ptr noundef %4, i32 noundef %8)
  br label %13

10:                                               ; preds = %5
  %11 = tail call i32 @llvm.smin.i32(i32 %1, i32 %3)
  %12 = tail call i32 @sqlite3StrNICmp16(ptr noundef %2, ptr noundef %4, i32 noundef %11)
  br label %13

13:                                               ; preds = %10, %7
  %.0 = phi i32 [ %9, %7 ], [ %12, %10 ]
  %.0.fr = freeze i32 %.0
  %14 = icmp eq i32 %.0.fr, 0
  %15 = sub nsw i32 %1, %3
  %spec.select = select i1 %14, i32 %15, i32 %.0.fr
  br label %16

16:                                               ; preds = %13, %.thread
  %17 = phi i32 [ %6, %.thread ], [ %spec.select, %13 ]
  ret i32 %17
}

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3StrNICmp(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @sqlite3StrNICmp16(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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)"}


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