; LLVM IR from DionysiosB/CodeForces :: 0300-0399 (325A-SquareAndRectangles)

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

16:                                               ; preds = %104, %0
  %17 = load i64, ptr %11, align 8, !tbaa !5
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = icmp slt i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %107

21:                                               ; preds = %16
  %22 = load i64, ptr %11, align 8, !tbaa !5
  %23 = getelementptr inbounds [4 x i64], ptr %15, i64 %22
  %24 = getelementptr inbounds [4 x i64], ptr %23, i64 0, i64 0
  %25 = load i64, ptr %11, align 8, !tbaa !5
  %26 = getelementptr inbounds [4 x i64], ptr %15, i64 %25
  %27 = getelementptr inbounds [4 x i64], ptr %26, i64 0, i64 1
  %28 = load i64, ptr %11, align 8, !tbaa !5
  %29 = getelementptr inbounds [4 x i64], ptr %15, i64 %28
  %30 = getelementptr inbounds [4 x i64], ptr %29, i64 0, i64 2
  %31 = load i64, ptr %11, align 8, !tbaa !5
  %32 = getelementptr inbounds [4 x i64], ptr %15, i64 %31
  %33 = getelementptr inbounds [4 x i64], ptr %32, i64 0, i64 3
  %34 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %24, ptr noundef %27, ptr noundef %30, ptr noundef %33)
  %35 = load i64, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds [4 x i64], ptr %15, i64 %35
  %37 = getelementptr inbounds [4 x i64], ptr %36, i64 0, i64 0
  %38 = load i64, ptr %37, align 16, !tbaa !5
  %39 = load i64, ptr %6, align 8, !tbaa !5
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %41, label %46

41:                                               ; preds = %21
  %42 = load i64, ptr %11, align 8, !tbaa !5
  %43 = getelementptr inbounds [4 x i64], ptr %15, i64 %42
  %44 = getelementptr inbounds [4 x i64], ptr %43, i64 0, i64 0
  %45 = load i64, ptr %44, align 16, !tbaa !5
  store i64 %45, ptr %6, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %41, %21
  %47 = load i64, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds [4 x i64], ptr %15, i64 %47
  %49 = getelementptr inbounds [4 x i64], ptr %48, i64 0, i64 1
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = load i64, ptr %7, align 8, !tbaa !5
  %52 = icmp slt i64 %50, %51
  br i1 %52, label %53, label %58

53:                                               ; preds = %46
  %54 = load i64, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds [4 x i64], ptr %15, i64 %54
  %56 = getelementptr inbounds [4 x i64], ptr %55, i64 0, i64 1
  %57 = load i64, ptr %56, align 8, !tbaa !5
  store i64 %57, ptr %7, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %53, %46
  %59 = load i64, ptr %11, align 8, !tbaa !5
  %60 = getelementptr inbounds [4 x i64], ptr %15, i64 %59
  %61 = getelementptr inbounds [4 x i64], ptr %60, i64 0, i64 2
  %62 = load i64, ptr %61, align 16, !tbaa !5
  %63 = load i64, ptr %8, align 8, !tbaa !5
  %64 = icmp sgt i64 %62, %63
  br i1 %64, label %65, label %70

65:                                               ; preds = %58
  %66 = load i64, ptr %11, align 8, !tbaa !5
  %67 = getelementptr inbounds [4 x i64], ptr %15, i64 %66
  %68 = getelementptr inbounds [4 x i64], ptr %67, i64 0, i64 2
  %69 = load i64, ptr %68, align 16, !tbaa !5
  store i64 %69, ptr %8, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %65, %58
  %71 = load i64, ptr %11, align 8, !tbaa !5
  %72 = getelementptr inbounds [4 x i64], ptr %15, i64 %71
  %73 = getelementptr inbounds [4 x i64], ptr %72, i64 0, i64 3
  %74 = load i64, ptr %73, align 8, !tbaa !5
  %75 = load i64, ptr %9, align 8, !tbaa !5
  %76 = icmp sgt i64 %74, %75
  br i1 %76, label %77, label %82

77:                                               ; preds = %70
  %78 = load i64, ptr %11, align 8, !tbaa !5
  %79 = getelementptr inbounds [4 x i64], ptr %15, i64 %78
  %80 = getelementptr inbounds [4 x i64], ptr %79, i64 0, i64 3
  %81 = load i64, ptr %80, align 8, !tbaa !5
  store i64 %81, ptr %9, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %77, %70
  %83 = load i64, ptr %11, align 8, !tbaa !5
  %84 = getelementptr inbounds [4 x i64], ptr %15, i64 %83
  %85 = getelementptr inbounds [4 x i64], ptr %84, i64 0, i64 3
  %86 = load i64, ptr %85, align 8, !tbaa !5
  %87 = load i64, ptr %11, align 8, !tbaa !5
  %88 = getelementptr inbounds [4 x i64], ptr %15, i64 %87
  %89 = getelementptr inbounds [4 x i64], ptr %88, i64 0, i64 1
  %90 = load i64, ptr %89, align 8, !tbaa !5
  %91 = sub nsw i64 %86, %90
  %92 = load i64, ptr %11, align 8, !tbaa !5
  %93 = getelementptr inbounds [4 x i64], ptr %15, i64 %92
  %94 = getelementptr inbounds [4 x i64], ptr %93, i64 0, i64 2
  %95 = load i64, ptr %94, align 16, !tbaa !5
  %96 = load i64, ptr %11, align 8, !tbaa !5
  %97 = getelementptr inbounds [4 x i64], ptr %15, i64 %96
  %98 = getelementptr inbounds [4 x i64], ptr %97, i64 0, i64 0
  %99 = load i64, ptr %98, align 16, !tbaa !5
  %100 = sub nsw i64 %95, %99
  %101 = mul nsw i64 %91, %100
  %102 = load i64, ptr %10, align 8, !tbaa !5
  %103 = add nsw i64 %102, %101
  store i64 %103, ptr %10, align 8, !tbaa !5
  br label %104

104:                                              ; preds = %82
  %105 = load i64, ptr %11, align 8, !tbaa !5
  %106 = add nsw i64 %105, 1
  store i64 %106, ptr %11, align 8, !tbaa !5
  br label %16, !llvm.loop !9

107:                                              ; preds = %20
  %108 = load i64, ptr %8, align 8, !tbaa !5
  %109 = load i64, ptr %6, align 8, !tbaa !5
  %110 = sub nsw i64 %108, %109
  %111 = load i64, ptr %9, align 8, !tbaa !5
  %112 = load i64, ptr %7, align 8, !tbaa !5
  %113 = sub nsw i64 %111, %112
  %114 = icmp eq i64 %110, %113
  br i1 %114, label %115, label %127

115:                                              ; preds = %107
  %116 = load i64, ptr %8, align 8, !tbaa !5
  %117 = load i64, ptr %6, align 8, !tbaa !5
  %118 = sub nsw i64 %116, %117
  %119 = load i64, ptr %9, align 8, !tbaa !5
  %120 = load i64, ptr %7, align 8, !tbaa !5
  %121 = sub nsw i64 %119, %120
  %122 = mul nsw i64 %118, %121
  %123 = load i64, ptr %10, align 8, !tbaa !5
  %124 = icmp eq i64 %122, %123
  br i1 %124, label %125, label %127

125:                                              ; preds = %115
  %126 = call i32 @puts(ptr noundef @.str.2)
  br label %129

127:                                              ; preds = %115, %107
  %128 = call i32 @puts(ptr noundef @.str.3)
  br label %129

129:                                              ; preds = %127, %125
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %130 = load ptr, ptr %4, align 8
  call void @llvm.stackrestore.p0(ptr %130)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %131 = load i32, ptr %1, align 4
  ret i32 %131
}

; 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
declare ptr @llvm.stacksave.p0() #3

; 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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

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 = { nocallback nofree nosync nounwind willreturn }
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"}


; 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 [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = 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) #5
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = call ptr @llvm.stacksave.p0()
  %5 = alloca [4 x i64], i64 %3, align 16
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = icmp sgt i64 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %8 = sub nsw i64 %.136, %spec.select
  %9 = sub nsw i64 %.1, %.138
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %.033.lcssa = phi i64 [ 0, %0 ], [ %28, %._crit_edge.loopexit ]
  %10 = phi i64 [ -32000, %0 ], [ %8, %._crit_edge.loopexit ]
  %11 = phi i64 [ -32000, %0 ], [ %9, %._crit_edge.loopexit ]
  %12 = icmp eq i64 %10, %11
  %13 = mul nsw i64 %11, %10
  %14 = icmp eq i64 %13, %.033.lcssa
  %or.cond = select i1 %12, i1 %14, i1 false
  %.str.2..str.3 = select i1 %or.cond, ptr @.str.2, ptr @.str.3
  %15 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %.str.2..str.3)
  call void @llvm.stackrestore.p0(ptr %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret i32 0

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.053 = phi i64 [ %29, %.lr.ph ], [ 0, %0 ]
  %.03352 = phi i64 [ %28, %.lr.ph ], [ 0, %0 ]
  %.03451 = phi i64 [ %.1, %.lr.ph ], [ 0, %0 ]
  %.03550 = phi i64 [ %.136, %.lr.ph ], [ 0, %0 ]
  %.03749 = phi i64 [ %.138, %.lr.ph ], [ 32000, %0 ]
  %.03948 = phi i64 [ %spec.select, %.lr.ph ], [ 32000, %0 ]
  %16 = getelementptr inbounds [4 x i64], ptr %5, i64 %.053
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = getelementptr inbounds i8, ptr %16, i64 16
  %19 = getelementptr inbounds i8, ptr %16, i64 24
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %16, ptr noundef nonnull %17, ptr noundef nonnull %18, ptr noundef nonnull %19)
  %21 = load i64, ptr %16, align 16, !tbaa !5
  %spec.select = call i64 @llvm.smin.i64(i64 %21, i64 %.03948)
  %22 = load i64, ptr %17, align 8, !tbaa !5
  %.138 = call i64 @llvm.smin.i64(i64 %22, i64 %.03749)
  %23 = load i64, ptr %18, align 16, !tbaa !5
  %.136 = call i64 @llvm.smax.i64(i64 %23, i64 %.03550)
  %24 = load i64, ptr %19, align 8, !tbaa !5
  %.1 = call i64 @llvm.smax.i64(i64 %24, i64 %.03451)
  %25 = sub nsw i64 %24, %22
  %26 = sub nsw i64 %23, %21
  %27 = mul nsw i64 %25, %26
  %28 = add nsw i64 %27, %.03352
  %29 = add nuw nsw i64 %.053, 1
  %30 = load i64, ptr %1, align 8, !tbaa !5
  %31 = icmp slt i64 %29, %30
  br i1 %31, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9
}

; 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
declare ptr @llvm.stacksave.p0() #3

; 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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

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

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass