; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 996A. Hit the Lottery (main)

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

@__const.main.arr = external hidden unnamed_addr constant [5 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [5 x i32], align 16
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 20, ptr %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %2, ptr align 16 @__const.main.arr, i64 20, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  br label %6

6:                                                ; preds = %56, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %8 = icmp ne i32 %7, -1
  br i1 %8, label %9, label %59

9:                                                ; preds = %6
  store i32 0, ptr %5, align 4, !tbaa !5
  store i32 4, ptr %4, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %53, %9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp sge i32 %11, 0
  br i1 %12, label %13, label %56

13:                                               ; preds = %10
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [5 x i32], ptr %2, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp sge i32 %14, %18
  br i1 %19, label %20, label %52

20:                                               ; preds = %13
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [5 x i32], ptr %2, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sdiv i32 %21, %25
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = add nsw i32 %27, %26
  store i32 %28, ptr %5, align 4, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [5 x i32], ptr %2, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = srem i32 %29, %33
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %20
  br label %56

37:                                               ; preds = %20
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [5 x i32], ptr %2, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sdiv i32 %38, %42
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [5 x i32], ptr %2, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = mul nsw i32 %43, %47
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = sub nsw i32 %49, %48
  store i32 %50, ptr %3, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %37
  br label %52

52:                                               ; preds = %51, %13
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %4, align 4, !tbaa !5
  br label %10, !llvm.loop !9

56:                                               ; preds = %36, %10
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %57)
  br label %6, !llvm.loop !11

59:                                               ; preds = %6
  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
  call void @llvm.lifetime.end.p0(i64 20, ptr %2) #4
  ret i32 0
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #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 = !{!"int", !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"

@__const.main.arr = external hidden unnamed_addr constant [5 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not15 = icmp eq i32 %2, -1
  br i1 %.not15, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %0
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.arr, i64 16), align 16, !tbaa !5
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.arr, i64 12), align 4
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.arr, i64 8), align 8
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.arr, i64 4), align 4
  %6 = load i32, ptr @__const.main.arr, align 16
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %49
  %.promoted = load i32, ptr %1, align 4, !tbaa !5
  %.not12 = icmp slt i32 %.promoted, %.pre
  br i1 %.not12, label %13, label %7

7:                                                ; preds = %.preheader
  %8 = sdiv i32 %.promoted, %.pre
  %.recomposed = srem i32 %.promoted, %.pre
  %9 = srem i32 %.promoted, %.pre
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %49, label %11

11:                                               ; preds = %7
  %12 = mul nsw i32 %8, %.pre
  store i32 %.recomposed, ptr %1, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %.preheader, %11
  %14 = phi i32 [ %.recomposed, %11 ], [ %.promoted, %.preheader ]
  %.1 = phi i32 [ %8, %11 ], [ 0, %.preheader ]
  %.not12.1 = icmp slt i32 %14, %3
  br i1 %.not12.1, label %22, label %15

15:                                               ; preds = %13
  %16 = sdiv i32 %14, %3
  %.recomposed17 = srem i32 %14, %3
  %17 = add nsw i32 %16, %.1
  %18 = srem i32 %14, %3
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %49, label %20

20:                                               ; preds = %15
  %21 = mul nsw i32 %16, %3
  store i32 %.recomposed17, ptr %1, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %20, %13
  %23 = phi i32 [ %.recomposed17, %20 ], [ %14, %13 ]
  %.1.1 = phi i32 [ %17, %20 ], [ %.1, %13 ]
  %.not12.2 = icmp slt i32 %23, %4
  br i1 %.not12.2, label %31, label %24

24:                                               ; preds = %22
  %25 = sdiv i32 %23, %4
  %.recomposed18 = srem i32 %23, %4
  %26 = add nsw i32 %25, %.1.1
  %27 = srem i32 %23, %4
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %49, label %29

29:                                               ; preds = %24
  %30 = mul nsw i32 %25, %4
  store i32 %.recomposed18, ptr %1, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %29, %22
  %32 = phi i32 [ %.recomposed18, %29 ], [ %23, %22 ]
  %.1.2 = phi i32 [ %26, %29 ], [ %.1.1, %22 ]
  %.not12.3 = icmp slt i32 %32, %5
  br i1 %.not12.3, label %40, label %33

33:                                               ; preds = %31
  %34 = sdiv i32 %32, %5
  %.recomposed19 = srem i32 %32, %5
  %35 = add nsw i32 %34, %.1.2
  %36 = srem i32 %32, %5
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %49, label %38

38:                                               ; preds = %33
  %39 = mul nsw i32 %34, %5
  store i32 %.recomposed19, ptr %1, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %38, %31
  %41 = phi i32 [ %.recomposed19, %38 ], [ %32, %31 ]
  %.1.3 = phi i32 [ %35, %38 ], [ %.1.2, %31 ]
  %.not12.4 = icmp slt i32 %41, %6
  br i1 %.not12.4, label %49, label %42

42:                                               ; preds = %40
  %43 = sdiv i32 %41, %6
  %.recomposed20 = srem i32 %41, %6
  %44 = add nsw i32 %43, %.1.3
  %45 = srem i32 %41, %6
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %49, label %47

47:                                               ; preds = %42
  %48 = mul nsw i32 %43, %6
  store i32 %.recomposed20, ptr %1, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %40, %47, %42, %33, %24, %15, %7
  %.2 = phi i32 [ %8, %7 ], [ %17, %15 ], [ %26, %24 ], [ %35, %33 ], [ %44, %42 ], [ %44, %47 ], [ %.1.3, %40 ]
  %50 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.2)
  %51 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not = icmp eq i32 %51, -1
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %49, %0
  call void @llvm.lifetime.end.p0(i64 4, 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: nofree nounwind
declare noundef i32 @printf(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

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


; Effective O3 passes: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass