program main
  implicit none
  integer :: i, n, cnt = 1
  integer, allocatable :: h(:)

  read *, n
  allocate (h(n))
  read *, h

  do i = 2, n
    if (check(h, i-1, i)) cnt = cnt + 1
  end do

  print '(i0)', cnt
contains
  recursive function check(h, i, k) result(visible)
    integer, allocatable :: h(:) 
    integer :: i, k
    logical :: visible

    if (i == 1) then
      visible = h(1) <= h(k)
    else if (h(i) > h(k)) then
      visible = .false.
    else
      visible = check(h, i-1, k)
    end if
  end function

end program
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEcnt = internal unnamed_addr global i32 1
@_QFEh = internal global { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] } { ptr null, i64 ptrtoint (ptr getelementptr (i32, ptr null, i32 1) to i64), i32 20180515, i8 1, i8 9, i8 2, i8 0, [1 x [3 x i64]] [[3 x i64] [i64 1, i64 0, i64 ptrtoint (ptr getelementptr (i32, ptr null, i32 1) to i64)]] }
@_QQcl.8d5bb519418ecbbfe635050ec18220ca = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4480/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8d5bb519418ecbbfe635050ec18220ca, i32 6)
  %6 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %4, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %5)
  %8 = load i32, ptr %4, align 4, !tbaa !3
  %9 = call i32 @llvm.smax.i32(i32 %8, i32 0)
  %10 = zext i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 2
  %12 = call ptr @malloc(i64 %11)
  store ptr %12, ptr @_QFEh, align 16, !tbaa !7
  store i64 4, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 1), align 8, !tbaa !7
  store i32 20180515, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 2), align 16, !tbaa !7
  store i8 1, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 3), align 4, !tbaa !7
  store i8 9, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 4), align 1, !tbaa !7
  store i8 2, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 5), align 2, !tbaa !7
  store i8 0, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 6), align 1, !tbaa !7
  store i64 1, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 7), align 8, !tbaa !7
  store i64 %10, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 7, i64 0, i64 1), align 16, !tbaa !7
  store i64 4, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 7, i64 0, i64 2), align 8, !tbaa !7
  %13 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8d5bb519418ecbbfe635050ec18220ca, i32 8)
  %.unpack = load ptr, ptr @_QFEh, align 16, !tbaa !7
  %.unpack53.unpack.unpack = load i64, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 7), align 8, !tbaa !7
  %.unpack53.unpack.unpack55 = load i64, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEh, i64 0, i32 7, i64 0, i64 1), align 16, !tbaa !7
  %14 = icmp eq i64 %.unpack53.unpack.unpack55, 0
  %15 = select i1 %14, i64 1, i64 %.unpack53.unpack.unpack
  store ptr %.unpack, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 %15, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack53.unpack.unpack55, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %16 = call i1 @_FortranAioInputDescriptor(ptr %13, ptr nonnull %1)
  %17 = call i32 @_FortranAioEndIoStatement(ptr %13)
  %18 = load i32, ptr %4, align 4, !tbaa !3
  %19 = icmp sgt i32 %18, 1
  br i1 %19, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %20 = zext i32 %18 to i64
  %_QFEcnt.promoted = load i32, ptr @_QFEcnt, align 4, !tbaa !3
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %28
  %.in = phi i64 [ %23, %28 ], [ %20, %.lr.ph.preheader ]
  %21 = phi i32 [ %30, %28 ], [ 2, %.lr.ph.preheader ]
  %22 = phi i32 [ %29, %28 ], [ %_QFEcnt.promoted, %.lr.ph.preheader ]
  %23 = add nsw i64 %.in, -1
  store i32 %21, ptr %3, align 4, !tbaa !3
  %24 = add nsw i32 %21, -1
  store i32 %24, ptr %2, align 4, !tbaa !3
  %25 = call i32 @_QFPcheck(ptr nonnull @_QFEh, ptr nonnull %2, ptr nonnull %3)
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %28, label %26

26:                                               ; preds = %.lr.ph
  %27 = add i32 %22, 1
  store i32 %27, ptr @_QFEcnt, align 4, !tbaa !3
  br label %28

28:                                               ; preds = %26, %.lr.ph
  %29 = phi i32 [ %27, %26 ], [ %22, %.lr.ph ]
  %30 = add nuw i32 %21, 1
  %31 = icmp ugt i64 %.in, 2
  br i1 %31, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %28, %0
  %32 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.8d5bb519418ecbbfe635050ec18220ca, i32 14)
  %33 = load i32, ptr @_QFEcnt, align 4, !tbaa !3
  %34 = call i1 @_FortranAioOutputInteger32(ptr %32, i32 %33)
  %35 = call i32 @_FortranAioEndIoStatement(ptr %32)
  ret void
}

; Function Attrs: nofree nosync nounwind memory(read, inaccessiblemem: none)
define i32 @_QFPcheck(ptr nocapture readonly %0, ptr nocapture readonly %1, ptr nocapture readonly %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  %5 = load i32, ptr %1, align 4, !tbaa !3
  %6 = icmp eq i32 %5, 1
  %.unpack42 = load ptr, ptr %0, align 8, !tbaa !7
  %.elt55 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7
  %.unpack56.unpack.unpack = load i64, ptr %.elt55, align 8, !tbaa !7
  br i1 %6, label %7, label %18

7:                                                ; preds = %3
  %8 = sub i64 1, %.unpack56.unpack.unpack
  %9 = getelementptr i32, ptr %.unpack42, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !3
  %11 = load i32, ptr %2, align 4, !tbaa !3
  %12 = sext i32 %11 to i64
  %13 = sub i64 %12, %.unpack56.unpack.unpack
  %14 = getelementptr i32, ptr %.unpack42, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !3
  %16 = icmp sle i32 %10, %15
  %17 = zext i1 %16 to i32
  br label %32

18:                                               ; preds = %3
  %19 = sext i32 %5 to i64
  %20 = sub i64 %19, %.unpack56.unpack.unpack
  %21 = getelementptr i32, ptr %.unpack42, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !3
  %23 = load i32, ptr %2, align 4, !tbaa !3
  %24 = sext i32 %23 to i64
  %25 = sub i64 %24, %.unpack56.unpack.unpack
  %26 = getelementptr i32, ptr %.unpack42, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !3
  %28 = icmp sgt i32 %22, %27
  br i1 %28, label %32, label %29

29:                                               ; preds = %18
  %30 = add i32 %5, -1
  store i32 %30, ptr %4, align 4, !tbaa !3
  %31 = call i32 @_QFPcheck(ptr nonnull %0, ptr nonnull %4, ptr nonnull %2)
  br label %32

32:                                               ; preds = %18, %7, %29
  %.0 = phi i32 [ %17, %7 ], [ %31, %29 ], [ 0, %18 ]
  ret i32 %.0
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nofree nosync nounwind memory(read, inaccessiblemem: none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
