; LLVM IR from kojiba/purge :: PurgeEvasionUtils (encryptPurgeEvasion)

; 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 @evasionHashData(ptr noundef, i64 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; 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) #3

declare void @evasionRand(ptr noundef) #4

; 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 ptr @encryptPurgeEvasion(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca [8 x i64], align 16
  %15 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #8
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #8
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = add i64 %16, 8
  store i64 %17, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #8
  %18 = load i64, ptr %11, align 8, !tbaa !9
  %19 = udiv i64 %18, 64
  store i64 %19, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #8
  %20 = load i64, ptr %11, align 8, !tbaa !9
  %21 = urem i64 %20, 64
  store i64 %21, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %14) #8
  %22 = call ptr @llvm.stacksave.p0()
  store ptr %22, ptr %15, align 8
  %23 = alloca i8, i64 64, align 16
  %24 = load i64, ptr %13, align 8, !tbaa !9
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %33

26:                                               ; preds = %4
  %27 = load i64, ptr %13, align 8, !tbaa !9
  %28 = sub i64 64, %27
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = add i64 %29, %28
  store i64 %30, ptr %11, align 8, !tbaa !9
  %31 = load i64, ptr %12, align 8, !tbaa !9
  %32 = add i64 %31, 1
  store i64 %32, ptr %12, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %26, %4
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = call noalias ptr @malloc(i64 noundef %34) #9
  store ptr %35, ptr %10, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %95

38:                                               ; preds = %33
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 0, ptr %39, align 8, !tbaa !9
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %40, ptr align 8 %6, i64 8, i1 false)
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 8
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %42, ptr align 1 %43, i64 %44, i1 false)
  %45 = load i64, ptr %13, align 8, !tbaa !9
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %54

47:                                               ; preds = %38
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = getelementptr inbounds i8, ptr %48, i64 %49
  %51 = getelementptr inbounds i8, ptr %50, i64 8
  %52 = load i64, ptr %13, align 8, !tbaa !9
  %53 = sub i64 64, %52
  call void @llvm.memset.p0.i64(ptr align 1 %51, i8 0, i64 %53, i1 false)
  br label %54

54:                                               ; preds = %47, %38
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 8
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = sub i64 %57, 8
  %59 = getelementptr inbounds [8 x i64], ptr %14, i64 0, i64 0
  call void @evasionHashData(ptr noundef %56, i64 noundef %58, ptr noundef %59)
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %71, %54
  %61 = load i64, ptr %9, align 8, !tbaa !9
  %62 = load i64, ptr %12, align 8, !tbaa !9
  %63 = icmp ult i64 %61, %62
  br i1 %63, label %64, label %74

64:                                               ; preds = %60
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  call void @evasionRand(ptr noundef %65)
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %23, ptr align 8 %66, i64 64, i1 false)
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load i64, ptr %9, align 8, !tbaa !9
  %69 = mul i64 %68, 64
  %70 = getelementptr inbounds i8, ptr %67, i64 %69
  call void @purgeEncrypt(ptr noundef %70, ptr noundef %23)
  call void @llvm.memset.p0.i64(ptr align 16 %23, i8 0, i64 64, i1 false)
  br label %71

71:                                               ; preds = %64
  %72 = load i64, ptr %9, align 8, !tbaa !9
  %73 = add i64 %72, 1
  store i64 %73, ptr %9, align 8, !tbaa !9
  br label %60, !llvm.loop !11

74:                                               ; preds = %60
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  call void @evasionRand(ptr noundef %75)
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %23, ptr align 8 %76, i64 64, i1 false)
  %77 = getelementptr inbounds [8 x i64], ptr %14, i64 0, i64 0
  call void @purgeEncrypt(ptr noundef %77, ptr noundef %23)
  call void @llvm.memset.p0.i64(ptr align 16 %23, i8 0, i64 64, i1 false)
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = load i64, ptr %11, align 8, !tbaa !9
  %80 = add i64 %79, 64
  %81 = call ptr @realloc(ptr noundef %78, i64 noundef %80) #10
  store ptr %81, ptr %10, align 8, !tbaa !5
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = icmp ne ptr %82, null
  br i1 %83, label %84, label %94

84:                                               ; preds = %74
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = load i64, ptr %11, align 8, !tbaa !9
  %87 = getelementptr inbounds i8, ptr %85, i64 %86
  %88 = getelementptr inbounds [8 x i64], ptr %14, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %87, ptr align 16 %88, i64 64, i1 false)
  %89 = load i64, ptr %11, align 8, !tbaa !9
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %89, ptr %90, align 8, !tbaa !9
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = load i64, ptr %91, align 8, !tbaa !9
  %93 = add i64 %92, 64
  store i64 %93, ptr %91, align 8, !tbaa !9
  br label %94

94:                                               ; preds = %84, %74
  br label %95

95:                                               ; preds = %94, %33
  %96 = load ptr, ptr %10, align 8, !tbaa !5
  %97 = load ptr, ptr %15, align 8
  call void @llvm.stackrestore.p0(ptr %97)
  call void @llvm.lifetime.end.p0(i64 64, ptr %14) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  ret ptr %96
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #5

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #6

declare void @purgeEncrypt(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #7

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #5

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { nocallback nofree nosync nounwind willreturn }
attributes #6 = { nounwind allocsize(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 #7 = { nounwind allocsize(1) "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 #8 = { nounwind }
attributes #9 = { nounwind allocsize(0) }
attributes #10 = { nounwind allocsize(1) }

!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 = distinct !{!11, !12}
!12 = !{!"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: nounwind uwtable
declare dso_local void @evasionHashData(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

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

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

; 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) #3

declare void @evasionRand(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress 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 noalias noundef ptr @encryptPurgeEvasion(ptr nocapture noundef readonly %0, i64 noundef %1, ptr noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = alloca [8 x i64], align 16
  %6 = add i64 %1, 8
  %7 = lshr i64 %6, 6
  %8 = and i64 %6, 63
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #8
  %9 = tail call ptr @llvm.stacksave.p0()
  %10 = alloca [64 x i8], align 16
  %.not = icmp ne i64 %8, 0
  %11 = add i64 %1, 72
  %12 = sub i64 %11, %8
  %.040 = select i1 %.not, i64 %12, i64 %6
  %13 = zext i1 %.not to i64
  %.039 = add nuw nsw i64 %7, %13
  %14 = tail call noalias ptr @malloc(i64 noundef %.040) #9
  %.not46 = icmp eq ptr %14, null
  br i1 %.not46, label %30, label %15

15:                                               ; preds = %4
  store i64 0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %14, align 1
  %16 = getelementptr inbounds i8, ptr %14, i64 8
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %16, ptr align 1 %0, i64 %1, i1 false)
  br i1 %.not, label %17, label %21

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %14, i64 %1
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = sub nuw nsw i64 64, %8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %19, i8 0, i64 %20, i1 false)
  br label %21

21:                                               ; preds = %17, %15
  %22 = add i64 %.040, -8
  call void @evasionHashData(ptr noundef nonnull %16, i64 noundef %22, ptr noundef nonnull %5)
  %.not49 = icmp eq i64 %.039, 0
  br i1 %.not49, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %21, %.lr.ph
  %.048 = phi i64 [ %25, %.lr.ph ], [ 0, %21 ]
  call void @evasionRand(ptr noundef %2) #8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %10, ptr noundef nonnull align 8 dereferenceable(64) %2, i64 64, i1 false)
  %23 = shl nuw i64 %.048, 6
  %24 = getelementptr inbounds i8, ptr %14, i64 %23
  call void @purgeEncrypt(ptr noundef nonnull %24, ptr noundef nonnull %10) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %10, i8 0, i64 64, i1 false)
  %25 = add nuw nsw i64 %.048, 1
  %exitcond.not = icmp eq i64 %25, %.039
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %21
  call void @evasionRand(ptr noundef %2) #8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %10, ptr noundef nonnull align 8 dereferenceable(64) %2, i64 64, i1 false)
  call void @purgeEncrypt(ptr noundef nonnull %5, ptr noundef nonnull %10) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %10, i8 0, i64 64, i1 false)
  %26 = add i64 %.040, 64
  %27 = call ptr @realloc(ptr noundef nonnull %14, i64 noundef %26) #10
  %.not47 = icmp eq ptr %27, null
  br i1 %.not47, label %30, label %28

28:                                               ; preds = %._crit_edge
  %29 = getelementptr inbounds i8, ptr %27, i64 %.040
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(64) %29, ptr noundef nonnull align 16 dereferenceable(64) %5, i64 64, i1 false)
  store i64 %26, ptr %3, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %._crit_edge, %28, %4
  %.038 = phi ptr [ %27, %28 ], [ null, %._crit_edge ], [ null, %4 ]
  call void @llvm.stackrestore.p0(ptr %9)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #8
  ret ptr %.038
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #5

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #6

declare void @purgeEncrypt(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #7

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #5

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #6 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #7 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #8 = { nounwind }
attributes #9 = { nounwind allocsize(0) }
attributes #10 = { nounwind allocsize(1) }

!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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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