; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 996D. Suit and Tie (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"

@arr = external dso_local global [201 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 i32, align 4
  %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 4, ptr %2) #4
  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 = %74, %0
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %8 = icmp ne i32 %7, -1
  br i1 %8, label %9, label %77

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

10:                                               ; preds = %20, %9
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = mul nsw i32 2, %12
  %14 = icmp slt i32 %11, %13
  br i1 %14, label %15, label %23

15:                                               ; preds = %10
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [201 x i32], ptr @arr, i64 0, i64 %17
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %18)
  br label %20

20:                                               ; preds = %15
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !5
  br label %10, !llvm.loop !9

23:                                               ; preds = %10
  store i32 0, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %71, %23
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = mul nsw i32 2, %26
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %29, label %74

29:                                               ; preds = %24
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %4, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %67, %29
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = mul nsw i32 2, %34
  %36 = icmp slt i32 %33, %35
  br i1 %36, label %37, label %70

37:                                               ; preds = %32
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [201 x i32], ptr @arr, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [201 x i32], ptr @arr, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp eq i32 %41, %45
  br i1 %46, label %47, label %66

47:                                               ; preds = %37
  br label %48

48:                                               ; preds = %53, %47
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = icmp ne i32 %49, %51
  br i1 %52, label %53, label %65

53:                                               ; preds = %48
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [201 x i32], ptr @arr, i64 0, i64 %55
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sub nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [201 x i32], ptr @arr, i64 0, i64 %59
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %56, ptr noundef nonnull align 4 dereferenceable(4) %60) #4
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = add nsw i32 %61, -1
  store i32 %62, ptr %4, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %5, align 4, !tbaa !5
  br label %48, !llvm.loop !11

65:                                               ; preds = %48
  br label %66

66:                                               ; preds = %65, %37
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %4, align 4, !tbaa !5
  br label %32, !llvm.loop !12

70:                                               ; preds = %32
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %3, align 4, !tbaa !5
  br label %24, !llvm.loop !13

74:                                               ; preds = %24
  %75 = load i32, ptr %5, align 4, !tbaa !5
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %75)
  br label %6, !llvm.loop !14

77:                                               ; 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 4, 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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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

; 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 = { "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 = { inlinehint 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 #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}
!12 = distinct !{!12, !10}
!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"

@arr = external dso_local global [201 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 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) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not40 = icmp eq i32 %2, -1
  br i1 %.not40, label %._crit_edge41, label %.preheader25

.preheader25:                                     ; preds = %0, %._crit_edge
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.preheader24:                                     ; preds = %.lr.ph
  %5 = icmp sgt i32 %8, 0
  br i1 %5, label %.lr.ph38, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader25, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader25 ]
  %6 = getelementptr inbounds [201 x i32], ptr @arr, i64 0, i64 %indvars.iv
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %6)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = shl nsw i32 %8, 1
  %10 = sext i32 %9 to i64
  %11 = icmp slt i64 %indvars.iv.next, %10
  br i1 %11, label %.lr.ph, label %.preheader24, !llvm.loop !9

.loopexit23.loopexit:                             ; preds = %.loopexit
  %.pre50 = shl nsw i32 %33, 1
  %.pre51 = sext i32 %.pre50 to i64
  br label %.loopexit23

.loopexit23:                                      ; preds = %.loopexit23.loopexit, %.lr.ph38
  %.pre-phi52 = phi i64 [ %.pre51, %.loopexit23.loopexit ], [ %16, %.lr.ph38 ]
  %12 = phi i32 [ %33, %.loopexit23.loopexit ], [ %14, %.lr.ph38 ]
  %.1.lcssa = phi i32 [ %.3, %.loopexit23.loopexit ], [ %.037, %.lr.ph38 ]
  %13 = icmp slt i64 %indvars.iv.next48, %.pre-phi52
  br i1 %13, label %.lr.ph38, label %._crit_edge, !llvm.loop !11

.lr.ph38:                                         ; preds = %.preheader24, %.loopexit23
  %14 = phi i32 [ %12, %.loopexit23 ], [ %8, %.preheader24 ]
  %indvars.iv47 = phi i64 [ %indvars.iv.next48, %.loopexit23 ], [ 0, %.preheader24 ]
  %.037 = phi i32 [ %.1.lcssa, %.loopexit23 ], [ 0, %.preheader24 ]
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %15 = shl nsw i32 %14, 1
  %16 = sext i32 %15 to i64
  %17 = icmp slt i64 %indvars.iv.next48, %16
  br i1 %17, label %.lr.ph34, label %.loopexit23

.lr.ph34:                                         ; preds = %.lr.ph38
  %18 = getelementptr inbounds [201 x i32], ptr @arr, i64 0, i64 %indvars.iv47
  %19 = trunc nsw i64 %indvars.iv.next48 to i32
  br label %20

20:                                               ; preds = %.lr.ph34, %.loopexit
  %21 = phi i32 [ %14, %.lr.ph34 ], [ %33, %.loopexit ]
  %22 = phi i32 [ %14, %.lr.ph34 ], [ %34, %.loopexit ]
  %.133 = phi i32 [ %.037, %.lr.ph34 ], [ %.3, %.loopexit ]
  %.01732 = phi i32 [ %19, %.lr.ph34 ], [ %35, %.loopexit ]
  %23 = load i32, ptr %18, align 4, !tbaa !5
  %24 = sext i32 %.01732 to i64
  %25 = getelementptr inbounds [201 x i32], ptr @arr, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp ne i32 %23, %26
  %28 = zext i32 %.01732 to i64
  %.not2227 = icmp eq i64 %indvars.iv.next48, %28
  %or.cond = or i1 %27, %.not2227
  br i1 %or.cond, label %.loopexit, label %.lr.ph30

.lr.ph30:                                         ; preds = %20, %.lr.ph30
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %.lr.ph30 ], [ %24, %20 ]
  %.229 = phi i32 [ %31, %.lr.ph30 ], [ %.133, %20 ]
  %29 = getelementptr inbounds [201 x i32], ptr @arr, i64 0, i64 %indvars.iv44
  %indvars.iv.next45 = add nsw i64 %indvars.iv44, -1
  %30 = getelementptr inbounds [201 x i32], ptr @arr, i64 0, i64 %indvars.iv.next45
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %29, ptr noundef nonnull align 4 dereferenceable(4) %30) #4
  %31 = add nsw i32 %.229, 1
  %32 = icmp eq i64 %indvars.iv.next45, %indvars.iv.next48
  br i1 %32, label %.loopexit.loopexit, label %.lr.ph30, !llvm.loop !12

.loopexit.loopexit:                               ; preds = %.lr.ph30
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %20
  %33 = phi i32 [ %21, %20 ], [ %.pre, %.loopexit.loopexit ]
  %34 = phi i32 [ %22, %20 ], [ %.pre, %.loopexit.loopexit ]
  %.219 = phi i32 [ %.01732, %20 ], [ %19, %.loopexit.loopexit ]
  %.3 = phi i32 [ %.133, %20 ], [ %31, %.loopexit.loopexit ]
  %35 = add nsw i32 %.219, 1
  %36 = shl nsw i32 %34, 1
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %20, label %.loopexit23.loopexit, !llvm.loop !13

._crit_edge:                                      ; preds = %.loopexit23, %.preheader25, %.preheader24
  %.0.lcssa = phi i32 [ 0, %.preheader24 ], [ 0, %.preheader25 ], [ %.1.lcssa, %.loopexit23 ]
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.0.lcssa)
  %39 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.not = icmp eq i32 %39, -1
  br i1 %.not, label %._crit_edge41, label %.preheader25, !llvm.loop !14

._crit_edge41:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 4, 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

; 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 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 = { inlinehint 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 #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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


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