; LLVM IR from chensoft/libsocket :: lib/libchen/src/base/str.ll (ZN4chen3str11levenshteinEPKcmS2_m)

; 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.std::initializer_list" = type { ptr, i64 }

; 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: mustprogress uwtable
define dso_local noundef i64 @_ZN4chen3str11levenshteinEPKcmS2_m(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #1 align 2 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca %"class.std::initializer_list", align 8
  %13 = alloca [3 x i64], align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %4
  %17 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %17, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %72

18:                                               ; preds = %4
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %22, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %72

23:                                               ; preds = %18
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = sub i64 %25, 1
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load i64, ptr %9, align 8, !tbaa !9
  %32 = sub i64 %31, 1
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = sext i8 %34 to i32
  %36 = icmp eq i32 %29, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %23
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %39

38:                                               ; preds = %23
  store i64 1, ptr %10, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %38, %37
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #3
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = sub i64 %41, 1
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = call noundef i64 @_ZN4chen3str11levenshteinEPKcmS2_m(ptr noundef %40, i64 noundef %42, ptr noundef %43, i64 noundef %44)
  %46 = add i64 %45, 1
  store i64 %46, ptr %13, align 8, !tbaa !9
  %47 = getelementptr inbounds i64, ptr %13, i64 1
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i64, ptr %9, align 8, !tbaa !9
  %52 = sub i64 %51, 1
  %53 = call noundef i64 @_ZN4chen3str11levenshteinEPKcmS2_m(ptr noundef %48, i64 noundef %49, ptr noundef %50, i64 noundef %52)
  %54 = add i64 %53, 1
  store i64 %54, ptr %47, align 8, !tbaa !9
  %55 = getelementptr inbounds i64, ptr %13, i64 2
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i64, ptr %7, align 8, !tbaa !9
  %58 = sub i64 %57, 1
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = sub i64 %60, 1
  %62 = call noundef i64 @_ZN4chen3str11levenshteinEPKcmS2_m(ptr noundef %56, i64 noundef %58, ptr noundef %59, i64 noundef %61)
  %63 = load i64, ptr %10, align 8, !tbaa !9
  %64 = add i64 %62, %63
  store i64 %64, ptr %55, align 8, !tbaa !9
  %65 = getelementptr inbounds %"class.std::initializer_list", ptr %12, i32 0, i32 0
  store ptr %13, ptr %65, align 8, !tbaa !12
  %66 = getelementptr inbounds %"class.std::initializer_list", ptr %12, i32 0, i32 1
  store i64 3, ptr %66, align 8, !tbaa !14
  %67 = getelementptr inbounds { ptr, i64 }, ptr %12, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8
  %69 = getelementptr inbounds { ptr, i64 }, ptr %12, i32 0, i32 1
  %70 = load i64, ptr %69, align 8
  %71 = call noundef i64 @_ZSt3minImET_St16initializer_listIS0_E(ptr %68, i64 %70)
  store i64 %71, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #3
  store i32 1, ptr %11, align 4
  br label %72

72:                                               ; preds = %39, %21, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %73 = load i64, ptr %5, align 8
  ret i64 %73
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZSt3minImET_St16initializer_listIS0_E(ptr, i64) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 #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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"_ZTSSt16initializer_listImE", !6, i64 0, !10, i64 8}
!14 = !{!13, !10, i64 8}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN4chen3str11levenshteinEPKcmS2_m(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #1 align 2 {
  %5 = alloca [3 x i64], align 8
  %6 = icmp eq i64 %1, 0
  br i1 %6, label %common.ret24, label %7

7:                                                ; preds = %4
  %8 = icmp eq i64 %3, 0
  br i1 %8, label %common.ret24, label %9

common.ret24:                                     ; preds = %7, %4, %9
  %common.ret24.op = phi i64 [ %25, %9 ], [ %3, %4 ], [ %1, %7 ]
  ret i64 %common.ret24.op

9:                                                ; preds = %7
  %10 = add i64 %1, -1
  %11 = getelementptr inbounds i8, ptr %0, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = add i64 %3, -1
  %14 = getelementptr inbounds i8, ptr %2, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = icmp ne i8 %12, %15
  %. = zext i1 %16 to i64
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  %17 = tail call noundef i64 @_ZN4chen3str11levenshteinEPKcmS2_m(ptr noundef %0, i64 noundef %10, ptr noundef %2, i64 noundef %3)
  %18 = add i64 %17, 1
  store i64 %18, ptr %5, align 8, !tbaa !8
  %19 = getelementptr inbounds i8, ptr %5, i64 8
  %20 = tail call noundef i64 @_ZN4chen3str11levenshteinEPKcmS2_m(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %13)
  %21 = add i64 %20, 1
  store i64 %21, ptr %19, align 8, !tbaa !8
  %22 = getelementptr inbounds i8, ptr %5, i64 16
  %23 = tail call noundef i64 @_ZN4chen3str11levenshteinEPKcmS2_m(ptr noundef %0, i64 noundef %10, ptr noundef %2, i64 noundef %13)
  %24 = add i64 %23, %.
  store i64 %24, ptr %22, align 8, !tbaa !8
  %25 = call noundef i64 @_ZSt3minImET_St16initializer_listIS0_E(ptr nonnull %5, i64 3)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  br label %common.ret24
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZSt3minImET_St16initializer_listIS0_E(ptr, i64) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 #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 = !{!9, !9, i64 0}
!9 = !{!"long", !6, i64 0}


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