; LLVM IR from Mohammed-Shoaib/Coding-Problems :: Codeforces/Solutions/1373E.ll (Z9constructi)

; 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 @_Z9constructi(i32 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = icmp sle i32 %5, 8
  br i1 %6, label %7, label %10

7:                                                ; preds = %1
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  store i64 %9, ptr %2, align 8
  br label %34

10:                                               ; preds = %1
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sub nsw i32 %11, 8
  store i32 %12, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = srem i32 %13, 9
  %15 = sext i32 %14 to i64
  store i64 %15, ptr %4, align 8, !tbaa !9
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = srem i32 %16, 9
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sub nsw i32 %18, %17
  store i32 %19, ptr %3, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %23, %10
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %20
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = mul nsw i64 10, %24
  %26 = add nsw i64 %25, 9
  store i64 %26, ptr %4, align 8, !tbaa !9
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sub nsw i32 %27, 9
  store i32 %28, ptr %3, align 4, !tbaa !5
  br label %20, !llvm.loop !11

29:                                               ; preds = %20
  %30 = load i64, ptr %4, align 8, !tbaa !9
  %31 = mul nsw i64 10, %30
  %32 = add nsw i64 %31, 8
  store i64 %32, ptr %4, align 8, !tbaa !9
  %33 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %33, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %34

34:                                               ; preds = %29, %7
  %35 = load i64, ptr %2, align 8
  ret i64 %35
}

; 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i64 @_Z9constructi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i32 %0, 9
  br i1 %2, label %3, label %5

3:                                                ; preds = %1
  %4 = sext i32 %0 to i64
  br label %22

5:                                                ; preds = %1
  %6 = add nsw i32 %0, -8
  %7 = urem i32 %6, 9
  %8 = zext nneg i32 %7 to i64
  %9 = sub nuw nsw i32 %6, %7
  %.not15 = icmp eq i32 %9, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %10 = add i32 %9, -9
  %11 = udiv i32 %10, 9
  %12 = add nuw nsw i32 %11, 1
  %xtraiter = and i32 %12, 7
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.017.prol = phi i64 [ %14, %.lr.ph.prol ], [ %8, %.lr.ph.preheader ]
  %.01216.prol = phi i32 [ %15, %.lr.ph.prol ], [ %9, %.lr.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %13 = mul nsw i64 %.017.prol, 10
  %14 = add nsw i64 %13, 9
  %15 = add nsw i32 %.01216.prol, -9
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !5

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa.unr = phi i64 [ poison, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %.017.unr = phi i64 [ %8, %.lr.ph.preheader ], [ %14, %.lr.ph.prol ]
  %.01216.unr = phi i32 [ %9, %.lr.ph.preheader ], [ %15, %.lr.ph.prol ]
  %16 = icmp ult i32 %10, 63
  br i1 %16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.017 = phi i64 [ %18, %.lr.ph ], [ %.017.unr, %.lr.ph.prol.loopexit ]
  %.01216 = phi i32 [ %19, %.lr.ph ], [ %.01216.unr, %.lr.ph.prol.loopexit ]
  %17 = mul i64 %.017, 100000000
  %18 = add i64 %17, 99999999
  %19 = add nsw i32 %.01216, -72
  %.not.7 = icmp eq i32 %19, 0
  br i1 %.not.7, label %._crit_edge, label %.lr.ph, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %5
  %.0.lcssa = phi i64 [ %8, %5 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %18, %.lr.ph ]
  %20 = mul nsw i64 %.0.lcssa, 10
  %21 = add nsw i64 %20, 8
  br label %22

22:                                               ; preds = %._crit_edge, %3
  %.013 = phi i64 [ %4, %3 ], [ %21, %._crit_edge ]
  ret i64 %.013
}

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.unroll.disable"}
!7 = distinct !{!7, !8}
!8 = !{!"llvm.loop.mustprogress"}


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