; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 1203B. Equal Rectangles (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 [405 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 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
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %10

10:                                               ; preds = %133, %0
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr %2, align 4, !tbaa !5
  %13 = icmp ne i32 %11, 0
  br i1 %13, label %14, label %134

14:                                               ; preds = %10
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %26, %14
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = mul nsw i32 4, %18
  %20 = icmp slt i32 %17, %19
  br i1 %20, label %21, label %29

21:                                               ; preds = %16
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %23
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %24)
  br label %26

26:                                               ; preds = %21
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !5
  br label %16, !llvm.loop !9

29:                                               ; preds = %16
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = mul nsw i32 4, %30
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr @arr, i64 %32
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @arr, ptr noundef %33)
  store i32 0, ptr %6, align 4, !tbaa !5
  %34 = load i32, ptr @arr, align 16, !tbaa !5
  %35 = load i32, ptr getelementptr inbounds ([405 x i32], ptr @arr, i64 0, i64 1), align 4, !tbaa !5
  %36 = icmp eq i32 %34, %35
  br i1 %36, label %37, label %60

37:                                               ; preds = %29
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = mul nsw i32 4, %38
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = mul nsw i32 4, %44
  %46 = sub nsw i32 %45, 2
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = icmp eq i32 %43, %49
  br i1 %50, label %51, label %60

51:                                               ; preds = %37
  store i32 1, ptr %6, align 4, !tbaa !5
  %52 = load i32, ptr @arr, align 16, !tbaa !5
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = mul nsw i32 4, %53
  %55 = sub nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = mul nsw i32 %52, %58
  store i32 %59, ptr %7, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %51, %37, %29
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %65, label %63

63:                                               ; preds = %60
  %64 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %133

65:                                               ; preds = %60
  store i32 1, ptr %6, align 4, !tbaa !5
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %124, %65
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = sub nsw i32 %68, 1
  %70 = mul nsw i32 2, %69
  %71 = icmp sle i32 %67, %70
  br i1 %71, label %72, label %127

72:                                               ; preds = %66
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = icmp eq i32 %76, %81
  br i1 %82, label %83, label %121

83:                                               ; preds = %72
  %84 = load i32, ptr %3, align 4, !tbaa !5
  %85 = mul nsw i32 4, %84
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  %88 = sub nsw i32 %85, %87
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = mul nsw i32 4, %92
  %94 = load i32, ptr %4, align 4, !tbaa !5
  %95 = add nsw i32 %94, 2
  %96 = sub nsw i32 %93, %95
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !5
  %100 = icmp eq i32 %91, %99
  br i1 %100, label %101, label %121

101:                                              ; preds = %83
  %102 = load i32, ptr %4, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !5
  %106 = load i32, ptr %3, align 4, !tbaa !5
  %107 = mul nsw i32 4, %106
  %108 = load i32, ptr %4, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  %110 = sub nsw i32 %107, %109
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %111
  %113 = load i32, ptr %112, align 4, !tbaa !5
  %114 = mul nsw i32 %105, %113
  store i32 %114, ptr %8, align 4, !tbaa !5
  %115 = load i32, ptr %7, align 4, !tbaa !5
  %116 = load i32, ptr %8, align 4, !tbaa !5
  %117 = icmp ne i32 %115, %116
  br i1 %117, label %118, label %120

118:                                              ; preds = %101
  store i32 0, ptr %6, align 4, !tbaa !5
  %119 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %127

120:                                              ; preds = %101
  br label %123

121:                                              ; preds = %83, %72
  store i32 0, ptr %6, align 4, !tbaa !5
  %122 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %127

123:                                              ; preds = %120
  br label %124

124:                                              ; preds = %123
  %125 = load i32, ptr %4, align 4, !tbaa !5
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr %4, align 4, !tbaa !5
  br label %66, !llvm.loop !11

127:                                              ; preds = %121, %118, %66
  %128 = load i32, ptr %6, align 4, !tbaa !5
  %129 = icmp ne i32 %128, 0
  br i1 %129, label %130, label %132

130:                                              ; preds = %127
  %131 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %132

132:                                              ; preds = %130, %127
  br label %133

133:                                              ; preds = %132, %63
  br label %10, !llvm.loop !12

134:                                              ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  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 uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #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 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}


; 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 [405 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr %1, align 4, !tbaa !5
  %.not37 = icmp eq i32 %4, 0
  br i1 %.not37, label %._crit_edge41, label %.lr.ph40

.lr.ph40:                                         ; preds = %0, %.thread
  %.01538 = phi i32 [ %.11631, %.thread ], [ undef, %0 ]
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %.lr.ph40.._crit_edge_crit_edge

.lr.ph40.._crit_edge_crit_edge:                   ; preds = %.lr.ph40
  %9 = shl nsw i32 %7, 2
  %.pre = sext i32 %9 to i64
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph40, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph40 ]
  %10 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %indvars.iv
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %10)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = shl nsw i32 %12, 2
  %14 = sext i32 %13 to i64
  %15 = icmp slt i64 %indvars.iv.next, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph40.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.lr.ph40.._crit_edge_crit_edge ], [ %14, %.lr.ph ]
  %16 = getelementptr inbounds i32, ptr @arr, i64 %.pre-phi
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @arr, ptr noundef nonnull %16)
  %17 = load i32, ptr @arr, align 16, !tbaa !5
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @arr, i64 4), align 4, !tbaa !5
  %19 = icmp eq i32 %17, %18
  br i1 %19, label %20, label %.thread

20:                                               ; preds = %._crit_edge
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = shl nsw i32 %21, 2
  %23 = add nsw i32 %22, -1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %22, -2
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %28
  %30 = load i32, ptr %29, align 8, !tbaa !5
  %.not35 = icmp eq i32 %26, %30
  %31 = mul nsw i32 %26, %17
  %spec.select28 = select i1 %.not35, i32 %31, i32 %.01538
  br i1 %.not35, label %.preheader, label %.thread

.preheader:                                       ; preds = %20
  %32 = shl i32 %21, 1
  %33 = sext i32 %22 to i64
  %34 = add i32 %32, -1
  %smax = call i32 @llvm.smax.i32(i32 %34, i32 2)
  %wide.trip.count = zext nneg i32 %smax to i64
  br label %35

35:                                               ; preds = %42, %.preheader
  %indvars.iv44 = phi i64 [ 2, %.preheader ], [ %indvars.iv.next45, %42 ]
  %exitcond = icmp eq i64 %indvars.iv44, %wide.trip.count
  br i1 %exitcond, label %.thread, label %36

36:                                               ; preds = %35
  %37 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %indvars.iv44
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %39 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %indvars.iv.next45
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp eq i32 %38, %40
  br i1 %41, label %42, label %.thread

42:                                               ; preds = %36
  %43 = sub nsw i64 %33, %indvars.iv.next45
  %44 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = trunc nuw nsw i64 %indvars.iv44 to i32
  %reass.sub = sub i32 %22, %46
  %47 = add i32 %reass.sub, -2
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [405 x i32], ptr @arr, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = icmp eq i32 %45, %50
  %52 = mul nsw i32 %45, %38
  %.not26 = icmp eq i32 %spec.select28, %52
  %or.cond = select i1 %51, i1 %.not26, i1 false
  br i1 %or.cond, label %35, label %.thread, !llvm.loop !11

.thread:                                          ; preds = %35, %36, %42, %20, %._crit_edge
  %.str.2.sink = phi ptr [ @.str.2, %._crit_edge ], [ @.str.2, %20 ], [ @.str.2, %42 ], [ @.str.2, %36 ], [ @.str.3, %35 ]
  %.11631 = phi i32 [ %.01538, %._crit_edge ], [ %.01538, %20 ], [ %spec.select28, %42 ], [ %spec.select28, %36 ], [ %spec.select28, %35 ]
  %53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2.sink)
  %54 = load i32, ptr %1, align 4, !tbaa !5
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %54, 0
  br i1 %.not, label %._crit_edge41, label %.lr.ph40, !llvm.loop !12

._crit_edge41:                                    ; preds = %.thread, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  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 uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

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 = { 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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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}


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