program ccc

implicit none

integer :: n, i
integer,allocatable,dimension(:) :: a, b

read(*,*) n

allocate(a(n))
allocate(b(n-1))

read(*,*) b

a(1) = b(1)
a(n) = b(n-1)

do i = 2, n-1
a(i) = min(b(i-1),b(i))
end do

write(*,'(i0)') sum(a)

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"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEa.8 = internal unnamed_addr global i64 0
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEb.8 = internal unnamed_addr global i64 0
@_QQcl.0217909891a05e80ea709a5e3f21b8fd = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3308/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 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0217909891a05e80ea709a5e3f21b8fd, i32 8)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i32, ptr %2, align 4, !tbaa !3
  %7 = call i32 @llvm.smax.i32(i32 %6, i32 0)
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEa.8, align 8, !tbaa !7
  %11 = add i32 %6, -1
  %12 = call i32 @llvm.smax.i32(i32 %11, i32 0)
  %13 = zext i32 %12 to i64
  %14 = shl nuw nsw i64 %13, 2
  %15 = call ptr @malloc(i64 %14)
  store ptr %15, ptr @_QFEb.0, align 8, !tbaa !7
  store i64 %13, ptr @_QFEb.8, align 8, !tbaa !7
  %16 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0217909891a05e80ea709a5e3f21b8fd, i32 13)
  %.unpack = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack333.unpack.unpack335 = load i64, ptr @_QFEb.8, align 8, !tbaa !7
  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 1, 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 %.unpack333.unpack.unpack335, 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
  %17 = call i1 @_FortranAioInputDescriptor(ptr %16, ptr nonnull %1)
  %18 = call i32 @_FortranAioEndIoStatement(ptr %16)
  %.unpack338 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %19 = load i32, ptr %.unpack338, align 4, !tbaa !3
  %.unpack350 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  store i32 %19, ptr %.unpack350, align 4, !tbaa !3
  %20 = load i32, ptr %2, align 4, !tbaa !3
  %21 = add i32 %20, -1
  %22 = sext i32 %21 to i64
  %23 = add nsw i64 %22, -1
  %24 = getelementptr i32, ptr %.unpack338, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !3
  %26 = sext i32 %20 to i64
  %27 = add nsw i64 %26, -1
  %28 = getelementptr i32, ptr %.unpack350, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !3
  %29 = load i32, ptr %2, align 4, !tbaa !3
  %30 = add i32 %29, -1
  %31 = icmp sgt i32 %30, 1
  br i1 %31, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %32 = zext i32 %30 to i64
  %33 = add nsw i64 %32, -1
  %min.iters.check = icmp ult i32 %30, 9
  br i1 %min.iters.check, label %.lr.ph.preheader446, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %uglygep = getelementptr i8, ptr %.unpack350, i64 4
  %34 = shl nuw nsw i64 %32, 2
  %uglygep423 = getelementptr i8, ptr %.unpack350, i64 %34
  %uglygep424 = getelementptr i8, ptr %.unpack338, i64 %34
  %bound0 = icmp ult ptr %uglygep, %uglygep424
  %bound1 = icmp ult ptr %.unpack338, %uglygep423
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.preheader446, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %33, -8
  %ind.end = or i64 %n.vec, 2
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %35 = getelementptr i32, ptr %.unpack338, i64 %index
  %wide.load = load <4 x i32>, ptr %35, align 4, !tbaa !3, !alias.scope !9
  %36 = getelementptr i32, ptr %35, i64 4
  %wide.load425 = load <4 x i32>, ptr %36, align 4, !tbaa !3, !alias.scope !9
  %37 = or i64 %index, 1
  %38 = getelementptr i32, ptr %.unpack338, i64 %37
  %wide.load426 = load <4 x i32>, ptr %38, align 4, !tbaa !3, !alias.scope !9
  %39 = getelementptr i32, ptr %38, i64 4
  %wide.load427 = load <4 x i32>, ptr %39, align 4, !tbaa !3, !alias.scope !9
  %40 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %wide.load, <4 x i32> %wide.load426)
  %41 = call <4 x i32> @llvm.smin.v4i32(<4 x i32> %wide.load425, <4 x i32> %wide.load427)
  %42 = or i64 %index, 1
  %43 = getelementptr i32, ptr %.unpack350, i64 %42
  store <4 x i32> %40, ptr %43, align 4, !tbaa !3, !alias.scope !12, !noalias !9
  %44 = getelementptr i32, ptr %43, i64 4
  store <4 x i32> %41, ptr %44, align 4, !tbaa !3, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 8
  %45 = icmp eq i64 %index.next, %n.vec
  br i1 %45, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %33, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader446

.lr.ph.preheader446:                              ; preds = %vector.memcheck, %.lr.ph.preheader, %middle.block
  %indvars.iv.ph = phi i64 [ 2, %vector.memcheck ], [ 2, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %46 = add nuw nsw i64 %32, 1
  %47 = sub nsw i64 %46, %indvars.iv.ph
  %xtraiter = and i64 %47, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader446
  %48 = add nsw i64 %indvars.iv.ph, -2
  %49 = getelementptr i32, ptr %.unpack338, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !3
  %51 = add nsw i64 %indvars.iv.ph, -1
  %52 = getelementptr i32, ptr %.unpack338, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !3
  %54 = call i32 @llvm.smin.i32(i32 %50, i32 %53)
  %55 = add nsw i64 %indvars.iv.ph, -1
  %56 = getelementptr i32, ptr %.unpack350, i64 %55
  store i32 %54, ptr %56, align 4, !tbaa !3
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.ph, 1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader446
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader446 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %57 = icmp eq i64 %indvars.iv.ph, %32
  br i1 %57, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %58 = add i64 %indvars.iv, -2
  %59 = getelementptr i32, ptr %.unpack338, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !3
  %61 = add i64 %indvars.iv, -1
  %62 = getelementptr i32, ptr %.unpack338, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !3
  %64 = call i32 @llvm.smin.i32(i32 %60, i32 %63)
  %65 = add i64 %indvars.iv, -1
  %66 = getelementptr i32, ptr %.unpack350, i64 %65
  store i32 %64, ptr %66, align 4, !tbaa !3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %67 = add i64 %indvars.iv, -1
  %68 = getelementptr i32, ptr %.unpack338, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !3
  %70 = getelementptr i32, ptr %.unpack338, i64 %indvars.iv
  %71 = load i32, ptr %70, align 4, !tbaa !3
  %72 = call i32 @llvm.smin.i32(i32 %69, i32 %71)
  %73 = getelementptr i32, ptr %.unpack350, i64 %indvars.iv
  store i32 %72, ptr %73, align 4, !tbaa !3
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next, %32
  br i1 %exitcond.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %0
  %74 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.0217909891a05e80ea709a5e3f21b8fd, i32 22)
  %.unpack386 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack393.unpack.unpack395 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %75 = icmp sgt i64 %.unpack393.unpack.unpack395, 0
  br i1 %75, label %.lr.ph.i.preheader, label %_FortranASumInteger4x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %._crit_edge
  %min.iters.check430 = icmp ult i64 %.unpack393.unpack.unpack395, 8
  br i1 %min.iters.check430, label %.lr.ph.i.preheader442, label %vector.ph431

vector.ph431:                                     ; preds = %.lr.ph.i.preheader
  %n.vec433 = and i64 %.unpack393.unpack.unpack395, -8
  br label %vector.body436

vector.body436:                                   ; preds = %vector.body436, %vector.ph431
  %index437 = phi i64 [ 0, %vector.ph431 ], [ %index.next441, %vector.body436 ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph431 ], [ %79, %vector.body436 ]
  %vec.phi438 = phi <4 x i32> [ zeroinitializer, %vector.ph431 ], [ %80, %vector.body436 ]
  %76 = shl i64 %index437, 2
  %77 = getelementptr i8, ptr %.unpack386, i64 %76
  %wide.load439 = load <4 x i32>, ptr %77, align 4, !tbaa !3
  %78 = getelementptr i32, ptr %77, i64 4
  %wide.load440 = load <4 x i32>, ptr %78, align 4, !tbaa !3
  %79 = add <4 x i32> %wide.load439, %vec.phi
  %80 = add <4 x i32> %wide.load440, %vec.phi438
  %index.next441 = add nuw i64 %index437, 8
  %81 = icmp eq i64 %index.next441, %n.vec433
  br i1 %81, label %middle.block428, label %vector.body436, !llvm.loop !18

middle.block428:                                  ; preds = %vector.body436
  %bin.rdx = add <4 x i32> %80, %79
  %82 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n435 = icmp eq i64 %.unpack393.unpack.unpack395, %n.vec433
  br i1 %cmp.n435, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader442

.lr.ph.i.preheader442:                            ; preds = %.lr.ph.i.preheader, %middle.block428
  %.ph = phi i32 [ 0, %.lr.ph.i.preheader ], [ %82, %middle.block428 ]
  %.ph443 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec433, %middle.block428 ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader442, %.lr.ph.i
  %83 = phi i32 [ %88, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader442 ]
  %84 = phi i64 [ %89, %.lr.ph.i ], [ %.ph443, %.lr.ph.i.preheader442 ]
  %85 = shl i64 %84, 2
  %86 = getelementptr i8, ptr %.unpack386, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !3
  %88 = add i32 %87, %83
  %89 = add nuw nsw i64 %84, 1
  %exitcond.not.i = icmp eq i64 %89, %.unpack393.unpack.unpack395
  br i1 %exitcond.not.i, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !19

_FortranASumInteger4x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block428, %._crit_edge
  %.lcssa.i = phi i32 [ 0, %._crit_edge ], [ %82, %middle.block428 ], [ %88, %.lr.ph.i ]
  %90 = call i1 @_FortranAioOutputInteger32(ptr %74, i32 %.lcssa.i)
  %91 = call i32 @_FortranAioEndIoStatement(ptr %74)
  ret void
}

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) #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.smin.v4i32(<4 x i32>, <4 x i32>) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind 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}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !15}
!18 = distinct !{!18, !15, !16}
!19 = distinct !{!19, !16, !15}
