; 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
define dso_local void @generate(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %40, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 6
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %43

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

14:                                               ; preds = %34, %13
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 6
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %37

18:                                               ; preds = %14
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = add nsw i32 %20, %21
  %23 = srem i32 %22, 6
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %19, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [6 x i8], ptr %27, i64 %29
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [6 x i8], ptr %30, i64 0, i64 %32
  store i8 %26, ptr %33, align 1, !tbaa !11
  br label %34

34:                                               ; preds = %18
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %8, align 4, !tbaa !9
  br label %14, !llvm.loop !12

37:                                               ; preds = %17
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %37
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !14

43:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

; 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

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}


; 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 norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @generate(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
.preheader:
  %2 = load i8, ptr %0, align 1, !tbaa !5
  store i8 %2, ptr %1, align 1, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 1
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %4, ptr %5, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 2
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 %7, ptr %8, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 3
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %1, i64 3
  store i8 %10, ptr %11, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %1, i64 4
  store i8 %13, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 5
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %1, i64 5
  store i8 %16, ptr %17, align 1, !tbaa !5
  %18 = load i8, ptr %3, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %1, i64 6
  store i8 %18, ptr %19, align 1, !tbaa !5
  %20 = load i8, ptr %6, align 1, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %1, i64 7
  store i8 %20, ptr %21, align 1, !tbaa !5
  %22 = load i8, ptr %9, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %1, i64 8
  store i8 %22, ptr %23, align 1, !tbaa !5
  %24 = load i8, ptr %12, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %1, i64 9
  store i8 %24, ptr %25, align 1, !tbaa !5
  %26 = load i8, ptr %15, align 1, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %1, i64 10
  store i8 %26, ptr %27, align 1, !tbaa !5
  %28 = load i8, ptr %0, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %1, i64 11
  store i8 %28, ptr %29, align 1, !tbaa !5
  %30 = load i8, ptr %6, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %1, i64 12
  store i8 %30, ptr %31, align 1, !tbaa !5
  %32 = load i8, ptr %9, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %1, i64 13
  store i8 %32, ptr %33, align 1, !tbaa !5
  %34 = load i8, ptr %12, align 1, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %1, i64 14
  store i8 %34, ptr %35, align 1, !tbaa !5
  %36 = load i8, ptr %15, align 1, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %1, i64 15
  store i8 %36, ptr %37, align 1, !tbaa !5
  %38 = load i8, ptr %0, align 1, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %1, i64 16
  store i8 %38, ptr %39, align 1, !tbaa !5
  %40 = load i8, ptr %3, align 1, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %1, i64 17
  store i8 %40, ptr %41, align 1, !tbaa !5
  %42 = load i8, ptr %9, align 1, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %1, i64 18
  store i8 %42, ptr %43, align 1, !tbaa !5
  %44 = load i8, ptr %12, align 1, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %1, i64 19
  store i8 %44, ptr %45, align 1, !tbaa !5
  %46 = load i8, ptr %15, align 1, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %1, i64 20
  store i8 %46, ptr %47, align 1, !tbaa !5
  %48 = load i8, ptr %0, align 1, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %1, i64 21
  store i8 %48, ptr %49, align 1, !tbaa !5
  %50 = load i8, ptr %3, align 1, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %1, i64 22
  store i8 %50, ptr %51, align 1, !tbaa !5
  %52 = load i8, ptr %6, align 1, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %1, i64 23
  store i8 %52, ptr %53, align 1, !tbaa !5
  %54 = load i8, ptr %12, align 1, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %1, i64 24
  store i8 %54, ptr %55, align 1, !tbaa !5
  %56 = load i8, ptr %15, align 1, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %1, i64 25
  store i8 %56, ptr %57, align 1, !tbaa !5
  %58 = load i8, ptr %0, align 1, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %1, i64 26
  store i8 %58, ptr %59, align 1, !tbaa !5
  %60 = load i8, ptr %3, align 1, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %1, i64 27
  store i8 %60, ptr %61, align 1, !tbaa !5
  %62 = load i8, ptr %6, align 1, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %1, i64 28
  store i8 %62, ptr %63, align 1, !tbaa !5
  %64 = load i8, ptr %9, align 1, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %1, i64 29
  store i8 %64, ptr %65, align 1, !tbaa !5
  %66 = load i8, ptr %15, align 1, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %1, i64 30
  store i8 %66, ptr %67, align 1, !tbaa !5
  %68 = load i8, ptr %0, align 1, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %1, i64 31
  store i8 %68, ptr %69, align 1, !tbaa !5
  %70 = load i8, ptr %3, align 1, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %1, i64 32
  store i8 %70, ptr %71, align 1, !tbaa !5
  %72 = load i8, ptr %6, align 1, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %1, i64 33
  store i8 %72, ptr %73, align 1, !tbaa !5
  %74 = load i8, ptr %9, align 1, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %1, i64 34
  store i8 %74, ptr %75, align 1, !tbaa !5
  %76 = load i8, ptr %12, align 1, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %1, i64 35
  store i8 %76, ptr %77, align 1, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass