; LLVM IR from ohler55/ox :: ext/ox (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
define dso_local i64 @b64_orig_size(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %5, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store i64 0, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = load i8, ptr %6, align 1, !tbaa !11
  %8 = sext i8 %7 to i32
  %9 = icmp ne i32 0, %8
  br i1 %9, label %10, label %48

10:                                               ; preds = %1
  br label %11

11:                                               ; preds = %17, %10
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = sext i8 %13 to i32
  %15 = icmp ne i32 0, %14
  br i1 %15, label %16, label %20

16:                                               ; preds = %11
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i32 1
  store ptr %19, ptr %2, align 8, !tbaa !5
  br label %11, !llvm.loop !12

20:                                               ; preds = %11
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = ptrtoint ptr %21 to i64
  %24 = ptrtoint ptr %22 to i64
  %25 = sub i64 %23, %24
  %26 = mul nsw i64 %25, 3
  %27 = sdiv i64 %26, 4
  store i64 %27, ptr %4, align 8, !tbaa !9
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i32 -1
  store ptr %29, ptr %2, align 8, !tbaa !5
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 61, %32
  br i1 %33, label %34, label %47

34:                                               ; preds = %20
  %35 = load i64, ptr %4, align 8, !tbaa !9
  %36 = add i64 %35, -1
  store i64 %36, ptr %4, align 8, !tbaa !9
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i32 -1
  store ptr %38, ptr %2, align 8, !tbaa !5
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = sext i8 %40 to i32
  %42 = icmp eq i32 61, %41
  br i1 %42, label %43, label %46

43:                                               ; preds = %34
  %44 = load i64, ptr %4, align 8, !tbaa !9
  %45 = add i64 %44, -1
  store i64 %45, ptr %4, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %43, %34
  br label %47

47:                                               ; preds = %46, %20
  br label %48

48:                                               ; preds = %47, %1
  %49 = load i64, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i64 %49
}

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 }

!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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local range(i64 -2305843009213693954, 2305843009213693952) i64 @b64_orig_size(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %16, label %.preheader

.preheader:                                       ; preds = %1, %.preheader
  %.01214 = phi ptr [ %3, %.preheader ], [ %0, %1 ]
  %3 = getelementptr inbounds i8, ptr %.01214, i64 1
  %.pr = load i8, ptr %3, align 1, !tbaa !5
  %.not13 = icmp eq i8 %.pr, 0
  br i1 %.not13, label %4, label %.preheader, !llvm.loop !8

4:                                                ; preds = %.preheader
  %5 = ptrtoint ptr %3 to i64
  %6 = ptrtoint ptr %0 to i64
  %7 = sub i64 %5, %6
  %8 = mul nsw i64 %7, 3
  %9 = sdiv i64 %8, 4
  %10 = load i8, ptr %.01214, align 1, !tbaa !5
  %11 = icmp eq i8 %10, 61
  br i1 %11, label %12, label %16

12:                                               ; preds = %4
  %13 = getelementptr inbounds i8, ptr %.01214, i64 -1
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = icmp eq i8 %14, 61
  %spec.select.v = select i1 %15, i64 -2, i64 -1
  %spec.select = add nsw i64 %spec.select.v, %9
  br label %16

16:                                               ; preds = %12, %4, %1
  %.0 = phi i64 [ %9, %4 ], [ 0, %1 ], [ %spec.select, %12 ]
  ret i64 %.0
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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