; LLVM IR from DionysiosB/CodeForces :: 0001-0099/75A-LifeWithoutZeros.ll (Z7convertx)

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

5:                                                ; preds = %18, %1
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = icmp sgt i64 %6, 0
  br i1 %7, label %8, label %21

8:                                                ; preds = %5
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = srem i64 %9, 10
  %11 = icmp ne i64 %10, 0
  br i1 %11, label %12, label %18

12:                                               ; preds = %8
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = mul nsw i64 10, %13
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = srem i64 %15, 10
  %17 = add nsw i64 %14, %16
  store i64 %17, ptr %3, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %12, %8
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = sdiv i64 %19, 10
  store i64 %20, ptr %2, align 8, !tbaa !5
  br label %5, !llvm.loop !9

21:                                               ; preds = %5
  br label %22

22:                                               ; preds = %25, %21
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = icmp sgt i64 %23, 0
  br i1 %24, label %25, label %33

25:                                               ; preds = %22
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = mul nsw i64 10, %26
  %28 = load i64, ptr %3, align 8, !tbaa !5
  %29 = srem i64 %28, 10
  %30 = add nsw i64 %27, %29
  store i64 %30, ptr %4, align 8, !tbaa !5
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = sdiv i64 %31, 10
  store i64 %32, ptr %3, align 8, !tbaa !5
  br label %22, !llvm.loop !11

33:                                               ; preds = %22
  %34 = load i64, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i64 %34
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; 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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i64 @_Z7convertx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp sgt i64 %0, 0
  br i1 %2, label %.lr.ph, label %._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %3 = icmp sgt i64 %.1, 0
  br i1 %3, label %.lr.ph17, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.01014 = phi i64 [ %.1, %.lr.ph ], [ 0, %1 ]
  %.01113 = phi i64 [ %7, %.lr.ph ], [ %0, %1 ]
  %4 = urem i64 %.01113, 10
  %.not = icmp eq i64 %4, 0
  %5 = mul nsw i64 %.01014, 10
  %6 = add nsw i64 %5, %4
  %.1 = select i1 %.not, i64 %.01014, i64 %6
  %7 = udiv i64 %.01113, 10
  %.not19 = icmp ult i64 %.01113, 10
  br i1 %.not19, label %.preheader, label %.lr.ph, !llvm.loop !5

.lr.ph17:                                         ; preds = %.preheader, %.lr.ph17
  %.016 = phi i64 [ %10, %.lr.ph17 ], [ 0, %.preheader ]
  %.215 = phi i64 [ %11, %.lr.ph17 ], [ %.1, %.preheader ]
  %8 = mul nsw i64 %.016, 10
  %9 = urem i64 %.215, 10
  %10 = add nsw i64 %8, %9
  %11 = udiv i64 %.215, 10
  %.not20 = icmp ult i64 %.215, 10
  br i1 %.not20, label %._crit_edge, label %.lr.ph17, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph17, %1, %.preheader
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ 0, %1 ], [ %10, %.lr.ph17 ]
  ret i64 %.0.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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