; LLVM IR from TypicalHog/THCrypt :: main.ll (Z7encryptxxxPhxS_S_)

; 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: mustprogress nounwind uwtable
define dso_local void @_Z7encryptxxxPhxS_S_(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6) #1 {
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i64, align 8
  store i64 %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !9
  store ptr %6, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  store i64 0, ptr %15, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %58, %7
  %19 = load i64, ptr %15, align 8, !tbaa !5
  %20 = load i64, ptr %10, align 8, !tbaa !5
  %21 = icmp slt i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store i32 2, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  br label %61

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #2
  %24 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %24, ptr %17, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %53, %23
  %26 = load i64, ptr %17, align 8, !tbaa !5
  %27 = load i64, ptr %12, align 8, !tbaa !5
  %28 = icmp slt i64 %26, %27
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %25
  %31 = load ptr, ptr %14, align 8, !tbaa !9
  %32 = load ptr, ptr %11, align 8, !tbaa !9
  %33 = load i64, ptr %15, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %32, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = mul nsw i32 %36, 256
  %38 = sext i32 %37 to i64
  %39 = load ptr, ptr %13, align 8, !tbaa !9
  %40 = load i64, ptr %17, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %39, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = zext i8 %42 to i64
  %44 = load i64, ptr %17, align 8, !tbaa !5
  %45 = add nsw i64 %43, %44
  %46 = srem i64 %45, 256
  %47 = add nsw i64 %38, %46
  %48 = getelementptr inbounds i8, ptr %31, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = load ptr, ptr %13, align 8, !tbaa !9
  %51 = load i64, ptr %17, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  store i8 %49, ptr %52, align 1, !tbaa !11
  br label %53

53:                                               ; preds = %30
  %54 = load i64, ptr %9, align 8, !tbaa !5
  %55 = load i64, ptr %17, align 8, !tbaa !5
  %56 = add nsw i64 %55, %54
  store i64 %56, ptr %17, align 8, !tbaa !5
  br label %25, !llvm.loop !12

57:                                               ; preds = %29
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %15, align 8, !tbaa !5
  %60 = add nsw i64 %59, 1
  store i64 %60, ptr %15, align 8, !tbaa !5
  br label %18, !llvm.loop !14

61:                                               ; preds = %22
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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 memory(argmem: readwrite) uwtable
define dso_local void @_Z7encryptxxxPhxS_S_(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef readonly %3, i64 noundef %4, ptr nocapture noundef %5, ptr nocapture noundef readonly %6) local_unnamed_addr #0 {
  %8 = icmp sgt i64 %2, 0
  %9 = icmp slt i64 %0, %4
  %or.cond = and i1 %8, %9
  br i1 %or.cond, label %.preheader.us, label %._crit_edge18

.preheader.us:                                    ; preds = %7, %._crit_edge.us
  %.01517.us = phi i64 [ %25, %._crit_edge.us ], [ 0, %7 ]
  %10 = getelementptr inbounds i8, ptr %3, i64 %.01517.us
  br label %11

11:                                               ; preds = %.preheader.us, %11
  %.016.us = phi i64 [ %0, %.preheader.us ], [ %23, %11 ]
  %12 = load i8, ptr %10, align 1, !tbaa !5
  %13 = zext i8 %12 to i64
  %14 = shl nuw nsw i64 %13, 8
  %15 = getelementptr inbounds i8, ptr %5, i64 %.016.us
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = zext i8 %16 to i64
  %18 = add nsw i64 %.016.us, %17
  %19 = srem i64 %18, 256
  %20 = getelementptr i8, ptr %6, i64 %14
  %21 = getelementptr i8, ptr %20, i64 %19
  %22 = load i8, ptr %21, align 1, !tbaa !5
  store i8 %22, ptr %15, align 1, !tbaa !5
  %23 = add nsw i64 %.016.us, %1
  %24 = icmp slt i64 %23, %4
  br i1 %24, label %11, label %._crit_edge.us, !llvm.loop !8

._crit_edge.us:                                   ; preds = %11
  %25 = add nuw nsw i64 %.01517.us, 1
  %exitcond.not = icmp eq i64 %25, %2
  br i1 %exitcond.not, label %._crit_edge18, label %.preheader.us, !llvm.loop !10

._crit_edge18:                                    ; preds = %._crit_edge.us, %7
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind 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++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass