; LLVM IR from DionysiosB/CodeForces :: 0600-0699 (681B-EconomyGame)

; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 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 i8, align 1
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  store i8 0, ptr %3, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %50, %0
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = mul nsw i64 %10, 1234567
  %12 = load i64, ptr %2, align 8, !tbaa !9
  %13 = icmp sle i64 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  store i32 2, ptr %5, align 4
  br label %53

15:                                               ; preds = %9
  %16 = load i8, ptr %3, align 1, !tbaa !5, !range !11, !noundef !12
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store i32 2, ptr %5, align 4
  br label %53

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %45, %19
  %21 = load i64, ptr %4, align 8, !tbaa !9
  %22 = mul nsw i64 %21, 1234567
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = mul nsw i64 %23, 123456
  %25 = add nsw i64 %22, %24
  %26 = load i64, ptr %2, align 8, !tbaa !9
  %27 = icmp sle i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %20
  store i32 5, ptr %5, align 4
  br label %48

29:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %30 = load i64, ptr %2, align 8, !tbaa !9
  %31 = load i64, ptr %4, align 8, !tbaa !9
  %32 = mul nsw i64 %31, 1234567
  %33 = sub nsw i64 %30, %32
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = mul nsw i64 %34, 123456
  %36 = sub nsw i64 %33, %35
  store i64 %36, ptr %7, align 8, !tbaa !9
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = srem i64 %37, 1234
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %29
  store i8 1, ptr %3, align 1, !tbaa !5
  store i32 5, ptr %5, align 4
  br label %42

41:                                               ; preds = %29
  store i32 0, ptr %5, align 4
  br label %42

42:                                               ; preds = %41, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %43 = load i32, ptr %5, align 4
  switch i32 %43, label %48 [
    i32 0, label %44
  ]

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %6, align 8, !tbaa !9
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %6, align 8, !tbaa !9
  br label %20, !llvm.loop !13

48:                                               ; preds = %42, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load i64, ptr %4, align 8, !tbaa !9
  %52 = add nsw i64 %51, 1
  store i64 %52, ptr %4, align 8, !tbaa !9
  br label %9, !llvm.loop !15

53:                                               ; preds = %18, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %54

54:                                               ; preds = %53
  %55 = load i8, ptr %3, align 1, !tbaa !5, !range !11, !noundef !12
  %56 = trunc i8 %55 to i1
  %57 = zext i1 %56 to i64
  %58 = select i1 %56, ptr @.str.1, ptr @.str.2
  %59 = call i32 @puts(ptr noundef %58)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %60 = load i32, ptr %1, align 4
  ret i32 %60
}

; 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 @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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 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) #3
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %.not23 = icmp slt i64 %3, 0
  br i1 %.not23, label %._crit_edge28, label %.lr.ph27

.lr.ph27:                                         ; preds = %0, %._crit_edge
  %4 = phi i64 [ %14, %._crit_edge ], [ 0, %0 ]
  %.01325 = phi i64 [ %13, %._crit_edge ], [ 0, %0 ]
  %.01424 = phi i8 [ %.3.ph, %._crit_edge ], [ 0, %0 ]
  %5 = trunc nuw i8 %.01424 to i1
  br i1 %5, label %._crit_edge28.loopexit, label %.lr.ph

6:                                                ; preds = %.lr.ph
  %7 = add nuw nsw i64 %.020, 1
  %8 = mul nuw nsw i64 %7, 123456
  %9 = add nuw nsw i64 %8, %4
  %.not17 = icmp sgt i64 %9, %3
  br i1 %.not17, label %._crit_edge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph27, %6
  %10 = phi i64 [ %9, %6 ], [ %4, %.lr.ph27 ]
  %.020 = phi i64 [ %7, %6 ], [ 0, %.lr.ph27 ]
  %11 = sub i64 %3, %10
  %12 = srem i64 %11, 1234
  %.not18 = icmp eq i64 %12, 0
  br i1 %.not18, label %._crit_edge, label %6

._crit_edge:                                      ; preds = %.lr.ph, %6
  %.3.ph = phi i8 [ 1, %.lr.ph ], [ %.01424, %6 ]
  %13 = add nuw nsw i64 %.01325, 1
  %14 = mul nuw nsw i64 %13, 1234567
  %.not = icmp sgt i64 %14, %3
  br i1 %.not, label %._crit_edge28.loopexit, label %.lr.ph27, !llvm.loop !11

._crit_edge28.loopexit:                           ; preds = %.lr.ph27, %._crit_edge
  %.014.lcssa.ph = phi i8 [ %.3.ph, %._crit_edge ], [ %.01424, %.lr.ph27 ]
  %15 = trunc nuw i8 %.014.lcssa.ph to i1
  %16 = select i1 %15, ptr @.str.1, ptr @.str.2
  br label %._crit_edge28

._crit_edge28:                                    ; preds = %._crit_edge28.loopexit, %0
  %.014.lcssa = phi ptr [ @.str.2, %0 ], [ %16, %._crit_edge28.loopexit ]
  %17 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %.014.lcssa)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  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 @puts(ptr nocapture noundef readonly) local_unnamed_addr #2

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 = { 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}


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