Extract all global operation blocks (all blocks following GlobalOperationsStart).

    Args:
        ir_blocks_except_output_and_folds: list of IR blocks (excluding ConstructResult and all
                                           fold blocks), to extract global operations from

    Returns:
        tuple (global_operation_blocks, remaining_ir_blocks):
        - global_operation_blocks: list of IR blocks following a GlobalOperationsStart block if it
                                   exists, and an empty list otherwise
        - remaining_ir_blocks: list of IR blocks excluding GlobalOperationsStart and all global
                               operation blocks

def _extract_global_operations(ir_blocks_except_output_and_folds):
    """Extract all global operation blocks (all blocks following GlobalOperationsStart).

    Args:
        ir_blocks_except_output_and_folds: list of IR blocks (excluding ConstructResult and all
                                           fold blocks), to extract global operations from

    Returns:
        tuple (global_operation_blocks, remaining_ir_blocks):
        - global_operation_blocks: list of IR blocks following a GlobalOperationsStart block if it
                                   exists, and an empty list otherwise
        - remaining_ir_blocks: list of IR blocks excluding GlobalOperationsStart and all global
                               operation blocks
    """
    global_operation_blocks = []
    remaining_ir_blocks = []
    in_global_operations_scope = False

    for block in ir_blocks_except_output_and_folds:
        if isinstance(block, (ConstructResult, Fold, Unfold)):
            raise AssertionError(u'Received unexpected block of type {}. No ConstructResult or '
                                 u'Fold/Unfold blocks should be present: {}'
                                 .format(type(block).__name__, ir_blocks_except_output_and_folds))
        elif isinstance(block, GlobalOperationsStart):
            in_global_operations_scope = True
        elif in_global_operations_scope:
            global_operation_blocks.append(block)
        else:
            remaining_ir_blocks.append(block)

    return global_operation_blocks, remaining_ir_blocks