; LLVM IR from DionysiosB/CodeForces :: 1400-1499 (1409C-YetAnotherArrayRestoration)

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

18:                                               ; preds = %119, %0
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = add nsw i64 %19, -1
  store i64 %20, ptr %3, align 8, !tbaa !5
  %21 = icmp ne i64 %19, 0
  br i1 %21, label %22, label %121

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4, ptr noundef %5, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 1000000000, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 1, ptr %10, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %100, %22
  %25 = load i64, ptr %10, align 8, !tbaa !5
  %26 = load i64, ptr %5, align 8, !tbaa !5
  %27 = icmp sle i64 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 4, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %103

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store i64 1, ptr %12, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %96, %29
  %31 = load i64, ptr %12, align 8, !tbaa !5
  %32 = load i64, ptr %6, align 8, !tbaa !5
  %33 = load i64, ptr %5, align 8, !tbaa !5
  %34 = sub nsw i64 %32, %33
  %35 = icmp sle i64 %31, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %30
  store i32 7, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %99

37:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #3
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = load i64, ptr %10, align 8, !tbaa !5
  %40 = sub nsw i64 %38, %39
  %41 = load i64, ptr %12, align 8, !tbaa !5
  %42 = srem i64 %40, %41
  %43 = icmp eq i64 %42, 0
  br i1 %43, label %44, label %52

44:                                               ; preds = %37
  %45 = load i64, ptr %5, align 8, !tbaa !5
  %46 = load i64, ptr %10, align 8, !tbaa !5
  %47 = sub nsw i64 %45, %46
  %48 = load i64, ptr %12, align 8, !tbaa !5
  %49 = sdiv i64 %47, %48
  %50 = load i64, ptr %4, align 8, !tbaa !5
  %51 = icmp slt i64 %49, %50
  br label %52

52:                                               ; preds = %44, %37
  %53 = phi i1 [ false, %37 ], [ %51, %44 ]
  %54 = zext i1 %53 to i8
  store i8 %54, ptr %13, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #3
  %55 = load i64, ptr %6, align 8, !tbaa !5
  %56 = load i64, ptr %10, align 8, !tbaa !5
  %57 = sub nsw i64 %55, %56
  %58 = load i64, ptr %12, align 8, !tbaa !5
  %59 = srem i64 %57, %58
  %60 = icmp eq i64 %59, 0
  br i1 %60, label %61, label %69

61:                                               ; preds = %52
  %62 = load i64, ptr %6, align 8, !tbaa !5
  %63 = load i64, ptr %10, align 8, !tbaa !5
  %64 = sub nsw i64 %62, %63
  %65 = load i64, ptr %12, align 8, !tbaa !5
  %66 = sdiv i64 %64, %65
  %67 = load i64, ptr %4, align 8, !tbaa !5
  %68 = icmp slt i64 %66, %67
  br label %69

69:                                               ; preds = %61, %52
  %70 = phi i1 [ false, %52 ], [ %68, %61 ]
  %71 = zext i1 %70 to i8
  store i8 %71, ptr %14, align 1, !tbaa !9
  %72 = load i8, ptr %13, align 1, !tbaa !9, !range !11, !noundef !12
  %73 = trunc i8 %72 to i1
  br i1 %73, label %74, label %77

74:                                               ; preds = %69
  %75 = load i8, ptr %14, align 1, !tbaa !9, !range !11, !noundef !12
  %76 = trunc i8 %75 to i1
  br i1 %76, label %78, label %77

77:                                               ; preds = %74, %69
  store i32 9, ptr %11, align 4
  br label %93

78:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %79 = load i64, ptr %10, align 8, !tbaa !5
  %80 = load i64, ptr %4, align 8, !tbaa !5
  %81 = sub nsw i64 %80, 1
  %82 = load i64, ptr %12, align 8, !tbaa !5
  %83 = mul nsw i64 %81, %82
  %84 = add nsw i64 %79, %83
  store i64 %84, ptr %15, align 8, !tbaa !5
  %85 = load i64, ptr %15, align 8, !tbaa !5
  %86 = load i64, ptr %9, align 8, !tbaa !5
  %87 = icmp slt i64 %85, %86
  br i1 %87, label %88, label %92

88:                                               ; preds = %78
  %89 = load i64, ptr %15, align 8, !tbaa !5
  store i64 %89, ptr %9, align 8, !tbaa !5
  %90 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %90, ptr %7, align 8, !tbaa !5
  %91 = load i64, ptr %12, align 8, !tbaa !5
  store i64 %91, ptr %8, align 8, !tbaa !5
  br label %92

92:                                               ; preds = %88, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  store i32 0, ptr %11, align 4
  br label %93

93:                                               ; preds = %92, %77
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  %94 = load i32, ptr %11, align 4
  switch i32 %94, label %123 [
    i32 0, label %95
    i32 9, label %96
  ]

95:                                               ; preds = %93
  br label %96

96:                                               ; preds = %95, %93
  %97 = load i64, ptr %12, align 8, !tbaa !5
  %98 = add nsw i64 %97, 1
  store i64 %98, ptr %12, align 8, !tbaa !5
  br label %30, !llvm.loop !13

99:                                               ; preds = %36
  br label %100

100:                                              ; preds = %99
  %101 = load i64, ptr %10, align 8, !tbaa !5
  %102 = add nsw i64 %101, 1
  store i64 %102, ptr %10, align 8, !tbaa !5
  br label %24, !llvm.loop !15

103:                                              ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 0, ptr %16, align 8, !tbaa !5
  br label %104

104:                                              ; preds = %116, %103
  %105 = load i64, ptr %16, align 8, !tbaa !5
  %106 = load i64, ptr %4, align 8, !tbaa !5
  %107 = icmp slt i64 %105, %106
  br i1 %107, label %109, label %108

108:                                              ; preds = %104
  store i32 10, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %119

109:                                              ; preds = %104
  %110 = load i64, ptr %7, align 8, !tbaa !5
  %111 = load i64, ptr %16, align 8, !tbaa !5
  %112 = load i64, ptr %8, align 8, !tbaa !5
  %113 = mul nsw i64 %111, %112
  %114 = add nsw i64 %110, %113
  %115 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %114)
  br label %116

116:                                              ; preds = %109
  %117 = load i64, ptr %16, align 8, !tbaa !5
  %118 = add nsw i64 %117, 1
  store i64 %118, ptr %16, align 8, !tbaa !5
  br label %104, !llvm.loop !16

119:                                              ; preds = %108
  %120 = call i32 @puts(ptr noundef @.str.3)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %18, !llvm.loop !17

121:                                              ; preds = %18
  store i32 0, ptr %1, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %122 = load i32, ptr %1, align 4
  ret i32 %122

123:                                              ; preds = %93
  unreachable
}

; 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = 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
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = add nsw i64 %6, -1
  store i64 %7, ptr %1, align 8, !tbaa !5
  %.not65 = icmp eq i64 %6, 0
  br i1 %.not65, label %._crit_edge68, label %.lr.ph67

.lr.ph67:                                         ; preds = %0, %._crit_edge64
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %.not3955 = icmp slt i64 %9, 1
  %.pre = load i64, ptr %2, align 8
  br i1 %.not3955, label %.preheader47, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %.lr.ph67
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %.not4048.not = icmp sgt i64 %10, %9
  %11 = add nsw i64 %.pre, -1
  br i1 %.not4048.not, label %.preheader.preheader, label %.preheader47

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  %12 = add nuw i64 %10, 1
  %13 = sub i64 %12, %9
  br label %.preheader

.preheader47:                                     ; preds = %._crit_edge, %.preheader.lr.ph, %.lr.ph67
  %.028.lcssa = phi i64 [ 0, %.lr.ph67 ], [ 0, %.preheader.lr.ph ], [ %.331, %._crit_edge ]
  %.027.lcssa = phi i64 [ 0, %.lr.ph67 ], [ 0, %.preheader.lr.ph ], [ %.3, %._crit_edge ]
  %14 = icmp sgt i64 %.pre, 0
  br i1 %14, label %.lr.ph, label %._crit_edge64

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %.02759 = phi i64 [ %.3, %._crit_edge ], [ 0, %.preheader.preheader ]
  %.02858 = phi i64 [ %.331, %._crit_edge ], [ 0, %.preheader.preheader ]
  %.03357 = phi i64 [ %17, %._crit_edge ], [ 1, %.preheader.preheader ]
  %.03456 = phi i64 [ %.337, %._crit_edge ], [ 1000000000, %.preheader.preheader ]
  %15 = sub nsw i64 %9, %.03357
  %16 = sub nsw i64 %10, %.03357
  br label %18

._crit_edge:                                      ; preds = %.thread
  %17 = add nuw i64 %.03357, 1
  %exitcond70.not = icmp eq i64 %.03357, %9
  br i1 %exitcond70.not, label %.preheader47, label %.preheader, !llvm.loop !9

18:                                               ; preds = %.preheader, %.thread
  %.152 = phi i64 [ %.02759, %.preheader ], [ %.3, %.thread ]
  %.12951 = phi i64 [ %.02858, %.preheader ], [ %.331, %.thread ]
  %.03250 = phi i64 [ 1, %.preheader ], [ %32, %.thread ]
  %.13549 = phi i64 [ %.03456, %.preheader ], [ %.337, %.thread ]
  %19 = srem i64 %15, %.03250
  %20 = sdiv i64 %15, %.03250
  %21 = icmp eq i64 %19, 0
  %22 = icmp slt i64 %20, %.pre
  %23 = select i1 %21, i1 %22, i1 false
  %24 = srem i64 %16, %.03250
  %25 = sdiv i64 %16, %.03250
  %26 = icmp eq i64 %24, 0
  %27 = icmp slt i64 %25, %.pre
  %brmerge.not = select i1 %23, i1 %27, i1 false
  %or.cond = select i1 %26, i1 %brmerge.not, i1 false
  br i1 %or.cond, label %28, label %.thread

28:                                               ; preds = %18
  %29 = mul nsw i64 %11, %.03250
  %30 = add nsw i64 %29, %.03357
  %31 = icmp slt i64 %30, %.13549
  %.236 = call i64 @llvm.smin.i64(i64 %30, i64 %.13549)
  %.230 = select i1 %31, i64 %.03250, i64 %.12951
  %.2 = select i1 %31, i64 %.03357, i64 %.152
  br label %.thread

.thread:                                          ; preds = %18, %28
  %.337 = phi i64 [ %.236, %28 ], [ %.13549, %18 ]
  %.331 = phi i64 [ %.230, %28 ], [ %.12951, %18 ]
  %.3 = phi i64 [ %.2, %28 ], [ %.152, %18 ]
  %32 = add nuw i64 %.03250, 1
  %exitcond.not = icmp eq i64 %32, %13
  br i1 %exitcond.not, label %._crit_edge, label %18, !llvm.loop !11

._crit_edge64:                                    ; preds = %.lr.ph, %.preheader47
  %33 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %34 = load i64, ptr %1, align 8, !tbaa !5
  %35 = add nsw i64 %34, -1
  store i64 %35, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %34, 0
  br i1 %.not, label %._crit_edge68, label %.lr.ph67, !llvm.loop !12

.lr.ph:                                           ; preds = %.preheader47, %.lr.ph
  %.063 = phi i64 [ %39, %.lr.ph ], [ 0, %.preheader47 ]
  %36 = mul nsw i64 %.063, %.028.lcssa
  %37 = add nsw i64 %36, %.027.lcssa
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %37)
  %39 = add nuw nsw i64 %.063, 1
  %40 = load i64, ptr %2, align 8, !tbaa !5
  %41 = icmp slt i64 %39, %40
  br i1 %41, label %.lr.ph, label %._crit_edge64, !llvm.loop !13

._crit_edge68:                                    ; preds = %._crit_edge64, %0
  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.smin.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}
!13 = distinct !{!13, !10}


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