; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhanchengguo/homework/base64/Base64.ll (Z13base64_decodePKclPc)

; 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"

@.str = external hidden unnamed_addr constant [23 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [106 x i8], align 1
@__PRETTY_FUNCTION__._Z13base64_decodePKclPc = external hidden unnamed_addr constant [47 x i8], align 1
@_ZL11reverse_map = external hidden global [128 x i8], align 16
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1

; 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 noundef i64 @_Z13base64_decodePKclPc(ptr noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca [4 x i8], align 1
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = and i64 %11, 3
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %17

15:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 54, ptr noundef @__PRETTY_FUNCTION__._Z13base64_decodePKclPc) #3
  unreachable

16:                                               ; No predecessors!
  br label %17

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

18:                                               ; preds = %127, %17
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = icmp slt i64 %19, %20
  br i1 %21, label %22, label %130

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

23:                                               ; preds = %39, %22
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = icmp slt i64 %24, 4
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %42

27:                                               ; preds = %23
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = load i64, ptr %10, align 8, !tbaa !9
  %31 = add nsw i64 %29, %30
  %32 = getelementptr inbounds i8, ptr %28, i64 %31
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = sext i8 %33 to i64
  %35 = getelementptr inbounds [128 x i8], ptr @_ZL11reverse_map, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = load i64, ptr %10, align 8, !tbaa !9
  %38 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 %37
  store i8 %36, ptr %38, align 1, !tbaa !11
  br label %39

39:                                               ; preds = %27
  %40 = load i64, ptr %10, align 8, !tbaa !9
  %41 = add nsw i64 %40, 1
  store i64 %41, ptr %10, align 8, !tbaa !9
  br label %23, !llvm.loop !12

42:                                               ; preds = %26
  %43 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 0
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = sext i8 %44 to i32
  %46 = icmp slt i32 %45, 64
  br i1 %46, label %47, label %52

47:                                               ; preds = %42
  %48 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 1
  %49 = load i8, ptr %48, align 1, !tbaa !11
  %50 = sext i8 %49 to i32
  %51 = icmp slt i32 %50, 64
  br label %52

52:                                               ; preds = %47, %42
  %53 = phi i1 [ false, %42 ], [ %51, %47 ]
  br i1 %53, label %54, label %55

54:                                               ; preds = %52
  br label %57

55:                                               ; preds = %52
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 62, ptr noundef @__PRETTY_FUNCTION__._Z13base64_decodePKclPc) #3
  unreachable

56:                                               ; No predecessors!
  br label %57

57:                                               ; preds = %56, %54
  %58 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 0
  %59 = load i8, ptr %58, align 1, !tbaa !11
  %60 = sext i8 %59 to i32
  %61 = shl i32 %60, 2
  %62 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 1
  %63 = load i8, ptr %62, align 1, !tbaa !11
  %64 = sext i8 %63 to i32
  %65 = ashr i32 %64, 4
  %66 = or i32 %61, %65
  %67 = trunc i32 %66 to i8
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load i64, ptr %8, align 8, !tbaa !9
  %70 = add nsw i64 %69, 1
  store i64 %70, ptr %8, align 8, !tbaa !9
  %71 = getelementptr inbounds i8, ptr %68, i64 %69
  store i8 %67, ptr %71, align 1, !tbaa !11
  %72 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 2
  %73 = load i8, ptr %72, align 1, !tbaa !11
  %74 = sext i8 %73 to i32
  %75 = icmp sge i32 %74, 64
  br i1 %75, label %76, label %77

76:                                               ; preds = %57
  br label %130

77:                                               ; preds = %57
  %78 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 3
  %79 = load i8, ptr %78, align 1, !tbaa !11
  %80 = sext i8 %79 to i32
  %81 = icmp sge i32 %80, 64
  br i1 %81, label %82, label %97

82:                                               ; preds = %77
  %83 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 1
  %84 = load i8, ptr %83, align 1, !tbaa !11
  %85 = sext i8 %84 to i32
  %86 = shl i32 %85, 4
  %87 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 2
  %88 = load i8, ptr %87, align 1, !tbaa !11
  %89 = sext i8 %88 to i32
  %90 = ashr i32 %89, 2
  %91 = or i32 %86, %90
  %92 = trunc i32 %91 to i8
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = load i64, ptr %8, align 8, !tbaa !9
  %95 = add nsw i64 %94, 1
  store i64 %95, ptr %8, align 8, !tbaa !9
  %96 = getelementptr inbounds i8, ptr %93, i64 %94
  store i8 %92, ptr %96, align 1, !tbaa !11
  br label %130

97:                                               ; preds = %77
  %98 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 1
  %99 = load i8, ptr %98, align 1, !tbaa !11
  %100 = sext i8 %99 to i32
  %101 = shl i32 %100, 4
  %102 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 2
  %103 = load i8, ptr %102, align 1, !tbaa !11
  %104 = sext i8 %103 to i32
  %105 = ashr i32 %104, 2
  %106 = or i32 %101, %105
  %107 = trunc i32 %106 to i8
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = load i64, ptr %8, align 8, !tbaa !9
  %110 = add nsw i64 %109, 1
  store i64 %110, ptr %8, align 8, !tbaa !9
  %111 = getelementptr inbounds i8, ptr %108, i64 %109
  store i8 %107, ptr %111, align 1, !tbaa !11
  %112 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 2
  %113 = load i8, ptr %112, align 1, !tbaa !11
  %114 = sext i8 %113 to i32
  %115 = shl i32 %114, 6
  %116 = getelementptr inbounds [4 x i8], ptr %9, i64 0, i64 3
  %117 = load i8, ptr %116, align 1, !tbaa !11
  %118 = sext i8 %117 to i32
  %119 = or i32 %115, %118
  %120 = trunc i32 %119 to i8
  %121 = load ptr, ptr %6, align 8, !tbaa !5
  %122 = load i64, ptr %8, align 8, !tbaa !9
  %123 = add nsw i64 %122, 1
  store i64 %123, ptr %8, align 8, !tbaa !9
  %124 = getelementptr inbounds i8, ptr %121, i64 %122
  store i8 %120, ptr %124, align 1, !tbaa !11
  br label %125

125:                                              ; preds = %97
  br label %126

126:                                              ; preds = %125
  br label %127

127:                                              ; preds = %126
  %128 = load i64, ptr %7, align 8, !tbaa !9
  %129 = add nsw i64 %128, 4
  store i64 %129, ptr %7, align 8, !tbaa !9
  br label %18, !llvm.loop !14

130:                                              ; preds = %82, %76, %18
  %131 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i64 %131
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

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 = { noreturn 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 #3 = { noreturn nounwind }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple 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"}
!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"

@.str = external hidden unnamed_addr constant [23 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [106 x i8], align 1
@__PRETTY_FUNCTION__._Z13base64_decodePKclPc = external hidden unnamed_addr constant [47 x i8], align 1
@_ZL11reverse_map = external hidden local_unnamed_addr global [128 x i8], align 16
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z13base64_decodePKclPc(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = and i64 %1, 3
  %5 = icmp eq i64 %4, 0
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 54, ptr noundef nonnull @__PRETTY_FUNCTION__._Z13base64_decodePKclPc) #2
  unreachable

7:                                                ; preds = %3
  %8 = icmp sgt i64 %1, 0
  br i1 %8, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %7, %51
  %.01830 = phi i64 [ %55, %51 ], [ 0, %7 ]
  %.01929 = phi i64 [ %57, %51 ], [ 0, %7 ]
  %9 = getelementptr inbounds i8, ptr %0, i64 %.01929
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = sext i8 %10 to i64
  %12 = getelementptr inbounds [128 x i8], ptr @_ZL11reverse_map, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = or disjoint i64 %.01929, 1
  %15 = getelementptr inbounds i8, ptr %0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = sext i8 %16 to i64
  %18 = getelementptr inbounds [128 x i8], ptr @_ZL11reverse_map, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = or disjoint i64 %.01929, 2
  %21 = getelementptr inbounds i8, ptr %0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = sext i8 %22 to i64
  %24 = getelementptr inbounds [128 x i8], ptr @_ZL11reverse_map, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = or disjoint i64 %.01929, 3
  %27 = getelementptr inbounds i8, ptr %0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = sext i8 %28 to i64
  %30 = getelementptr inbounds [128 x i8], ptr @_ZL11reverse_map, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = icmp slt i8 %13, 64
  %33 = icmp slt i8 %19, 64
  %34 = select i1 %32, i1 %33, i1 false
  br i1 %34, label %36, label %35

35:                                               ; preds = %.preheader
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 62, ptr noundef nonnull @__PRETTY_FUNCTION__._Z13base64_decodePKclPc) #2
  unreachable

36:                                               ; preds = %.preheader
  %37 = shl i8 %13, 2
  %38 = ashr i8 %19, 4
  %39 = or i8 %38, %37
  %40 = add nuw nsw i64 %.01830, 1
  %41 = getelementptr inbounds i8, ptr %2, i64 %.01830
  store i8 %39, ptr %41, align 1, !tbaa !5
  %42 = icmp sgt i8 %25, 63
  br i1 %42, label %.loopexit, label %43

43:                                               ; preds = %36
  %44 = icmp sgt i8 %31, 63
  %45 = shl i8 %19, 4
  %46 = ashr i8 %25, 2
  %47 = or i8 %46, %45
  br i1 %44, label %48, label %51

48:                                               ; preds = %43
  %49 = add nuw nsw i64 %.01830, 2
  %50 = getelementptr inbounds i8, ptr %2, i64 %40
  store i8 %47, ptr %50, align 1, !tbaa !5
  br label %.loopexit

51:                                               ; preds = %43
  %52 = getelementptr inbounds i8, ptr %2, i64 %40
  store i8 %47, ptr %52, align 1, !tbaa !5
  %53 = shl i8 %25, 6
  %54 = or i8 %31, %53
  %55 = add nuw nsw i64 %.01830, 3
  %56 = getelementptr inbounds i8, ptr %41, i64 2
  store i8 %54, ptr %56, align 1, !tbaa !5
  %57 = add nuw nsw i64 %.01929, 4
  %58 = icmp slt i64 %57, %1
  br i1 %58, label %.preheader, label %.loopexit, !llvm.loop !8

.loopexit:                                        ; preds = %51, %36, %7, %48
  %.1 = phi i64 [ %49, %48 ], [ 0, %7 ], [ %55, %51 ], [ %40, %36 ]
  ret i64 %.1
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { noreturn 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 #2 = { noreturn 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++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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