(TranslationUnit
    [(Module
        random
        (TriviaNode
            [(EndOfLine)
            (EndOfLine)]
            []
        )
        [(Use
            []
            types
            [(UseSymbol
                dp
                ()
            )]
            .true.
            ()
        )
        (Use
            []
            utils
            [(UseSymbol
                stop_error
                ()
            )]
            .true.
            ()
        )]
        [(ImplicitNone
            []
            ()
        )]
        [(Declaration
            ()
            [(SimpleAttribute
                AttrPrivate
            )]
            []
            ()
        )
        (Declaration
            ()
            [(SimpleAttribute
                AttrPublic
            )]
            [(randn
            []
            []
            ()
            ()
            None
            ())
            (rand_gamma
            []
            []
            ()
            ()
            None
            ())]
            (TriviaNode
                []
                [(EndOfLine)
                (EndOfLine)]
            )
        )
        (Interface
            (InterfaceHeaderName
                randn
            )
            (TriviaNode
                []
                [(EndOfLine)
                (EndOfLine)]
            )
            [(InterfaceModuleProcedure
                [randn_scalar]
                [(SimpleAttribute
                    AttrModule
                )]
                ()
            )
            (InterfaceModuleProcedure
                [randn_vector]
                [(SimpleAttribute
                    AttrModule
                )]
                ()
            )
            (InterfaceModuleProcedure
                [randn_matrix]
                [(SimpleAttribute
                    AttrModule
                )]
                ()
            )
            (InterfaceModuleProcedure
                [randn_vector_n]
                [(SimpleAttribute
                    AttrModule
                )]
                ()
            )]
        )
        (Interface
            (InterfaceHeaderName
                rand_gamma
            )
            (TriviaNode
                []
                [(EndOfLine)
                (EndOfLine)]
            )
            [(InterfaceModuleProcedure
                [rand_gamma_scalar]
                [(SimpleAttribute
                    AttrModule
                )]
                ()
            )
            (InterfaceModuleProcedure
                [rand_gamma_vector]
                [(SimpleAttribute
                    AttrModule
                )]
                ()
            )
            (InterfaceModuleProcedure
                [rand_gamma_matrix]
                [(SimpleAttribute
                    AttrModule
                )]
                ()
            )
            (InterfaceModuleProcedure
                [rand_gamma_vector_n]
                [(SimpleAttribute
                    AttrModule
                )]
                ()
            )]
        )]
        []
        [(Subroutine
            randn_scalar
            [(x)]
            []
            ()
            (TriviaNode
                [(EndOfLine)
                (Comment
                    "! Returns a psuedorandom scalar drawn from the standard normal distribution."
                )
                (Comment
                    "!"
                )
                (Comment
                    "! [1] Marsaglia, G., & Bray, T. A. (1964). A Convenient Method for Generating"
                )
                (Comment
                    "!       Normal Variables. SIAM Review, 6(3), 260-264."
                )]
                [(EndOfLine)
                (EndOfLine)]
            )
            []
            []
            []
            [(Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    Out
                )]
                [(x
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeLogical
                    []
                    ()
                    ()
                    None
                )
                [(SimpleAttribute
                    AttrSave
                )]
                [(first
                []
                []
                ()
                (Logical .true. ())
                Equal
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(SimpleAttribute
                    AttrSave
                )]
                [(u
                [(1
                2
                DimensionExpr)]
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                []
                [(r2
                []
                []
                ()
                ()
                None
                ())]
                ()
            )]
            [(If
                0
                ()
                first
                [(DoLoop
                    0
                    ()
                    0
                    ()
                    ()
                    ()
                    ()
                    [(SubroutineCall
                        0
                        random_number
                        []
                        [(()
                        u
                        ()
                        0)]
                        []
                        []
                        ()
                    )
                    (Assignment
                        0
                        u
                        (- (* 2 u) 1)
                        ()
                    )
                    (Assignment
                        0
                        r2
                        (FuncCallOrArray
                            sum
                            []
                            [(()
                            (** u 2)
                            ()
                            0)]
                            []
                            []
                            []
                        )
                        ()
                    )
                    (If
                        0
                        ()
                        (BoolOp
                            (< r2 1)
                            And
                            (> r2 0)
                        )
                        [(Exit
                            0
                            ()
                            ()
                        )]
                        []
                        ()
                        ()
                        ()
                    )]
                    ()
                    ()
                )
                (Assignment
                    0
                    u
                    (* u (FuncCallOrArray
                        sqrt
                        []
                        [(()
                        (/ (* (u- 2) (FuncCallOrArray
                            log
                            []
                            [(()
                            r2
                            ()
                            0)]
                            []
                            []
                            []
                        )) r2)
                        ()
                        0)]
                        []
                        []
                        []
                    ))
                    ()
                )
                (Assignment
                    0
                    x
                    (FuncCallOrArray
                        u
                        []
                        [(()
                        1
                        ()
                        0)]
                        []
                        []
                        []
                    )
                    ()
                )]
                [(Assignment
                    0
                    x
                    (FuncCallOrArray
                        u
                        []
                        [(()
                        2
                        ()
                        0)]
                        []
                        []
                        []
                    )
                    ()
                )]
                ()
                ()
                ()
            )
            (Assignment
                0
                first
                (not first)
                ()
            )]
            []
            []
        )
        (Subroutine
            randn_vector_n
            [(n)
            (x)]
            []
            ()
            (TriviaNode
                []
                [(EndOfLine)
                (EndOfLine)]
            )
            []
            []
            []
            [(Declaration
                (AttrType
                    TypeInteger
                    []
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    In
                )]
                [(n
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    Out
                )]
                [(x
                [(1
                n
                DimensionExpr)]
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeInteger
                    []
                    ()
                    ()
                    None
                )
                []
                [(i
                []
                []
                ()
                ()
                None
                ())]
                ()
            )]
            [(DoLoop
                0
                ()
                0
                i
                1
                (FuncCallOrArray
                    size
                    []
                    [(()
                    x
                    ()
                    0)]
                    []
                    []
                    []
                )
                ()
                [(SubroutineCall
                    0
                    randn
                    []
                    [(()
                    (FuncCallOrArray
                        x
                        []
                        [(()
                        i
                        ()
                        0)]
                        []
                        []
                        []
                    )
                    ()
                    0)]
                    []
                    []
                    ()
                )]
                ()
                ()
            )]
            []
            []
        )
        (Subroutine
            randn_vector
            [(x)]
            []
            ()
            (TriviaNode
                []
                [(EndOfLine)
                (EndOfLine)]
            )
            []
            []
            []
            [(Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    Out
                )]
                [(x
                [(()
                ()
                DimensionExpr)]
                []
                ()
                ()
                None
                ())]
                ()
            )]
            [(SubroutineCall
                0
                randn_vector_n
                []
                [(()
                (FuncCallOrArray
                    size
                    []
                    [(()
                    x
                    ()
                    0)]
                    []
                    []
                    []
                )
                ()
                0)
                (()
                x
                ()
                0)]
                []
                []
                ()
            )]
            []
            []
        )
        (Subroutine
            randn_matrix
            [(x)]
            []
            ()
            (TriviaNode
                []
                [(EndOfLine)
                (EndOfLine)]
            )
            []
            []
            []
            [(Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    Out
                )]
                [(x
                [(()
                ()
                DimensionExpr)
                (()
                ()
                DimensionExpr)]
                []
                ()
                ()
                None
                ())]
                ()
            )]
            [(SubroutineCall
                0
                randn_vector_n
                []
                [(()
                (FuncCallOrArray
                    size
                    []
                    [(()
                    x
                    ()
                    0)]
                    []
                    []
                    []
                )
                ()
                0)
                (()
                x
                ()
                0)]
                []
                []
                ()
            )]
            []
            []
        )
        (Subroutine
            rand_gamma0
            [(a)
            (first)
            (fn_val)]
            []
            ()
            (TriviaNode
                [(EndOfLine)
                (Comment
                    "! Returns a psuedorandom scalar drawn from the gamma distribution."
                )
                (Comment
                    "!"
                )
                (Comment
                    "! The shape parameter a >= 1."
                )
                (Comment
                    "!"
                )
                (Comment
                    "! [1] Marsaglia, G., & Tsang, W. W. (2000). A Simple Method for Generating"
                )
                (Comment
                    "! Gamma Variables. ACM Transactions on Mathematical Software (TOMS), 26(3),"
                )
                (Comment
                    "! 363-372."
                )]
                [(EndOfLine)
                (EndOfLine)]
            )
            []
            []
            []
            [(Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    In
                )]
                [(a
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeLogical
                    []
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    In
                )]
                [(first
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    Out
                )]
                [(fn_val
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(SimpleAttribute
                    AttrSave
                )]
                [(c
                []
                []
                ()
                ()
                None
                ())
                (d
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                []
                [(U
                []
                []
                ()
                ()
                None
                ())
                (v
                []
                []
                ()
                ()
                None
                ())
                (x
                []
                []
                ()
                ()
                None
                ())]
                ()
            )]
            [(If
                0
                ()
                (< a 1)
                [(SubroutineCall
                    0
                    stop_error
                    []
                    [(()
                    (String "Shape parameter must be >= 1" ())
                    ()
                    0)]
                    []
                    []
                    ()
                )]
                []
                ()
                ()
                ()
            )
            (If
                0
                ()
                first
                [(Assignment
                    0
                    d
                    (- a (/ (Real "1._dp") 3))
                    ()
                )
                (Assignment
                    0
                    c
                    (/ 1 (FuncCallOrArray
                        sqrt
                        []
                        [(()
                        (* 9 d)
                        ()
                        0)]
                        []
                        []
                        []
                    ))
                    ()
                )]
                []
                ()
                ()
                ()
            )
            (DoLoop
                0
                ()
                0
                ()
                ()
                ()
                ()
                [(DoLoop
                    0
                    ()
                    0
                    ()
                    ()
                    ()
                    ()
                    [(SubroutineCall
                        0
                        randn
                        []
                        [(()
                        x
                        ()
                        0)]
                        []
                        []
                        ()
                    )
                    (Assignment
                        0
                        v
                        (** (+ 1 (* c x)) 3)
                        ()
                    )
                    (If
                        0
                        ()
                        (> v 0)
                        [(Exit
                            0
                            ()
                            ()
                        )]
                        []
                        ()
                        ()
                        ()
                    )]
                    ()
                    ()
                )
                (SubroutineCall
                    0
                    random_number
                    []
                    [(()
                    U
                    ()
                    0)]
                    []
                    []
                    (TriviaNode
                        []
                        [(EndOfLine)
                        (Comment
                            "! Note: the number 0.0331 below is exact, see [1]."
                        )]
                    )
                )
                (If
                    0
                    ()
                    (< U (- 1 (* (Real "0.0331_dp") (** x 4))))
                    [(Assignment
                        0
                        fn_val
                        (* d v)
                        ()
                    )
                    (Exit
                        0
                        ()
                        ()
                    )]
                    [(If
                        0
                        ()
                        (< (FuncCallOrArray
                            log
                            []
                            [(()
                            U
                            ()
                            0)]
                            []
                            []
                            []
                        ) (+ (/ (** x 2) 2) (* d (+ (- 1 v) (FuncCallOrArray
                            log
                            []
                            [(()
                            v
                            ()
                            0)]
                            []
                            []
                            []
                        )))))
                        [(Assignment
                            0
                            fn_val
                            (* d v)
                            ()
                        )
                        (Exit
                            0
                            ()
                            ()
                        )]
                        []
                        ()
                        ()
                        ()
                    )]
                    ()
                    ()
                    ()
                )]
                ()
                ()
            )]
            []
            []
        )
        (Subroutine
            rand_gamma_scalar
            [(a)
            (x)]
            []
            ()
            (TriviaNode
                []
                [(EndOfLine)
                (EndOfLine)]
            )
            []
            []
            []
            [(Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    In
                )]
                [(a
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    Out
                )]
                [(x
                []
                []
                ()
                ()
                None
                ())]
                ()
            )]
            [(SubroutineCall
                0
                rand_gamma0
                []
                [(()
                a
                ()
                0)
                (()
                (Logical .true. ())
                ()
                0)
                (()
                x
                ()
                0)]
                []
                []
                ()
            )]
            []
            []
        )
        (Subroutine
            rand_gamma_vector_n
            [(a)
            (n)
            (x)]
            []
            ()
            (TriviaNode
                []
                [(EndOfLine)
                (EndOfLine)]
            )
            []
            []
            []
            [(Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    In
                )]
                [(a
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeInteger
                    []
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    In
                )]
                [(n
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    Out
                )]
                [(x
                [(1
                n
                DimensionExpr)]
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeInteger
                    []
                    ()
                    ()
                    None
                )
                []
                [(i
                []
                []
                ()
                ()
                None
                ())]
                ()
            )]
            [(SubroutineCall
                0
                rand_gamma0
                []
                [(()
                a
                ()
                0)
                (()
                (Logical .true. ())
                ()
                0)
                (()
                (FuncCallOrArray
                    x
                    []
                    [(()
                    1
                    ()
                    0)]
                    []
                    []
                    []
                )
                ()
                0)]
                []
                []
                ()
            )
            (DoLoop
                0
                ()
                0
                i
                2
                (FuncCallOrArray
                    size
                    []
                    [(()
                    x
                    ()
                    0)]
                    []
                    []
                    []
                )
                ()
                [(SubroutineCall
                    0
                    rand_gamma0
                    []
                    [(()
                    a
                    ()
                    0)
                    (()
                    (Logical .false. ())
                    ()
                    0)
                    (()
                    (FuncCallOrArray
                        x
                        []
                        [(()
                        i
                        ()
                        0)]
                        []
                        []
                        []
                    )
                    ()
                    0)]
                    []
                    []
                    ()
                )]
                ()
                ()
            )]
            []
            []
        )
        (Subroutine
            rand_gamma_vector
            [(a)
            (x)]
            []
            ()
            (TriviaNode
                []
                [(EndOfLine)
                (EndOfLine)]
            )
            []
            []
            []
            [(Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    In
                )]
                [(a
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    Out
                )]
                [(x
                [(()
                ()
                DimensionExpr)]
                []
                ()
                ()
                None
                ())]
                ()
            )]
            [(SubroutineCall
                0
                rand_gamma_vector_n
                []
                [(()
                a
                ()
                0)
                (()
                (FuncCallOrArray
                    size
                    []
                    [(()
                    x
                    ()
                    0)]
                    []
                    []
                    []
                )
                ()
                0)
                (()
                x
                ()
                0)]
                []
                []
                ()
            )]
            []
            []
        )
        (Subroutine
            rand_gamma_matrix
            [(a)
            (x)]
            []
            ()
            (TriviaNode
                []
                [(EndOfLine)
                (EndOfLine)]
            )
            []
            []
            []
            [(Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    In
                )]
                [(a
                []
                []
                ()
                ()
                None
                ())]
                ()
            )
            (Declaration
                (AttrType
                    TypeReal
                    [(()
                    dp
                    Value)]
                    ()
                    ()
                    None
                )
                [(AttrIntent
                    Out
                )]
                [(x
                [(()
                ()
                DimensionExpr)
                (()
                ()
                DimensionExpr)]
                []
                ()
                ()
                None
                ())]
                ()
            )]
            [(SubroutineCall
                0
                rand_gamma_vector_n
                []
                [(()
                a
                ()
                0)
                (()
                (FuncCallOrArray
                    size
                    []
                    [(()
                    x
                    ()
                    0)]
                    []
                    []
                    []
                )
                ()
                0)
                (()
                x
                ()
                0)]
                []
                []
                ()
            )]
            []
            []
        )]
    )]
)
