; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 888A. Local Extrema (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"

@.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 [1001 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 4004, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  br label %6

6:                                                ; preds = %79, %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 %82

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

10:                                               ; preds = %19, %9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %22

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

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

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

23:                                               ; preds = %76, %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sub nsw i32 %25, 1
  %27 = icmp slt i32 %24, %26
  br i1 %27, label %28, label %79

28:                                               ; preds = %23
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1001 x i32], ptr %2, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sub nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1001 x i32], ptr %2, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = icmp sgt i32 %32, %37
  br i1 %38, label %39, label %50

39:                                               ; preds = %28
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1001 x i32], ptr %2, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1001 x i32], ptr %2, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = icmp sgt i32 %43, %48
  br i1 %49, label %72, label %50

50:                                               ; preds = %39, %28
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1001 x i32], ptr %2, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sub nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1001 x i32], ptr %2, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = icmp slt i32 %54, %59
  br i1 %60, label %61, label %75

61:                                               ; preds = %50
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1001 x i32], ptr %2, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [1001 x i32], ptr %2, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = icmp slt i32 %65, %70
  br i1 %71, label %72, label %75

72:                                               ; preds = %61, %39
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %5, align 4, !tbaa !5
  br label %75

75:                                               ; preds = %72, %61, %50
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %4, align 4, !tbaa !5
  br label %23, !llvm.loop !11

79:                                               ; preds = %23
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %80)
  br label %6, !llvm.loop !12

82:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4004, ptr %2) #3
  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

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 = { 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"

@.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 [1001 x i32], align 16
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4004, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %.not26 = icmp eq i32 %3, -1
  br i1 %.not26, label %._crit_edge27, label %.preheader19

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

.preheader:                                       ; preds = %.lr.ph
  %6 = icmp sgt i32 %10, 2
  br i1 %6, label %.lr.ph24.preheader, label %._crit_edge

.lr.ph24.preheader:                               ; preds = %.preheader
  %7 = add nsw i32 %10, -1
  %wide.trip.count = zext nneg i32 %7 to i64
  %.pre = load i32, ptr %1, align 16, !tbaa !5
  br label %.lr.ph24

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

.lr.ph24:                                         ; preds = %.lr.ph24.preheader, %31
  %13 = phi i32 [ %.pre, %.lr.ph24.preheader ], [ %15, %31 ]
  %indvars.iv30 = phi i64 [ 1, %.lr.ph24.preheader ], [ %indvars.iv.next31, %31 ]
  %.023 = phi i32 [ 0, %.lr.ph24.preheader ], [ %.1, %31 ]
  %14 = getelementptr inbounds [1001 x i32], ptr %1, i64 0, i64 %indvars.iv30
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, %13
  br i1 %16, label %17, label %22

17:                                               ; preds = %.lr.ph24
  %18 = add nuw nsw i64 %indvars.iv30, 1
  %19 = getelementptr inbounds [1001 x i32], ptr %1, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp sgt i32 %15, %20
  br i1 %21, label %29, label %22

22:                                               ; preds = %17, %.lr.ph24
  %23 = icmp slt i32 %15, %13
  br i1 %23, label %24, label %31

24:                                               ; preds = %22
  %25 = add nuw nsw i64 %indvars.iv30, 1
  %26 = getelementptr inbounds [1001 x i32], ptr %1, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp slt i32 %15, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %24, %17
  %30 = add nsw i32 %.023, 1
  br label %31

31:                                               ; preds = %22, %24, %29
  %.1 = phi i32 [ %30, %29 ], [ %.023, %24 ], [ %.023, %22 ]
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph24, !llvm.loop !11

._crit_edge:                                      ; preds = %31, %.preheader19, %.preheader
  %.0.lcssa = phi i32 [ 0, %.preheader ], [ 0, %.preheader19 ], [ %.1, %31 ]
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.0.lcssa)
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %.not = icmp eq i32 %33, -1
  br i1 %.not, label %._crit_edge27, label %.preheader19, !llvm.loop !12

._crit_edge27:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4004, 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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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