; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 01. Mathematics/21_Binary To Octal.ll (Z8BinToOctx)

; 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: mustprogress uwtable
define dso_local noundef i32 @_Z8BinToOctx(i64 noundef %0) #1 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %9, %1
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = icmp ne i64 %7, 0
  br i1 %8, label %9, label %23

9:                                                ; preds = %6
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = srem i64 %10, 10
  %12 = sitofp i64 %11 to double
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = call noundef double @_ZSt3powIiiEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef 2, i32 noundef %13)
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sitofp i32 %15 to double
  %17 = call double @llvm.fmuladd.f64(double %12, double %14, double %16)
  %18 = fptosi double %17 to i32
  store i32 %18, ptr %4, align 4, !tbaa !9
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %5, align 4, !tbaa !9
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = sdiv i64 %21, 10
  store i64 %22, ptr %2, align 8, !tbaa !5
  br label %6, !llvm.loop !11

23:                                               ; preds = %6
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %27, %23
  %25 = load i32, ptr %4, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %38

27:                                               ; preds = %24
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = srem i32 %28, 8
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = mul nsw i32 %29, %30
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = add nsw i32 %32, %31
  store i32 %33, ptr %3, align 4, !tbaa !9
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = sdiv i32 %34, 8
  store i32 %35, ptr %4, align 4, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = mul nsw i32 %36, 10
  store i32 %37, ptr %5, align 4, !tbaa !9
  br label %24, !llvm.loop !13

38:                                               ; preds = %24
  %39 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %39
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3powIiiEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 nounwind uwtable
define dso_local noundef i32 @_Z8BinToOctx(i64 noundef %0) local_unnamed_addr #0 {
  %.not18 = icmp eq i64 %0, 0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %.not1722 = icmp eq i32 %7, 0
  br i1 %.not1722, label %._crit_edge, label %.lr.ph26

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.021 = phi i32 [ %8, %.lr.ph ], [ 0, %1 ]
  %.01320 = phi i32 [ %7, %.lr.ph ], [ 0, %1 ]
  %.01619 = phi i64 [ %9, %.lr.ph ], [ %0, %1 ]
  %2 = srem i64 %.01619, 10
  %3 = sitofp i64 %2 to double
  %4 = tail call noundef double @_ZSt3powIiiEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef 2, i32 noundef %.021)
  %5 = sitofp i32 %.01320 to double
  %6 = tail call double @llvm.fmuladd.f64(double %3, double %4, double %5)
  %7 = fptosi double %6 to i32
  %8 = add nuw nsw i32 %.021, 1
  %9 = sdiv i64 %.01619, 10
  %.01619.off = add i64 %.01619, 9
  %.not = icmp ult i64 %.01619.off, 19
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !5

.lr.ph26:                                         ; preds = %.preheader, %.lr.ph26
  %.125 = phi i32 [ %14, %.lr.ph26 ], [ 1, %.preheader ]
  %.11424 = phi i32 [ %13, %.lr.ph26 ], [ %7, %.preheader ]
  %.01523 = phi i32 [ %12, %.lr.ph26 ], [ 0, %.preheader ]
  %10 = srem i32 %.11424, 8
  %11 = mul nsw i32 %10, %.125
  %12 = add nsw i32 %11, %.01523
  %13 = sdiv i32 %.11424, 8
  %14 = mul nuw nsw i32 %.125, 10
  %.11424.off = add i32 %.11424, 7
  %.not17 = icmp ult i32 %.11424.off, 15
  br i1 %.not17, label %._crit_edge, label %.lr.ph26, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph26, %1, %.preheader
  %.015.lcssa = phi i32 [ 0, %.preheader ], [ 0, %1 ], [ %12, %.lr.ph26 ]
  ret i32 %.015.lcssa
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3powIiiEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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 = { inlinehint 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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