; LLVM IR from lelegard/cryptobench :: src/sys.ll (ZN3sys13base64_decodeERSt6vectorIhSaIhEEPKvm)

; 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 willreturn memory(read)
declare i32 @isspace(i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3sys13base64_decodeERSt6vectorIhSaIhEEPKvm(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef %1, i64 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca [4 x i8], align 1
  %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
  store i64 %2, ptr %6, align 8, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZNSt6vectorIhSaIhEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %16, label %13

13:                                               ; preds = %3
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %13, %3
  br label %60

17:                                               ; preds = %13
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = mul i64 %19, 3
  %21 = udiv i64 %20, 4
  call void @_ZNSt6vectorIhSaIhEE7reserveEm(ptr noundef nonnull align 8 dereferenceable(24) %18, i64 noundef %21)
  call void @llvm.lifetime.start.p0(i64 4, 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 8, ptr %9) #4
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %22, ptr %9, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %52, %17
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = icmp ugt i64 %24, 0
  br i1 %25, label %26, label %56

26:                                               ; preds = %23
  br label %27

27:                                               ; preds = %47, %26
  %28 = load i64, ptr %8, align 8, !tbaa !9
  %29 = icmp ult i64 %28, 4
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = icmp ugt i64 %31, 0
  br label %33

33:                                               ; preds = %30, %27
  %34 = phi i1 [ false, %27 ], [ %32, %30 ]
  br i1 %34, label %35, label %52

35:                                               ; preds = %33
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = call i32 @isspace(i32 noundef %38) #5
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %47, label %41

41:                                               ; preds = %35
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %8, align 8, !tbaa !9
  %46 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 %44
  store i8 %43, ptr %46, align 1, !tbaa !11
  br label %47

47:                                               ; preds = %41, %35
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %9, align 8, !tbaa !5
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = add i64 %50, -1
  store i64 %51, ptr %6, align 8, !tbaa !9
  br label %27, !llvm.loop !12

52:                                               ; preds = %33
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  %55 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZN12_GLOBAL__N_113base64_updateERSt6vectorIhSaIhEEPKcm(ptr noundef nonnull align 8 dereferenceable(24) %53, ptr noundef %54, i64 noundef %55)
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %23, !llvm.loop !14

56:                                               ; preds = %23
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  %59 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZN12_GLOBAL__N_113base64_updateERSt6vectorIhSaIhEEPKcm(ptr noundef nonnull align 8 dereferenceable(24) %57, ptr noundef %58, i64 noundef %59)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %60

60:                                               ; preds = %56, %16
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEE7reserveEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN12_GLOBAL__N_113base64_updateERSt6vectorIhSaIhEEPKcm(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 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 #3 = { mustprogress 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

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

; 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: mustprogress nofree nounwind willreturn memory(read)
declare i32 @isspace(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3sys13base64_decodeERSt6vectorIhSaIhEEPKvm(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef readonly %1, i64 noundef %2) local_unnamed_addr #3 {
  %4 = alloca [4 x i8], align 1
  tail call void @_ZNSt6vectorIhSaIhEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  %5 = icmp eq ptr %1, null
  %6 = icmp eq i64 %2, 0
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %24, label %7

7:                                                ; preds = %3
  %8 = mul i64 %2, 3
  %9 = lshr i64 %8, 2
  tail call void @_ZNSt6vectorIhSaIhEE7reserveEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %9)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  br label %.preheader

.preheader:                                       ; preds = %.preheader.backedge, %7
  %.127 = phi ptr [ %1, %7 ], [ %17, %.preheader.backedge ]
  %.11926 = phi i64 [ 0, %7 ], [ %.11926.be, %.preheader.backedge ]
  %.12125 = phi i64 [ %2, %7 ], [ %18, %.preheader.backedge ]
  %10 = load i8, ptr %.127, align 1, !tbaa !5
  %11 = sext i8 %10 to i32
  %12 = call i32 @isspace(i32 noundef %11) #5
  %.not24 = icmp eq i32 %12, 0
  br i1 %.not24, label %13, label %16

13:                                               ; preds = %.preheader
  %14 = add nuw nsw i64 %.11926, 1
  %15 = getelementptr inbounds [4 x i8], ptr %4, i64 0, i64 %.11926
  store i8 %10, ptr %15, align 1, !tbaa !5
  br label %16

16:                                               ; preds = %13, %.preheader
  %.2 = phi i64 [ %.11926, %.preheader ], [ %14, %13 ]
  %17 = getelementptr inbounds i8, ptr %.127, i64 1
  %18 = add i64 %.12125, -1
  %19 = icmp ult i64 %.2, 4
  %20 = icmp ne i64 %18, 0
  %21 = select i1 %19, i1 %20, i1 false
  br i1 %21, label %.preheader.backedge, label %22

.preheader.backedge:                              ; preds = %16, %22
  %.11926.be = phi i64 [ %.2, %16 ], [ 0, %22 ]
  br label %.preheader, !llvm.loop !8

22:                                               ; preds = %16
  call void @_ZN12_GLOBAL__N_113base64_updateERSt6vectorIhSaIhEEPKcm(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %4, i64 noundef %.2)
  %.not = icmp eq i64 %18, 0
  br i1 %.not, label %23, label %.preheader.backedge

23:                                               ; preds = %22
  call void @_ZN12_GLOBAL__N_113base64_updateERSt6vectorIhSaIhEEPKcm(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull %4, i64 noundef 0)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  br label %24

24:                                               ; preds = %3, %23
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEE7reserveEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN12_GLOBAL__N_113base64_updateERSt6vectorIhSaIhEEPKcm(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(read) "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 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 #3 = { mustprogress 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass