; LLVM IR from kala13x/libxutils :: src/crypt (base64)

; 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
declare dso_local ptr @XBase64_Decrypt(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @XBase64_UrlDecrypt(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %19

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %19

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %15, %12, %2
  store ptr null, ptr %3, align 8
  br label %80

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = add i64 %22, 1
  %24 = call noalias ptr @malloc(i64 noundef %23) #5
  store ptr %24, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %20
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %79

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

29:                                               ; preds = %66, %28
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = icmp ult i64 %30, %32
  br i1 %33, label %34, label %69

34:                                               ; preds = %29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %35, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = zext i8 %38 to i32
  %40 = icmp eq i32 %39, 45
  br i1 %40, label %41, label %45

41:                                               ; preds = %34
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %42, i64 %43
  store i8 43, ptr %44, align 1, !tbaa !11
  br label %65

45:                                               ; preds = %34
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i64, ptr %8, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = zext i8 %49 to i32
  %51 = icmp eq i32 %50, 95
  br i1 %51, label %52, label %56

52:                                               ; preds = %45
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  store i8 47, ptr %55, align 1, !tbaa !11
  br label %64

56:                                               ; preds = %45
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load i64, ptr %8, align 8, !tbaa !9
  %59 = getelementptr inbounds i8, ptr %57, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !11
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i64, ptr %8, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %61, i64 %62
  store i8 %60, ptr %63, align 1, !tbaa !11
  br label %64

64:                                               ; preds = %56, %52
  br label %65

65:                                               ; preds = %64, %41
  br label %66

66:                                               ; preds = %65
  %67 = load i64, ptr %8, align 8, !tbaa !9
  %68 = add i64 %67, 1
  store i64 %68, ptr %8, align 8, !tbaa !9
  br label %29, !llvm.loop !12

69:                                               ; preds = %29
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = load i64, ptr %71, align 8, !tbaa !9
  %73 = getelementptr inbounds i8, ptr %70, i64 %72
  store i8 0, ptr %73, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = call ptr @XBase64_Decrypt(ptr noundef %74, ptr noundef %75)
  store ptr %76, ptr %9, align 8, !tbaa !5
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %77) #4
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %78, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %79

79:                                               ; preds = %69, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %80

80:                                               ; preds = %79, %19
  %81 = load ptr, ptr %3, align 8
  ret ptr %81
}

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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 = { 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 #3 = { nounwind "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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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 ptr @XBase64_Decrypt(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @XBase64_UrlDecrypt(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp ne ptr %0, null
  %4 = icmp ne ptr %1, null
  %or.cond = and i1 %3, %4
  br i1 %or.cond, label %5, label %32

5:                                                ; preds = %2
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %32, label %7

7:                                                ; preds = %5
  %8 = add i64 %6, 1
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #3
  %.not34 = icmp eq ptr %9, null
  br i1 %.not34, label %32, label %.preheader.preheader

.preheader.preheader:                             ; preds = %7
  %xtraiter = and i64 %6, 1
  %10 = icmp eq i64 %6, 1
  br i1 %10, label %.unr-lcssa, label %.preheader.preheader.new

.preheader.preheader.new:                         ; preds = %.preheader.preheader
  %unroll_iter = and i64 %6, -2
  br label %.preheader

.preheader:                                       ; preds = %22, %.preheader.preheader.new
  %.02735 = phi i64 [ 0, %.preheader.preheader.new ], [ %23, %22 ]
  %niter = phi i64 [ 0, %.preheader.preheader.new ], [ %niter.next.1, %22 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 %.02735
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %9, i64 %.02735
  switch i8 %12, label %15 [
    i8 45, label %.preheader.1
    i8 95, label %14
  ]

14:                                               ; preds = %.preheader
  br label %.preheader.1

15:                                               ; preds = %.preheader
  br label %.preheader.1

.preheader.1:                                     ; preds = %.preheader, %15, %14
  %.sink = phi i8 [ %12, %15 ], [ 47, %14 ], [ 43, %.preheader ]
  store i8 %.sink, ptr %13, align 1, !tbaa !9
  %16 = or disjoint i64 %.02735, 1
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %9, i64 %16
  switch i8 %18, label %21 [
    i8 45, label %22
    i8 95, label %20
  ]

20:                                               ; preds = %.preheader.1
  br label %22

21:                                               ; preds = %.preheader.1
  br label %22

22:                                               ; preds = %21, %20, %.preheader.1
  %.sink.1 = phi i8 [ %18, %21 ], [ 47, %20 ], [ 43, %.preheader.1 ]
  store i8 %.sink.1, ptr %19, align 1, !tbaa !9
  %23 = add nuw i64 %.02735, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.unr-lcssa, label %.preheader, !llvm.loop !10

.unr-lcssa:                                       ; preds = %22, %.preheader.preheader
  %.02735.unr = phi i64 [ 0, %.preheader.preheader ], [ %23, %22 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %29, label %.preheader.epil

.preheader.epil:                                  ; preds = %.unr-lcssa
  %24 = getelementptr inbounds i8, ptr %0, i64 %.02735.unr
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %9, i64 %.02735.unr
  switch i8 %25, label %28 [
    i8 45, label %.epilog-lcssa
    i8 95, label %27
  ]

27:                                               ; preds = %.preheader.epil
  br label %.epilog-lcssa

28:                                               ; preds = %.preheader.epil
  br label %.epilog-lcssa

.epilog-lcssa:                                    ; preds = %28, %27, %.preheader.epil
  %.sink.epil = phi i8 [ %25, %28 ], [ 47, %27 ], [ 43, %.preheader.epil ]
  store i8 %.sink.epil, ptr %26, align 1, !tbaa !9
  br label %29

29:                                               ; preds = %.unr-lcssa, %.epilog-lcssa
  %30 = getelementptr inbounds i8, ptr %9, i64 %6
  store i8 0, ptr %30, align 1, !tbaa !9
  %31 = tail call ptr @XBase64_Decrypt(ptr noundef nonnull %9, ptr noundef nonnull %1)
  tail call void @free(ptr noundef nonnull %9) #4
  br label %32

32:                                               ; preds = %29, %7, %2, %5
  %.1 = phi ptr [ null, %5 ], [ null, %2 ], [ %31, %29 ], [ null, %7 ]
  ret ptr %.1
}

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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 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 #2 = { mustprogress nounwind willreturn allockind("free") 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 #3 = { nounwind allocsize(0) }
attributes #4 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass