; LLVM IR from 0intro/wmii :: lib/libutf (runetype)

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

@__tolower2 = external hidden global [108 x i32], align 16
@__tolower1 = external hidden global [666 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @tolowerrune(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = call ptr @bsearch(i32 noundef %6, ptr noundef @__tolower2, i32 noundef 36, i32 noundef 3)
  store ptr %7, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %29

10:                                               ; preds = %1
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !9
  %13 = getelementptr inbounds i32, ptr %12, i64 0
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp uge i32 %11, %14
  br i1 %15, label %16, label %29

16:                                               ; preds = %10
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = getelementptr inbounds i32, ptr %18, i64 1
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp ule i32 %17, %20
  br i1 %21, label %22, label %29

22:                                               ; preds = %16
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds i32, ptr %24, i64 2
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add i32 %23, %26
  %28 = sub i32 %27, 500
  store i32 %28, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %49

29:                                               ; preds = %16, %10, %1
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = call ptr @bsearch(i32 noundef %30, ptr noundef @__tolower1, i32 noundef 333, i32 noundef 2)
  store ptr %31, ptr %4, align 8, !tbaa !9
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %47

34:                                               ; preds = %29
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = getelementptr inbounds i32, ptr %36, i64 0
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp eq i32 %35, %38
  br i1 %39, label %40, label %47

40:                                               ; preds = %34
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  %43 = getelementptr inbounds i32, ptr %42, i64 1
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add i32 %41, %44
  %46 = sub i32 %45, 500
  store i32 %46, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %49

47:                                               ; preds = %34, %29
  %48 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %48, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %49

49:                                               ; preds = %47, %40, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %50 = load i32, ptr %2, align 4
  ret i32 %50
}

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

@__tolower2 = external hidden global [108 x i32], align 16
@__tolower1 = external hidden global [666 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @tolowerrune(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @bsearch(i32 noundef %0, ptr noundef nonnull @__tolower2, i32 noundef 36, i32 noundef 3)
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %10, label %3

3:                                                ; preds = %1
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %.not18 = icmp ugt i32 %4, %0
  br i1 %.not18, label %10, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %2, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not19 = icmp ult i32 %7, %0
  br i1 %.not19, label %10, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %2, i64 8
  br label %.sink.split

10:                                               ; preds = %5, %3, %1
  %11 = tail call ptr @bsearch(i32 noundef %0, ptr noundef nonnull @__tolower1, i32 noundef 333, i32 noundef 2)
  %.not20 = icmp eq ptr %11, null
  br i1 %.not20, label %20, label %12

12:                                               ; preds = %10
  %13 = load i32, ptr %11, align 4, !tbaa !5
  %14 = icmp eq i32 %13, %0
  br i1 %14, label %15, label %20

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %11, i64 4
  br label %.sink.split

.sink.split:                                      ; preds = %8, %15
  %.sink = phi ptr [ %16, %15 ], [ %9, %8 ]
  %17 = load i32, ptr %.sink, align 4, !tbaa !5
  %18 = add i32 %0, -500
  %19 = add i32 %18, %17
  br label %20

20:                                               ; preds = %.sink.split, %10, %12
  %.0 = phi i32 [ %0, %12 ], [ %0, %10 ], [ %19, %.sink.split ]
  ret i32 %.0
}

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

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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