; LLVM IR from Water-Melon/Melon :: src (mln_rc)

; 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: nounwind uwtable
define dso_local void @mln_rc4_calc(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca [256 x i8], align 16
  %12 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 256, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %13 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 0
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %13, ptr align 1 %14, i64 256, i1 false)
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %70, %3
  %16 = load i64, ptr %12, align 8, !tbaa !9
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %19, label %73

19:                                               ; preds = %15
  %20 = load i32, ptr %7, align 4, !tbaa !11
  %21 = add i32 %20, 1
  %22 = urem i32 %21, 256
  store i32 %22, ptr %7, align 4, !tbaa !11
  %23 = load i32, ptr %8, align 4, !tbaa !11
  %24 = load i32, ptr %7, align 4, !tbaa !11
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !13
  %28 = zext i8 %27 to i32
  %29 = add i32 %23, %28
  %30 = urem i32 %29, 256
  store i32 %30, ptr %8, align 4, !tbaa !11
  %31 = load i32, ptr %7, align 4, !tbaa !11
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !13
  store i8 %34, ptr %10, align 1, !tbaa !13
  %35 = load i32, ptr %8, align 4, !tbaa !11
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !13
  %39 = load i32, ptr %7, align 4, !tbaa !11
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 %40
  store i8 %38, ptr %41, align 1, !tbaa !13
  %42 = load i8, ptr %10, align 1, !tbaa !13
  %43 = load i32, ptr %8, align 4, !tbaa !11
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 %44
  store i8 %42, ptr %45, align 1, !tbaa !13
  %46 = load i32, ptr %7, align 4, !tbaa !11
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !13
  %50 = zext i8 %49 to i32
  %51 = load i32, ptr %8, align 4, !tbaa !11
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !13
  %55 = zext i8 %54 to i32
  %56 = add nsw i32 %50, %55
  %57 = srem i32 %56, 256
  store i32 %57, ptr %9, align 4, !tbaa !11
  %58 = load i32, ptr %9, align 4, !tbaa !11
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !13
  %62 = zext i8 %61 to i32
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i64, ptr %12, align 8, !tbaa !9
  %65 = getelementptr inbounds i8, ptr %63, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !13
  %67 = zext i8 %66 to i32
  %68 = xor i32 %67, %62
  %69 = trunc i32 %68 to i8
  store i8 %69, ptr %65, align 1, !tbaa !13
  br label %70

70:                                               ; preds = %19
  %71 = load i64, ptr %12, align 8, !tbaa !9
  %72 = add i64 %71, 1
  store i64 %72, ptr %12, align 8, !tbaa !9
  br label %15, !llvm.loop !14

73:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 256, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @mln_rc4_calc(ptr nocapture noundef nonnull readonly %0, ptr nocapture noundef nonnull %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = alloca [256 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %4) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) %4, ptr noundef nonnull align 1 dereferenceable(256) %0, i64 256, i1 false)
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.021 = phi i64 [ %20, %.lr.ph ], [ 0, %3 ]
  %.01620 = phi i32 [ %6, %.lr.ph ], [ 0, %3 ]
  %.01719 = phi i8 [ %.narrow18, %.lr.ph ], [ 0, %3 ]
  %5 = add nuw nsw i32 %.01620, 1
  %6 = and i32 %5, 255
  %7 = zext nneg i32 %6 to i64
  %8 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %.narrow18 = add i8 %9, %.01719
  %10 = zext i8 %.narrow18 to i64
  %11 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !5
  store i8 %12, ptr %8, align 1, !tbaa !5
  store i8 %9, ptr %11, align 1, !tbaa !5
  %13 = load i8, ptr %8, align 1, !tbaa !5
  %.narrow = add i8 %13, %9
  %14 = zext i8 %.narrow to i64
  %15 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %1, i64 %.021
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = xor i8 %18, %16
  store i8 %19, ptr %17, align 1, !tbaa !5
  %20 = add nuw i64 %.021, 1
  %exitcond.not = icmp eq i64 %20, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %3
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %4) #3
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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" }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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