; LLVM IR from HarshCasper/NeoAlgo :: C/cryptography (Burrows_Wheeler_Transform)

; 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: nounwind uwtable
declare dso_local void @generate(ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @sort(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 0
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  call void @generate(ptr noundef %15, ptr noundef %16)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %74, %3
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 6
  br i1 %19, label %20, label %77

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %71, %20
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = icmp slt i32 %22, 1
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i32 4, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %74

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #2
  store i8 123, ptr %11, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %54, %25
  %27 = load i32, ptr %13, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 6
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 7, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %57

30:                                               ; preds = %26
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %13, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [6 x i8], ptr %31, i64 %33
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [6 x i8], ptr %34, i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = sext i8 %38 to i32
  %40 = load i8, ptr %11, align 1, !tbaa !11
  %41 = sext i8 %40 to i32
  %42 = icmp slt i32 %39, %41
  br i1 %42, label %43, label %53

43:                                               ; preds = %30
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %13, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [6 x i8], ptr %44, i64 %46
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [6 x i8], ptr %47, i64 0, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !11
  store i8 %51, ptr %11, align 1, !tbaa !11
  %52 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %52, ptr %12, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %43, %30
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %13, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %13, align 4, !tbaa !9
  br label %26, !llvm.loop !12

57:                                               ; preds = %29
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %7, align 4, !tbaa !9
  %62 = sext i32 %60 to i64
  %63 = getelementptr inbounds i32, ptr %59, i64 %62
  store i32 %58, ptr %63, align 4, !tbaa !9
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [6 x i8], ptr %64, i64 %66
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [6 x i8], ptr %67, i64 0, i64 %69
  store i8 123, ptr %70, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #2
  br label %71

71:                                               ; preds = %57
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %9, align 4, !tbaa !9
  br label %21, !llvm.loop !14

74:                                               ; preds = %24
  %75 = load i32, ptr %8, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %8, align 4, !tbaa !9
  br label %17, !llvm.loop !15

77:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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 = !{!"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}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; 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
declare dso_local void @generate(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @sort(ptr noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
.preheader29:
  tail call void @generate(ptr noundef %0, ptr noundef %1)
  %3 = load i8, ptr %1, align 1, !tbaa !5
  %spec.select = tail call i8 @llvm.smin.i8(i8 %3, i8 123)
  %4 = getelementptr inbounds i8, ptr %1, i64 6
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %6 = icmp slt i8 %5, %spec.select
  %spec.select.1 = tail call i8 @llvm.smin.i8(i8 %5, i8 %spec.select)
  %spec.select28.1 = zext i1 %6 to i32
  %7 = getelementptr inbounds i8, ptr %1, i64 12
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = icmp slt i8 %8, %spec.select.1
  %spec.select.2 = tail call i8 @llvm.smin.i8(i8 %8, i8 %spec.select.1)
  %spec.select28.2 = select i1 %9, i32 2, i32 %spec.select28.1
  %10 = getelementptr inbounds i8, ptr %1, i64 18
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = icmp slt i8 %11, %spec.select.2
  %spec.select.3 = tail call i8 @llvm.smin.i8(i8 %11, i8 %spec.select.2)
  %spec.select28.3 = select i1 %12, i32 3, i32 %spec.select28.2
  %13 = getelementptr inbounds i8, ptr %1, i64 24
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = icmp slt i8 %14, %spec.select.3
  %spec.select.4 = tail call i8 @llvm.smin.i8(i8 %14, i8 %spec.select.3)
  %spec.select28.4 = select i1 %15, i32 4, i32 %spec.select28.3
  %16 = getelementptr inbounds i8, ptr %1, i64 30
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = icmp slt i8 %17, %spec.select.4
  %spec.select28.5 = select i1 %18, i32 5, i32 %spec.select28.4
  store i32 %spec.select28.5, ptr %2, align 4, !tbaa !8
  %19 = zext nneg i32 %spec.select28.5 to i64
  %20 = getelementptr inbounds [6 x i8], ptr %1, i64 %19
  store i8 123, ptr %20, align 1, !tbaa !5
  %21 = load i8, ptr %1, align 1, !tbaa !5
  %22 = icmp slt i8 %21, 123
  %spec.select.141 = tail call i8 @llvm.smin.i8(i8 %21, i8 123)
  %spec.select28.142 = select i1 %22, i32 0, i32 %spec.select28.5
  %23 = load i8, ptr %4, align 1, !tbaa !5
  %24 = icmp slt i8 %23, %spec.select.141
  %spec.select.1.1 = tail call i8 @llvm.smin.i8(i8 %23, i8 %spec.select.141)
  %spec.select28.1.1 = select i1 %24, i32 1, i32 %spec.select28.142
  %25 = load i8, ptr %7, align 1, !tbaa !5
  %26 = icmp slt i8 %25, %spec.select.1.1
  %spec.select.2.1 = tail call i8 @llvm.smin.i8(i8 %25, i8 %spec.select.1.1)
  %spec.select28.2.1 = select i1 %26, i32 2, i32 %spec.select28.1.1
  %27 = load i8, ptr %10, align 1, !tbaa !5
  %28 = icmp slt i8 %27, %spec.select.2.1
  %spec.select.3.1 = tail call i8 @llvm.smin.i8(i8 %27, i8 %spec.select.2.1)
  %spec.select28.3.1 = select i1 %28, i32 3, i32 %spec.select28.2.1
  %29 = load i8, ptr %13, align 1, !tbaa !5
  %30 = icmp slt i8 %29, %spec.select.3.1
  %spec.select.4.1 = tail call i8 @llvm.smin.i8(i8 %29, i8 %spec.select.3.1)
  %spec.select28.4.1 = select i1 %30, i32 4, i32 %spec.select28.3.1
  %31 = load i8, ptr %16, align 1, !tbaa !5
  %32 = icmp slt i8 %31, %spec.select.4.1
  %spec.select28.5.1 = select i1 %32, i32 5, i32 %spec.select28.4.1
  %33 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %spec.select28.5.1, ptr %33, align 4, !tbaa !8
  %34 = zext nneg i32 %spec.select28.5.1 to i64
  %35 = getelementptr inbounds [6 x i8], ptr %1, i64 %34
  store i8 123, ptr %35, align 1, !tbaa !5
  %36 = load i8, ptr %1, align 1, !tbaa !5
  %37 = icmp slt i8 %36, 123
  %spec.select.243 = tail call i8 @llvm.smin.i8(i8 %36, i8 123)
  %spec.select28.244 = select i1 %37, i32 0, i32 %spec.select28.5.1
  %38 = load i8, ptr %4, align 1, !tbaa !5
  %39 = icmp slt i8 %38, %spec.select.243
  %spec.select.1.2 = tail call i8 @llvm.smin.i8(i8 %38, i8 %spec.select.243)
  %spec.select28.1.2 = select i1 %39, i32 1, i32 %spec.select28.244
  %40 = load i8, ptr %7, align 1, !tbaa !5
  %41 = icmp slt i8 %40, %spec.select.1.2
  %spec.select.2.2 = tail call i8 @llvm.smin.i8(i8 %40, i8 %spec.select.1.2)
  %spec.select28.2.2 = select i1 %41, i32 2, i32 %spec.select28.1.2
  %42 = load i8, ptr %10, align 1, !tbaa !5
  %43 = icmp slt i8 %42, %spec.select.2.2
  %spec.select.3.2 = tail call i8 @llvm.smin.i8(i8 %42, i8 %spec.select.2.2)
  %spec.select28.3.2 = select i1 %43, i32 3, i32 %spec.select28.2.2
  %44 = load i8, ptr %13, align 1, !tbaa !5
  %45 = icmp slt i8 %44, %spec.select.3.2
  %spec.select.4.2 = tail call i8 @llvm.smin.i8(i8 %44, i8 %spec.select.3.2)
  %spec.select28.4.2 = select i1 %45, i32 4, i32 %spec.select28.3.2
  %46 = load i8, ptr %16, align 1, !tbaa !5
  %47 = icmp slt i8 %46, %spec.select.4.2
  %spec.select28.5.2 = select i1 %47, i32 5, i32 %spec.select28.4.2
  %48 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %spec.select28.5.2, ptr %48, align 4, !tbaa !8
  %49 = zext nneg i32 %spec.select28.5.2 to i64
  %50 = getelementptr inbounds [6 x i8], ptr %1, i64 %49
  store i8 123, ptr %50, align 1, !tbaa !5
  %51 = load i8, ptr %1, align 1, !tbaa !5
  %52 = icmp slt i8 %51, 123
  %spec.select.345 = tail call i8 @llvm.smin.i8(i8 %51, i8 123)
  %spec.select28.346 = select i1 %52, i32 0, i32 %spec.select28.5.2
  %53 = load i8, ptr %4, align 1, !tbaa !5
  %54 = icmp slt i8 %53, %spec.select.345
  %spec.select.1.3 = tail call i8 @llvm.smin.i8(i8 %53, i8 %spec.select.345)
  %spec.select28.1.3 = select i1 %54, i32 1, i32 %spec.select28.346
  %55 = load i8, ptr %7, align 1, !tbaa !5
  %56 = icmp slt i8 %55, %spec.select.1.3
  %spec.select.2.3 = tail call i8 @llvm.smin.i8(i8 %55, i8 %spec.select.1.3)
  %spec.select28.2.3 = select i1 %56, i32 2, i32 %spec.select28.1.3
  %57 = load i8, ptr %10, align 1, !tbaa !5
  %58 = icmp slt i8 %57, %spec.select.2.3
  %spec.select.3.3 = tail call i8 @llvm.smin.i8(i8 %57, i8 %spec.select.2.3)
  %spec.select28.3.3 = select i1 %58, i32 3, i32 %spec.select28.2.3
  %59 = load i8, ptr %13, align 1, !tbaa !5
  %60 = icmp slt i8 %59, %spec.select.3.3
  %spec.select.4.3 = tail call i8 @llvm.smin.i8(i8 %59, i8 %spec.select.3.3)
  %spec.select28.4.3 = select i1 %60, i32 4, i32 %spec.select28.3.3
  %61 = load i8, ptr %16, align 1, !tbaa !5
  %62 = icmp slt i8 %61, %spec.select.4.3
  %spec.select28.5.3 = select i1 %62, i32 5, i32 %spec.select28.4.3
  %63 = getelementptr inbounds i8, ptr %2, i64 12
  store i32 %spec.select28.5.3, ptr %63, align 4, !tbaa !8
  %64 = zext nneg i32 %spec.select28.5.3 to i64
  %65 = getelementptr inbounds [6 x i8], ptr %1, i64 %64
  store i8 123, ptr %65, align 1, !tbaa !5
  %66 = load i8, ptr %1, align 1, !tbaa !5
  %67 = icmp slt i8 %66, 123
  %spec.select.447 = tail call i8 @llvm.smin.i8(i8 %66, i8 123)
  %spec.select28.448 = select i1 %67, i32 0, i32 %spec.select28.5.3
  %68 = load i8, ptr %4, align 1, !tbaa !5
  %69 = icmp slt i8 %68, %spec.select.447
  %spec.select.1.4 = tail call i8 @llvm.smin.i8(i8 %68, i8 %spec.select.447)
  %spec.select28.1.4 = select i1 %69, i32 1, i32 %spec.select28.448
  %70 = load i8, ptr %7, align 1, !tbaa !5
  %71 = icmp slt i8 %70, %spec.select.1.4
  %spec.select.2.4 = tail call i8 @llvm.smin.i8(i8 %70, i8 %spec.select.1.4)
  %spec.select28.2.4 = select i1 %71, i32 2, i32 %spec.select28.1.4
  %72 = load i8, ptr %10, align 1, !tbaa !5
  %73 = icmp slt i8 %72, %spec.select.2.4
  %spec.select.3.4 = tail call i8 @llvm.smin.i8(i8 %72, i8 %spec.select.2.4)
  %spec.select28.3.4 = select i1 %73, i32 3, i32 %spec.select28.2.4
  %74 = load i8, ptr %13, align 1, !tbaa !5
  %75 = icmp slt i8 %74, %spec.select.3.4
  %spec.select.4.4 = tail call i8 @llvm.smin.i8(i8 %74, i8 %spec.select.3.4)
  %spec.select28.4.4 = select i1 %75, i32 4, i32 %spec.select28.3.4
  %76 = load i8, ptr %16, align 1, !tbaa !5
  %77 = icmp slt i8 %76, %spec.select.4.4
  %spec.select28.5.4 = select i1 %77, i32 5, i32 %spec.select28.4.4
  %78 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 %spec.select28.5.4, ptr %78, align 4, !tbaa !8
  %79 = zext nneg i32 %spec.select28.5.4 to i64
  %80 = getelementptr inbounds [6 x i8], ptr %1, i64 %79
  store i8 123, ptr %80, align 1, !tbaa !5
  %81 = load i8, ptr %1, align 1, !tbaa !5
  %82 = icmp slt i8 %81, 123
  %spec.select.5 = tail call i8 @llvm.smin.i8(i8 %81, i8 123)
  %spec.select28.549 = select i1 %82, i32 0, i32 %spec.select28.5.4
  %83 = load i8, ptr %4, align 1, !tbaa !5
  %84 = icmp slt i8 %83, %spec.select.5
  %spec.select.1.5 = tail call i8 @llvm.smin.i8(i8 %83, i8 %spec.select.5)
  %spec.select28.1.5 = select i1 %84, i32 1, i32 %spec.select28.549
  %85 = load i8, ptr %7, align 1, !tbaa !5
  %86 = icmp slt i8 %85, %spec.select.1.5
  %spec.select.2.5 = tail call i8 @llvm.smin.i8(i8 %85, i8 %spec.select.1.5)
  %spec.select28.2.5 = select i1 %86, i32 2, i32 %spec.select28.1.5
  %87 = load i8, ptr %10, align 1, !tbaa !5
  %88 = icmp slt i8 %87, %spec.select.2.5
  %spec.select.3.5 = tail call i8 @llvm.smin.i8(i8 %87, i8 %spec.select.2.5)
  %spec.select28.3.5 = select i1 %88, i32 3, i32 %spec.select28.2.5
  %89 = load i8, ptr %13, align 1, !tbaa !5
  %90 = icmp slt i8 %89, %spec.select.3.5
  %spec.select.4.5 = tail call i8 @llvm.smin.i8(i8 %89, i8 %spec.select.3.5)
  %spec.select28.4.5 = select i1 %90, i32 4, i32 %spec.select28.3.5
  %91 = load i8, ptr %16, align 1, !tbaa !5
  %92 = icmp slt i8 %91, %spec.select.4.5
  %spec.select28.5.5 = select i1 %92, i32 5, i32 %spec.select28.4.5
  %93 = getelementptr inbounds i8, ptr %2, i64 20
  store i32 %spec.select28.5.5, ptr %93, align 4, !tbaa !8
  %94 = zext nneg i32 %spec.select28.5.5 to i64
  %95 = getelementptr inbounds [6 x i8], ptr %1, i64 %94
  store i8 123, ptr %95, align 1, !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.smin.i8(i8, i8) #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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass