program count_order
    implicit none
    integer(4):: n, i, t, pl, ql
    integer(4), allocatable:: p(:), q(:)
    integer(4), parameter:: bi(8) = [1, 2, 6, 24, 120, 720, 5040, 40320]

    read*, n
    allocate(p(n), q(n))
    read*, p(:)
    read*, q(:)
    pl = 0

    do i = 1, n-1
        where(p(i+1:) > p(i))
            p(i+1:) = p(i+1:) - 1
        end where
        p(i) = p(i) * bi(n-i)
    end do

    do i = 1, n-1
        where( q(i+1:) > q(i))
            q(i+1:) = q(i+1:) - 1
        end where
        q(i) = q(i) * bi(n-i)
    end do

    print*, abs(sum(p-q))
end program count_order
; 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"

@_QFECbi = internal unnamed_addr constant [8 x i32] [i32 1, i32 2, i32 6, i32 24, i32 120, i32 720, i32 5040, i32 40320]
@_QFEp.0 = internal unnamed_addr global ptr null
@_QFEp.8 = internal unnamed_addr global i64 0
@_QFEq.0 = internal unnamed_addr global ptr null
@_QFEq.8 = internal unnamed_addr global i64 0
@_QQcl.f353dc61e300234b3344977f841fdf9e = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2689/source.f\00"
@_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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f353dc61e300234b3344977f841fdf9e, i32 7)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = load i32, ptr %3, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 2
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEp.0, align 8, !tbaa !7
  store i64 %9, ptr @_QFEp.8, align 8, !tbaa !7
  %12 = call ptr @malloc(i64 %10)
  store ptr %12, ptr @_QFEq.0, align 8, !tbaa !7
  store i64 %9, ptr @_QFEq.8, align 8, !tbaa !7
  %13 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f353dc61e300234b3344977f841fdf9e, i32 9)
  %.unpack = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %.unpack425.unpack.unpack427 = load i64, ptr @_QFEp.8, align 8, !tbaa !7
  %14 = call i64 @llvm.smax.i64(i64 %.unpack425.unpack.unpack427, i64 0)
  store ptr %.unpack, ptr %2, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, i64 0, i32 7, i64 0, i64 1
  store i64 %14, 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 %2, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %15 = call i1 @_FortranAioInputDescriptor(ptr %13, ptr nonnull %2)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %13)
  %17 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f353dc61e300234b3344977f841fdf9e, i32 10)
  %.unpack430 = load ptr, ptr @_QFEq.0, align 8, !tbaa !7
  %.unpack437.unpack.unpack439 = load i64, ptr @_QFEq.8, align 8, !tbaa !7
  %18 = call i64 @llvm.smax.i64(i64 %.unpack437.unpack.unpack439, i64 0)
  store ptr %.unpack430, ptr %1, align 8, !tbaa !7
  %.fca.1.gep118 = 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.gep118, align 8, !tbaa !7
  %.fca.2.gep120 = 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.gep120, align 8, !tbaa !7
  %.fca.3.gep122 = 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.gep122, align 4, !tbaa !7
  %.fca.4.gep124 = 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.gep124, align 1, !tbaa !7
  %.fca.5.gep126 = 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.gep126, align 2, !tbaa !7
  %.fca.6.gep128 = 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.gep128, align 1, !tbaa !7
  %.fca.7.0.0.gep130 = 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.gep130, align 8, !tbaa !7
  %.fca.7.0.1.gep132 = 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 %18, ptr %.fca.7.0.1.gep132, align 8, !tbaa !7
  %.fca.7.0.2.gep134 = 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.gep134, align 8, !tbaa !7
  %19 = call i1 @_FortranAioInputDescriptor(ptr %17, ptr nonnull %1)
  %20 = call i32 @_FortranAioEndIoStatement(ptr %17)
  %21 = load i32, ptr %3, align 4, !tbaa !3
  %22 = add i32 %21, -1
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph543, label %._crit_edge551

.lr.ph543:                                        ; preds = %0
  %24 = zext i32 %22 to i64
  %.unpack502 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %.unpack509.unpack.unpack511 = load i64, ptr @_QFEp.8, align 8, !tbaa !7
  %25 = add i64 %.unpack509.unpack.unpack511, 1
  %26 = add i64 %.unpack509.unpack.unpack511, 1
  br label %27

27:                                               ; preds = %.lr.ph543, %._crit_edge
  %indvar = phi i32 [ 0, %.lr.ph543 ], [ %indvar.next, %._crit_edge ]
  %indvars.iv = phi i64 [ 1, %.lr.ph543 ], [ %indvars.iv.next, %._crit_edge ]
  %28 = add i32 %indvar, 2
  %29 = sext i32 %28 to i64
  %30 = sub i64 %26, %29
  %smax635 = call i64 @llvm.smax.i64(i64 %30, i64 0)
  %31 = add i32 %indvar, 2
  %32 = sext i32 %31 to i64
  %33 = sub i64 %25, %32
  %smax = call i64 @llvm.smax.i64(i64 %33, i64 0)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext568 = shl i64 %indvars.iv.next, 32
  %34 = ashr exact i64 %sext568, 32
  %35 = sub nsw i64 1, %34
  %36 = add i64 %35, %.unpack509.unpack.unpack511
  %37 = call i64 @llvm.smax.i64(i64 %36, i64 0)
  %38 = add nsw i64 %indvars.iv, -1
  %39 = getelementptr i32, ptr %.unpack502, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !3
  %41 = shl i64 %37, 2
  %42 = call ptr @malloc(i64 %41)
  %.not557 = icmp slt i64 %36, 1
  br i1 %.not557, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %27
  %43 = add nsw i64 %34, -1
  %min.iters.check = icmp ult i64 %smax, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %smax, 9223372036854775800
  %ind.end = sub nsw i64 %37, %n.vec
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %40, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert572 = insertelement <4 x i32> poison, i32 %40, i64 0
  %broadcast.splat573 = shufflevector <4 x i32> %broadcast.splatinsert572, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %44 = add i64 %43, %index
  %45 = getelementptr i32, ptr %.unpack502, i64 %44
  %wide.load = load <4 x i32>, ptr %45, align 4, !tbaa !3
  %46 = getelementptr i32, ptr %45, i64 4
  %wide.load571 = load <4 x i32>, ptr %46, align 4, !tbaa !3
  %47 = icmp sgt <4 x i32> %wide.load, %broadcast.splat
  %48 = icmp sgt <4 x i32> %wide.load571, %broadcast.splat573
  %49 = zext <4 x i1> %47 to <4 x i32>
  %50 = zext <4 x i1> %48 to <4 x i32>
  %51 = getelementptr i32, ptr %42, i64 %index
  store <4 x i32> %49, ptr %51, align 4, !tbaa !3
  %52 = getelementptr i32, ptr %51, i64 4
  store <4 x i32> %50, ptr %52, align 4, !tbaa !3
  %index.next = add nuw i64 %index, 8
  %53 = icmp eq i64 %index.next, %n.vec
  br i1 %53, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %smax, %n.vec
  br i1 %cmp.n, label %.preheader540, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph, %middle.block
  %.ph633 = phi i64 [ %37, %.lr.ph ], [ %ind.end, %middle.block ]
  %.ph634 = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

.preheader540:                                    ; preds = %scalar.ph, %middle.block
  br i1 %.not557, label %._crit_edge, label %.lr.ph541

.lr.ph541:                                        ; preds = %.preheader540
  %54 = add nsw i64 %34, -1
  %xtraiter = and i64 %smax635, 1
  %55 = icmp eq i64 %smax635, 1
  br i1 %55, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph541.new

.lr.ph541.new:                                    ; preds = %.lr.ph541
  %unroll_iter = and i64 %smax635, 9223372036854775806
  br label %67

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %56 = phi i64 [ %65, %scalar.ph ], [ %.ph633, %scalar.ph.preheader ]
  %57 = phi i64 [ %63, %scalar.ph ], [ %.ph634, %scalar.ph.preheader ]
  %58 = add i64 %43, %57
  %59 = getelementptr i32, ptr %.unpack502, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !3
  %61 = icmp sgt i32 %60, %40
  %62 = zext i1 %61 to i32
  %63 = add nuw nsw i64 %57, 1
  %64 = getelementptr i32, ptr %42, i64 %57
  store i32 %62, ptr %64, align 4, !tbaa !3
  %65 = add nsw i64 %56, -1
  %66 = icmp ugt i64 %56, 1
  br i1 %66, label %scalar.ph, label %.preheader540, !llvm.loop !12

67:                                               ; preds = %86, %.lr.ph541.new
  %68 = phi i64 [ 0, %.lr.ph541.new ], [ %78, %86 ]
  %niter = phi i64 [ 0, %.lr.ph541.new ], [ %niter.next.1, %86 ]
  %69 = or i64 %68, 1
  %70 = getelementptr i32, ptr %42, i64 %68
  %71 = load i32, ptr %70, align 4, !tbaa !3
  %.not538 = icmp eq i32 %71, 0
  br i1 %.not538, label %77, label %72

72:                                               ; preds = %67
  %73 = add i64 %54, %68
  %74 = getelementptr i32, ptr %.unpack502, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !3
  %76 = add i32 %75, -1
  store i32 %76, ptr %74, align 4, !tbaa !3
  br label %77

77:                                               ; preds = %72, %67
  %78 = add nuw nsw i64 %68, 2
  %79 = getelementptr i32, ptr %42, i64 %69
  %80 = load i32, ptr %79, align 4, !tbaa !3
  %.not538.1 = icmp eq i32 %80, 0
  br i1 %.not538.1, label %86, label %81

81:                                               ; preds = %77
  %82 = add i64 %54, %69
  %83 = getelementptr i32, ptr %.unpack502, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !3
  %85 = add i32 %84, -1
  store i32 %85, ptr %83, align 4, !tbaa !3
  br label %86

86:                                               ; preds = %81, %77
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1.not = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1.not, label %._crit_edge.loopexit.unr-lcssa, label %67

._crit_edge.loopexit.unr-lcssa:                   ; preds = %86, %.lr.ph541
  %.unr636 = phi i64 [ 0, %.lr.ph541 ], [ %78, %86 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa
  %87 = getelementptr i32, ptr %42, i64 %.unr636
  %88 = load i32, ptr %87, align 4, !tbaa !3
  %.not538.epil = icmp eq i32 %88, 0
  br i1 %.not538.epil, label %._crit_edge.loopexit, label %89

89:                                               ; preds = %.epil.preheader
  %90 = add i64 %54, %.unr636
  %91 = getelementptr i32, ptr %.unpack502, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !3
  %93 = add i32 %92, -1
  store i32 %93, ptr %91, align 4, !tbaa !3
  br label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %.epil.preheader, %89, %._crit_edge.loopexit.unr-lcssa
  %.pre = load i32, ptr %39, align 4, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %27, %._crit_edge.loopexit, %.preheader540
  %94 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %40, %.preheader540 ], [ %40, %27 ]
  call void @free(ptr %42)
  %95 = load i32, ptr %3, align 4, !tbaa !3
  %96 = trunc i64 %indvars.iv to i32
  %97 = sub i32 %95, %96
  %98 = sext i32 %97 to i64
  %99 = add nsw i64 %98, -1
  %100 = getelementptr [8 x i32], ptr @_QFECbi, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !3
  %102 = mul i32 %101, %94
  store i32 %102, ptr %39, align 4, !tbaa !3
  %exitcond.not = icmp eq i64 %indvars.iv, %24
  %indvar.next = add i32 %indvar, 1
  br i1 %exitcond.not, label %._crit_edge544, label %27

._crit_edge544:                                   ; preds = %._crit_edge
  %.pre565 = load i32, ptr %3, align 4, !tbaa !3
  %.pre567 = add i32 %.pre565, -1
  %103 = icmp sgt i32 %.pre567, 0
  br i1 %103, label %.lr.ph550, label %._crit_edge551

.lr.ph550:                                        ; preds = %._crit_edge544
  %104 = zext i32 %.pre567 to i64
  %.unpack466 = load ptr, ptr @_QFEq.0, align 8, !tbaa !7
  %.unpack473.unpack.unpack475 = load i64, ptr @_QFEq.8, align 8, !tbaa !7
  %105 = add i64 %.unpack473.unpack.unpack475, 1
  %106 = add i64 %.unpack473.unpack.unpack475, 1
  br label %107

107:                                              ; preds = %.lr.ph550, %._crit_edge548
  %indvar574 = phi i32 [ 0, %.lr.ph550 ], [ %indvar.next575, %._crit_edge548 ]
  %indvars.iv560 = phi i64 [ 1, %.lr.ph550 ], [ %indvars.iv.next561, %._crit_edge548 ]
  %108 = add i32 %indvar574, 2
  %109 = sext i32 %108 to i64
  %110 = sub i64 %106, %109
  %smax638 = call i64 @llvm.smax.i64(i64 %110, i64 0)
  %111 = add i32 %indvar574, 2
  %112 = sext i32 %111 to i64
  %113 = sub i64 %105, %112
  %smax576 = call i64 @llvm.smax.i64(i64 %113, i64 0)
  %indvars.iv.next561 = add nuw nsw i64 %indvars.iv560, 1
  %sext = shl i64 %indvars.iv.next561, 32
  %114 = ashr exact i64 %sext, 32
  %115 = sub nsw i64 1, %114
  %116 = add i64 %115, %.unpack473.unpack.unpack475
  %117 = call i64 @llvm.smax.i64(i64 %116, i64 0)
  %118 = add nsw i64 %indvars.iv560, -1
  %119 = getelementptr i32, ptr %.unpack466, i64 %118
  %120 = load i32, ptr %119, align 4, !tbaa !3
  %121 = shl i64 %117, 2
  %122 = call ptr @malloc(i64 %121)
  %.not555 = icmp slt i64 %116, 1
  br i1 %.not555, label %._crit_edge548, label %.lr.ph546

.lr.ph546:                                        ; preds = %107
  %123 = add nsw i64 %114, -1
  %min.iters.check579 = icmp ult i64 %smax576, 8
  br i1 %min.iters.check579, label %scalar.ph578.preheader, label %vector.ph580

vector.ph580:                                     ; preds = %.lr.ph546
  %n.vec582 = and i64 %smax576, 9223372036854775800
  %ind.end583 = sub nsw i64 %117, %n.vec582
  %broadcast.splatinsert591 = insertelement <4 x i32> poison, i32 %120, i64 0
  %broadcast.splat592 = shufflevector <4 x i32> %broadcast.splatinsert591, <4 x i32> poison, <4 x i32> zeroinitializer
  %broadcast.splatinsert593 = insertelement <4 x i32> poison, i32 %120, i64 0
  %broadcast.splat594 = shufflevector <4 x i32> %broadcast.splatinsert593, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body587

vector.body587:                                   ; preds = %vector.body587, %vector.ph580
  %index588 = phi i64 [ 0, %vector.ph580 ], [ %index.next595, %vector.body587 ]
  %124 = add i64 %123, %index588
  %125 = getelementptr i32, ptr %.unpack466, i64 %124
  %wide.load589 = load <4 x i32>, ptr %125, align 4, !tbaa !3
  %126 = getelementptr i32, ptr %125, i64 4
  %wide.load590 = load <4 x i32>, ptr %126, align 4, !tbaa !3
  %127 = icmp sgt <4 x i32> %wide.load589, %broadcast.splat592
  %128 = icmp sgt <4 x i32> %wide.load590, %broadcast.splat594
  %129 = zext <4 x i1> %127 to <4 x i32>
  %130 = zext <4 x i1> %128 to <4 x i32>
  %131 = getelementptr i32, ptr %122, i64 %index588
  store <4 x i32> %129, ptr %131, align 4, !tbaa !3
  %132 = getelementptr i32, ptr %131, i64 4
  store <4 x i32> %130, ptr %132, align 4, !tbaa !3
  %index.next595 = add nuw i64 %index588, 8
  %133 = icmp eq i64 %index.next595, %n.vec582
  br i1 %133, label %middle.block577, label %vector.body587, !llvm.loop !13

middle.block577:                                  ; preds = %vector.body587
  %cmp.n586 = icmp eq i64 %smax576, %n.vec582
  br i1 %cmp.n586, label %.preheader, label %scalar.ph578.preheader

scalar.ph578.preheader:                           ; preds = %.lr.ph546, %middle.block577
  %.ph631 = phi i64 [ %117, %.lr.ph546 ], [ %ind.end583, %middle.block577 ]
  %.ph632 = phi i64 [ 0, %.lr.ph546 ], [ %n.vec582, %middle.block577 ]
  br label %scalar.ph578

.preheader:                                       ; preds = %scalar.ph578, %middle.block577
  br i1 %.not555, label %._crit_edge548, label %.lr.ph547

.lr.ph547:                                        ; preds = %.preheader
  %134 = add nsw i64 %114, -1
  %xtraiter639 = and i64 %smax638, 1
  %135 = icmp eq i64 %smax638, 1
  br i1 %135, label %._crit_edge548.loopexit.unr-lcssa, label %.lr.ph547.new

.lr.ph547.new:                                    ; preds = %.lr.ph547
  %unroll_iter642 = and i64 %smax638, 9223372036854775806
  br label %147

scalar.ph578:                                     ; preds = %scalar.ph578.preheader, %scalar.ph578
  %136 = phi i64 [ %145, %scalar.ph578 ], [ %.ph631, %scalar.ph578.preheader ]
  %137 = phi i64 [ %143, %scalar.ph578 ], [ %.ph632, %scalar.ph578.preheader ]
  %138 = add i64 %123, %137
  %139 = getelementptr i32, ptr %.unpack466, i64 %138
  %140 = load i32, ptr %139, align 4, !tbaa !3
  %141 = icmp sgt i32 %140, %120
  %142 = zext i1 %141 to i32
  %143 = add nuw nsw i64 %137, 1
  %144 = getelementptr i32, ptr %122, i64 %137
  store i32 %142, ptr %144, align 4, !tbaa !3
  %145 = add nsw i64 %136, -1
  %146 = icmp ugt i64 %136, 1
  br i1 %146, label %scalar.ph578, label %.preheader, !llvm.loop !14

147:                                              ; preds = %166, %.lr.ph547.new
  %148 = phi i64 [ 0, %.lr.ph547.new ], [ %158, %166 ]
  %niter643 = phi i64 [ 0, %.lr.ph547.new ], [ %niter643.next.1, %166 ]
  %149 = or i64 %148, 1
  %150 = getelementptr i32, ptr %122, i64 %148
  %151 = load i32, ptr %150, align 4, !tbaa !3
  %.not = icmp eq i32 %151, 0
  br i1 %.not, label %157, label %152

152:                                              ; preds = %147
  %153 = add i64 %134, %148
  %154 = getelementptr i32, ptr %.unpack466, i64 %153
  %155 = load i32, ptr %154, align 4, !tbaa !3
  %156 = add i32 %155, -1
  store i32 %156, ptr %154, align 4, !tbaa !3
  br label %157

157:                                              ; preds = %152, %147
  %158 = add nuw nsw i64 %148, 2
  %159 = getelementptr i32, ptr %122, i64 %149
  %160 = load i32, ptr %159, align 4, !tbaa !3
  %.not.1 = icmp eq i32 %160, 0
  br i1 %.not.1, label %166, label %161

161:                                              ; preds = %157
  %162 = add i64 %134, %149
  %163 = getelementptr i32, ptr %.unpack466, i64 %162
  %164 = load i32, ptr %163, align 4, !tbaa !3
  %165 = add i32 %164, -1
  store i32 %165, ptr %163, align 4, !tbaa !3
  br label %166

166:                                              ; preds = %161, %157
  %niter643.next.1 = add i64 %niter643, 2
  %niter643.ncmp.1.not = icmp eq i64 %niter643.next.1, %unroll_iter642
  br i1 %niter643.ncmp.1.not, label %._crit_edge548.loopexit.unr-lcssa, label %147

._crit_edge548.loopexit.unr-lcssa:                ; preds = %166, %.lr.ph547
  %.unr640 = phi i64 [ 0, %.lr.ph547 ], [ %158, %166 ]
  %lcmp.mod641.not = icmp eq i64 %xtraiter639, 0
  br i1 %lcmp.mod641.not, label %._crit_edge548.loopexit, label %.epil.preheader637

.epil.preheader637:                               ; preds = %._crit_edge548.loopexit.unr-lcssa
  %167 = getelementptr i32, ptr %122, i64 %.unr640
  %168 = load i32, ptr %167, align 4, !tbaa !3
  %.not.epil = icmp eq i32 %168, 0
  br i1 %.not.epil, label %._crit_edge548.loopexit, label %169

169:                                              ; preds = %.epil.preheader637
  %170 = add i64 %134, %.unr640
  %171 = getelementptr i32, ptr %.unpack466, i64 %170
  %172 = load i32, ptr %171, align 4, !tbaa !3
  %173 = add i32 %172, -1
  store i32 %173, ptr %171, align 4, !tbaa !3
  br label %._crit_edge548.loopexit

._crit_edge548.loopexit:                          ; preds = %.epil.preheader637, %169, %._crit_edge548.loopexit.unr-lcssa
  %.pre566 = load i32, ptr %119, align 4, !tbaa !3
  br label %._crit_edge548

._crit_edge548:                                   ; preds = %107, %._crit_edge548.loopexit, %.preheader
  %174 = phi i32 [ %.pre566, %._crit_edge548.loopexit ], [ %120, %.preheader ], [ %120, %107 ]
  call void @free(ptr %122)
  %175 = load i32, ptr %3, align 4, !tbaa !3
  %176 = trunc i64 %indvars.iv560 to i32
  %177 = sub i32 %175, %176
  %178 = sext i32 %177 to i64
  %179 = add nsw i64 %178, -1
  %180 = getelementptr [8 x i32], ptr @_QFECbi, i64 0, i64 %179
  %181 = load i32, ptr %180, align 4, !tbaa !3
  %182 = mul i32 %181, %174
  store i32 %182, ptr %119, align 4, !tbaa !3
  %exitcond563.not = icmp eq i64 %indvars.iv560, %104
  %indvar.next575 = add i32 %indvar574, 1
  br i1 %exitcond563.not, label %._crit_edge551, label %107

._crit_edge551:                                   ; preds = %._crit_edge548, %0, %._crit_edge544
  %183 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.f353dc61e300234b3344977f841fdf9e, i32 27)
  %.unpack442 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %.unpack449.unpack.unpack451 = load i64, ptr @_QFEp.8, align 8, !tbaa !7
  %.unpack454 = load ptr, ptr @_QFEq.0, align 8, !tbaa !7
  %184 = shl i64 %.unpack449.unpack.unpack451, 2
  %185 = call ptr @malloc(i64 %184)
  %186 = icmp sgt i64 %.unpack449.unpack.unpack451, 0
  br i1 %186, label %.lr.ph553.preheader, label %_FortranASumInteger4x1_contract_simplified.exit

.lr.ph553.preheader:                              ; preds = %._crit_edge551
  %min.iters.check598 = icmp ult i64 %.unpack449.unpack.unpack451, 8
  br i1 %min.iters.check598, label %.lr.ph553.preheader629, label %vector.ph599

vector.ph599:                                     ; preds = %.lr.ph553.preheader
  %n.vec601 = and i64 %.unpack449.unpack.unpack451, -8
  br label %vector.body604

vector.body604:                                   ; preds = %vector.body604, %vector.ph599
  %index605 = phi i64 [ 0, %vector.ph599 ], [ %index.next610, %vector.body604 ]
  %187 = getelementptr i32, ptr %.unpack442, i64 %index605
  %wide.load606 = load <4 x i32>, ptr %187, align 4, !tbaa !3
  %188 = getelementptr i32, ptr %187, i64 4
  %wide.load607 = load <4 x i32>, ptr %188, align 4, !tbaa !3
  %189 = getelementptr i32, ptr %.unpack454, i64 %index605
  %wide.load608 = load <4 x i32>, ptr %189, align 4, !tbaa !3
  %190 = getelementptr i32, ptr %189, i64 4
  %wide.load609 = load <4 x i32>, ptr %190, align 4, !tbaa !3
  %191 = sub <4 x i32> %wide.load606, %wide.load608
  %192 = sub <4 x i32> %wide.load607, %wide.load609
  %193 = getelementptr i32, ptr %185, i64 %index605
  store <4 x i32> %191, ptr %193, align 4, !tbaa !3
  %194 = getelementptr i32, ptr %193, i64 4
  store <4 x i32> %192, ptr %194, align 4, !tbaa !3
  %index.next610 = add nuw i64 %index605, 8
  %195 = icmp eq i64 %index.next610, %n.vec601
  br i1 %195, label %middle.block596, label %vector.body604, !llvm.loop !15

middle.block596:                                  ; preds = %vector.body604
  %cmp.n603 = icmp eq i64 %.unpack449.unpack.unpack451, %n.vec601
  br i1 %cmp.n603, label %._crit_edge554, label %.lr.ph553.preheader629

.lr.ph553.preheader629:                           ; preds = %.lr.ph553.preheader, %middle.block596
  %.ph630 = phi i64 [ 0, %.lr.ph553.preheader ], [ %n.vec601, %middle.block596 ]
  br label %.lr.ph553

.lr.ph553:                                        ; preds = %.lr.ph553.preheader629, %.lr.ph553
  %196 = phi i64 [ %202, %.lr.ph553 ], [ %.ph630, %.lr.ph553.preheader629 ]
  %197 = getelementptr i32, ptr %.unpack442, i64 %196
  %198 = load i32, ptr %197, align 4, !tbaa !3
  %199 = getelementptr i32, ptr %.unpack454, i64 %196
  %200 = load i32, ptr %199, align 4, !tbaa !3
  %201 = sub i32 %198, %200
  %202 = add nuw nsw i64 %196, 1
  %203 = getelementptr i32, ptr %185, i64 %196
  store i32 %201, ptr %203, align 4, !tbaa !3
  %exitcond564.not = icmp eq i64 %202, %.unpack449.unpack.unpack451
  br i1 %exitcond564.not, label %._crit_edge554, label %.lr.ph553, !llvm.loop !16

._crit_edge554:                                   ; preds = %.lr.ph553, %middle.block596
  br i1 %186, label %.lr.ph.i.preheader, label %_FortranASumInteger4x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %._crit_edge554
  %min.iters.check613 = icmp ult i64 %.unpack449.unpack.unpack451, 8
  br i1 %min.iters.check613, label %.lr.ph.i.preheader625, label %vector.ph614

vector.ph614:                                     ; preds = %.lr.ph.i.preheader
  %n.vec616 = and i64 %.unpack449.unpack.unpack451, -8
  br label %vector.body619

vector.body619:                                   ; preds = %vector.body619, %vector.ph614
  %index620 = phi i64 [ 0, %vector.ph614 ], [ %index.next624, %vector.body619 ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph614 ], [ %207, %vector.body619 ]
  %vec.phi621 = phi <4 x i32> [ zeroinitializer, %vector.ph614 ], [ %208, %vector.body619 ]
  %204 = shl i64 %index620, 2
  %205 = getelementptr i8, ptr %185, i64 %204
  %wide.load622 = load <4 x i32>, ptr %205, align 4, !tbaa !3
  %206 = getelementptr i32, ptr %205, i64 4
  %wide.load623 = load <4 x i32>, ptr %206, align 4, !tbaa !3
  %207 = add <4 x i32> %wide.load622, %vec.phi
  %208 = add <4 x i32> %wide.load623, %vec.phi621
  %index.next624 = add nuw i64 %index620, 8
  %209 = icmp eq i64 %index.next624, %n.vec616
  br i1 %209, label %middle.block611, label %vector.body619, !llvm.loop !17

middle.block611:                                  ; preds = %vector.body619
  %bin.rdx = add <4 x i32> %208, %207
  %210 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n618 = icmp eq i64 %.unpack449.unpack.unpack451, %n.vec616
  br i1 %cmp.n618, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader625

.lr.ph.i.preheader625:                            ; preds = %.lr.ph.i.preheader, %middle.block611
  %.ph = phi i32 [ 0, %.lr.ph.i.preheader ], [ %210, %middle.block611 ]
  %.ph626 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec616, %middle.block611 ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader625, %.lr.ph.i
  %211 = phi i32 [ %216, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader625 ]
  %212 = phi i64 [ %217, %.lr.ph.i ], [ %.ph626, %.lr.ph.i.preheader625 ]
  %213 = shl i64 %212, 2
  %214 = getelementptr i8, ptr %185, i64 %213
  %215 = load i32, ptr %214, align 4, !tbaa !3
  %216 = add i32 %215, %211
  %217 = add nuw nsw i64 %212, 1
  %exitcond.not.i = icmp eq i64 %217, %.unpack449.unpack.unpack451
  br i1 %exitcond.not.i, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !18

_FortranASumInteger4x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block611, %._crit_edge551, %._crit_edge554
  %.lcssa.i = phi i32 [ 0, %._crit_edge554 ], [ 0, %._crit_edge551 ], [ %210, %middle.block611 ], [ %216, %.lr.ph.i ]
  %218 = call i32 @llvm.abs.i32(i32 %.lcssa.i, i1 false)
  %219 = call i1 @_FortranAioOutputInteger32(ptr %183, i32 %218)
  call void @free(ptr %185)
  %220 = call i32 @_FortranAioEndIoStatement(ptr %183)
  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 @_FortranAioBeginExternalListOutput(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 i64 @llvm.smax.i64(i64, i64) #2

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

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

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

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