; LLVM IR from DionysiosB/CodeForces :: 0100-0199 (109A-LuckySumOfDigits)

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

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 0, ptr %2, align 8, !tbaa !5
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 -1, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 -1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 1000000, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = sdiv i64 %12, 7
  store i64 %13, ptr %6, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %37, %0
  %15 = load i64, ptr %6, align 8, !tbaa !5
  %16 = icmp sge i64 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 2, ptr %7, align 4
  br label %40

18:                                               ; preds = %14
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = mul nsw i64 7, %20
  %22 = sub nsw i64 %19, %21
  %23 = srem i64 %22, 4
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %18
  br label %37

26:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = load i64, ptr %6, align 8, !tbaa !5
  %29 = mul nsw i64 7, %28
  %30 = sub nsw i64 %27, %29
  %31 = sdiv i64 %30, 4
  store i64 %31, ptr %8, align 8, !tbaa !5
  %32 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %32, ptr %3, align 8, !tbaa !5
  %33 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %33, ptr %4, align 8, !tbaa !5
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = load i64, ptr %4, align 8, !tbaa !5
  %36 = add nsw i64 %34, %35
  store i64 %36, ptr %5, align 8, !tbaa !5
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %40

37:                                               ; preds = %25
  %38 = load i64, ptr %6, align 8, !tbaa !5
  %39 = add nsw i64 %38, -1
  store i64 %39, ptr %6, align 8, !tbaa !5
  br label %14, !llvm.loop !9

40:                                               ; preds = %26, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = icmp sge i64 %42, 0
  br i1 %43, label %44, label %72

44:                                               ; preds = %41
  %45 = load i64, ptr %4, align 8, !tbaa !5
  %46 = icmp sge i64 %45, 0
  br i1 %46, label %47, label %72

47:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %48

48:                                               ; preds = %56, %47
  %49 = load i32, ptr %9, align 4, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = load i64, ptr %4, align 8, !tbaa !5
  %52 = icmp slt i64 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %48
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %59

54:                                               ; preds = %48
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %56

56:                                               ; preds = %54
  %57 = load i32, ptr %9, align 4, !tbaa !11
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %9, align 4, !tbaa !11
  br label %48, !llvm.loop !13

59:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %60

60:                                               ; preds = %68, %59
  %61 = load i32, ptr %10, align 4, !tbaa !11
  %62 = sext i32 %61 to i64
  %63 = load i64, ptr %3, align 8, !tbaa !5
  %64 = icmp slt i64 %62, %63
  br i1 %64, label %66, label %65

65:                                               ; preds = %60
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %71

66:                                               ; preds = %60
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %68

68:                                               ; preds = %66
  %69 = load i32, ptr %10, align 4, !tbaa !11
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %10, align 4, !tbaa !11
  br label %60, !llvm.loop !14

71:                                               ; preds = %65
  br label %74

72:                                               ; preds = %44, %41
  %73 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %74

74:                                               ; preds = %72, %71
  %75 = call i32 @puts(ptr noundef @.str.4)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %76 = load i32, ptr %1, align 4
  ret i32 %76
}

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

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

declare i32 @printf(ptr noundef, ...) #2

declare i32 @puts(ptr noundef) #2

attributes #0 = { mustprogress norecurse 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 = { "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 = { 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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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"

@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  store i64 0, ptr %1, align 8, !tbaa !5
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, -7
  br i1 %4, label %.lr.ph.preheader, label %.thread

.lr.ph.preheader:                                 ; preds = %0
  %5 = sdiv i64 %3, 7
  %.neg = mul i64 %5, -7
  %6 = add i64 %.neg, %3
  %7 = and i64 %6, 3
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %23, label %8

8:                                                ; preds = %.lr.ph.preheader
  %9 = icmp sgt i64 %3, 6
  br i1 %9, label %.lr.ph.1, label %.thread, !llvm.loop !9

.lr.ph.1:                                         ; preds = %8
  %10 = add nsw i64 %5, -1
  %.neg.1 = mul i64 %10, -7
  %11 = add i64 %.neg.1, %3
  %12 = and i64 %11, 3
  %.not.1 = icmp eq i64 %12, 0
  br i1 %.not.1, label %23, label %13

13:                                               ; preds = %.lr.ph.1
  %14 = icmp sgt i64 %3, 13
  br i1 %14, label %.lr.ph.2, label %.thread, !llvm.loop !9

.lr.ph.2:                                         ; preds = %13
  %15 = add nsw i64 %5, -2
  %.neg.2 = mul i64 %15, -7
  %16 = add i64 %.neg.2, %3
  %17 = and i64 %16, 3
  %.not.2 = icmp eq i64 %17, 0
  br i1 %.not.2, label %23, label %18

18:                                               ; preds = %.lr.ph.2
  %19 = icmp sgt i64 %3, 20
  br i1 %19, label %.lr.ph.3, label %.thread, !llvm.loop !9

.lr.ph.3:                                         ; preds = %18
  %20 = add nsw i64 %5, -3
  %.neg.3 = mul i64 %20, -7
  %21 = add i64 %.neg.3, %3
  %22 = and i64 %21, 3
  %.not.3 = icmp eq i64 %22, 0
  br i1 %.not.3, label %23, label %.thread

23:                                               ; preds = %.lr.ph.3, %.lr.ph.2, %.lr.ph.1, %.lr.ph.preheader
  %.01927.lcssa = phi i64 [ %5, %.lr.ph.preheader ], [ %10, %.lr.ph.1 ], [ %15, %.lr.ph.2 ], [ %20, %.lr.ph.3 ]
  %.lcssa = phi i64 [ %6, %.lr.ph.preheader ], [ %11, %.lr.ph.1 ], [ %16, %.lr.ph.2 ], [ %21, %.lr.ph.3 ]
  %24 = ashr exact i64 %.lcssa, 2
  %25 = icmp sgt i64 %24, -1
  br i1 %25, label %.preheader25, label %.thread

.preheader25:                                     ; preds = %23
  %.not32 = icmp eq i64 %.lcssa, 0
  br i1 %.not32, label %.preheader, label %.lr.ph29.preheader

.lr.ph29.preheader:                               ; preds = %.preheader25
  %umax = call i64 @llvm.umax.i64(i64 %24, i64 1)
  br label %.lr.ph29

.preheader:                                       ; preds = %.lr.ph29, %.preheader25
  %26 = icmp sgt i64 %.01927.lcssa, 0
  br i1 %26, label %.lr.ph31, label %.loopexit

.lr.ph29:                                         ; preds = %.lr.ph29.preheader, %.lr.ph29
  %indvars.iv = phi i64 [ 0, %.lr.ph29.preheader ], [ %indvars.iv.next, %.lr.ph29 ]
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %indvars.iv.next = add nuw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %umax
  br i1 %exitcond.not, label %.preheader, label %.lr.ph29, !llvm.loop !11

.lr.ph31:                                         ; preds = %.preheader, %.lr.ph31
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %.lr.ph31 ], [ 0, %.preheader ]
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %29 = icmp sgt i64 %.01927.lcssa, %indvars.iv.next37
  br i1 %29, label %.lr.ph31, label %.loopexit, !llvm.loop !12

.thread:                                          ; preds = %8, %13, %18, %.lr.ph.3, %0, %23
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph31, %.preheader, %.thread
  %31 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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

attributes #0 = { mustprogress nofree norecurse 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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", !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}
!12 = distinct !{!12, !10}


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