from __future__ import annotations

import gc
import inspect
import os
import time
from pathlib import Path

import dill as pickle
import pytest
from inference.core.workflows.execution_engine.constants import \
    NODE_COMPILATION_OUTPUT_PROPERTY
from inference.core.workflows.execution_engine.v1.compiler.entities import \
    NodeCategory
from inference.core.workflows.execution_engine.v1.compiler.utils import \
    is_control_flow_step
from networkx import DiGraph


def codeflash_wrap(codeflash_wrapped, codeflash_test_module_name, codeflash_test_class_name, codeflash_test_name, codeflash_function_name, codeflash_line_id, codeflash_loop_index, *args, **kwargs):
    test_id = f'{codeflash_test_module_name}:{codeflash_test_class_name}:{codeflash_test_name}:{codeflash_line_id}:{codeflash_loop_index}'
    if not hasattr(codeflash_wrap, 'index'):
        codeflash_wrap.index = {}
    if test_id in codeflash_wrap.index:
        codeflash_wrap.index[test_id] += 1
    else:
        codeflash_wrap.index[test_id] = 0
    codeflash_test_index = codeflash_wrap.index[test_id]
    invocation_id = f'{codeflash_line_id}_{codeflash_test_index}'
    test_stdout_tag = f"{codeflash_test_module_name}:{(codeflash_test_class_name + '.' if codeflash_test_class_name else '')}{codeflash_test_name}:{codeflash_function_name}:{codeflash_loop_index}:{invocation_id}"
    print(f'!$######{test_stdout_tag}######$!')
    exception = None
    gc.disable()
    try:
        counter = time.perf_counter_ns()
        return_value = codeflash_wrapped(*args, **kwargs)
        codeflash_duration = time.perf_counter_ns() - counter
    except Exception as e:
        codeflash_duration = time.perf_counter_ns() - counter
        exception = e
    gc.enable()
    print(f'!######{test_stdout_tag}######!')
    iteration = os.environ['CODEFLASH_TEST_ITERATION']
    with Path('{codeflash_run_tmp_dir_client_side}', f'test_return_values_{iteration}.bin').open('ab') as f:
        pickled_values = pickle.dumps((args, kwargs, exception)) if exception else pickle.dumps((args, kwargs, return_value))
        _test_name = f"{codeflash_test_module_name}:{(codeflash_test_class_name + '.' if codeflash_test_class_name else '')}{codeflash_test_name}:{codeflash_function_name}:{codeflash_line_id}".encode('ascii')
        f.write(len(_test_name).to_bytes(4, byteorder='big'))
        f.write(_test_name)
        f.write(codeflash_duration.to_bytes(8, byteorder='big'))
        f.write(len(pickled_values).to_bytes(4, byteorder='big'))
        f.write(pickled_values)
        f.write(codeflash_loop_index.to_bytes(8, byteorder='big'))
        f.write(len(invocation_id).to_bytes(4, byteorder='big'))
        f.write(invocation_id.encode('ascii'))
    if exception:
        raise exception
    return return_value

class MockNodeOutput:
    """Real object representing a node's compilation output with node category and flow control."""

    def __init__(self, node_category, controls_flow_value):
        self.node_category = node_category
        self._controls_flow_value = controls_flow_value

    def controls_flow(self):
        """Return whether this node controls flow."""
        return self._controls_flow_value

def test_control_flow_step_true():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that a STEP_NODE with controls_flow=True returns True.'
    graph = DiGraph()
    node_name = 'step_node_1'
    node_output = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=True)
    graph.add_node(node_name)
    graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_control_flow_step_true', 'is_control_flow_step', '6', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_control_flow_step_false_step_node_no_flow():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that a STEP_NODE with controls_flow=False returns False.'
    graph = DiGraph()
    node_name = 'step_node_2'
    node_output = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=False)
    graph.add_node(node_name)
    graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_control_flow_step_false_step_node_no_flow', 'is_control_flow_step', '6', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_input_node_with_controls_flow_true():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that an INPUT_NODE returns False even if controls_flow=True (not a step node).'
    graph = DiGraph()
    node_name = 'input_node_1'
    node_output = MockNodeOutput(node_category=NodeCategory.INPUT_NODE, controls_flow_value=True)
    graph.add_node(node_name)
    graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_input_node_with_controls_flow_true', 'is_control_flow_step', '6', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_output_node_with_controls_flow_true():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that an OUTPUT_NODE returns False even if controls_flow=True (not a step node).'
    graph = DiGraph()
    node_name = 'output_node_1'
    node_output = MockNodeOutput(node_category=NodeCategory.OUTPUT_NODE, controls_flow_value=True)
    graph.add_node(node_name)
    graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_output_node_with_controls_flow_true', 'is_control_flow_step', '6', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_multiple_step_nodes_mixed():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test graph with multiple step nodes with mixed control flow values.'
    graph = DiGraph()
    node1 = 'control_step_1'
    output1 = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=True)
    graph.add_node(node1)
    graph.nodes[node1][NODE_COMPILATION_OUTPUT_PROPERTY] = output1
    node2 = 'non_control_step_1'
    output2 = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=False)
    graph.add_node(node2)
    graph.nodes[node2][NODE_COMPILATION_OUTPUT_PROPERTY] = output2
    node3 = 'control_step_2'
    output3 = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=True)
    graph.add_node(node3)
    graph.nodes[node3][NODE_COMPILATION_OUTPUT_PROPERTY] = output3
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node1)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_multiple_step_nodes_mixed', 'is_control_flow_step', '14', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node2)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_multiple_step_nodes_mixed', 'is_control_flow_step', '15', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node3)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_multiple_step_nodes_mixed', 'is_control_flow_step', '16', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_empty_graph_raises_error():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that querying a non-existent node raises KeyError.'
    graph = DiGraph()
    with pytest.raises(KeyError):
        _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, 'non_existent_node')
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_empty_graph_raises_error', 'is_control_flow_step', '2_0', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)

def test_node_without_output_property_raises_error():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that a node without the output property raises KeyError.'
    graph = DiGraph()
    node_name = 'node_without_property'
    graph.add_node(node_name)
    with pytest.raises(KeyError):
        _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_node_without_output_property_raises_error', 'is_control_flow_step', '4_0', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)

def test_single_character_node_name():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with minimal node name (single character).'
    graph = DiGraph()
    node_name = 'a'
    node_output = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=True)
    graph.add_node(node_name)
    graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_single_character_node_name', 'is_control_flow_step', '6', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_long_node_name():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with very long node name.'
    graph = DiGraph()
    node_name = 'very_long_node_name_' * 50
    node_output = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=True)
    graph.add_node(node_name)
    graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_long_node_name', 'is_control_flow_step', '6', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_numeric_node_name():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with numeric node name.'
    graph = DiGraph()
    node_name = 42
    node_output = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=True)
    graph.add_node(node_name)
    graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_numeric_node_name', 'is_control_flow_step', '6', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_tuple_node_name():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test with tuple as node name.'
    graph = DiGraph()
    node_name = ('step', 1, 'node')
    node_output = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=False)
    graph.add_node(node_name)
    graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_tuple_node_name', 'is_control_flow_step', '6', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_large_graph_with_many_step_nodes():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test function performance on large graph with many step nodes.'
    graph = DiGraph()
    num_nodes = 500
    for i in range(num_nodes):
        node_name = f'step_node_{i}'
        controls_flow_value = i % 2 == 0
        node_output = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=controls_flow_value)
        graph.add_node(node_name)
        graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, 'step_node_0')
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_large_graph_with_many_step_nodes', 'is_control_flow_step', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, f'step_node_{num_nodes // 2}')
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_large_graph_with_many_step_nodes', 'is_control_flow_step', '5', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, f'step_node_{num_nodes - 1}')
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_large_graph_with_many_step_nodes', 'is_control_flow_step', '6', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_large_graph_mixed_node_types():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test function on large graph with mixed node types.'
    graph = DiGraph()
    num_total_nodes = 1000
    num_step_nodes = 400
    num_input_nodes = 300
    num_output_nodes = 300
    for i in range(num_step_nodes):
        node_name = f'step_{i}'
        controls_flow_value = i < num_step_nodes // 2
        node_output = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=controls_flow_value)
        graph.add_node(node_name)
        graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    for i in range(num_input_nodes):
        node_name = f'input_{i}'
        node_output = MockNodeOutput(node_category=NodeCategory.INPUT_NODE, controls_flow_value=True)
        graph.add_node(node_name)
        graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    for i in range(num_output_nodes):
        node_name = f'output_{i}'
        node_output = MockNodeOutput(node_category=NodeCategory.OUTPUT_NODE, controls_flow_value=True)
        graph.add_node(node_name)
        graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, 'step_0')
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_large_graph_mixed_node_types', 'is_control_flow_step', '9', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, f'step_{num_step_nodes // 2}')
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_large_graph_mixed_node_types', 'is_control_flow_step', '10', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, f'input_{num_input_nodes // 2}')
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_large_graph_mixed_node_types', 'is_control_flow_step', '11', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, f'output_{num_output_nodes - 1}')
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_large_graph_mixed_node_types', 'is_control_flow_step', '12', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value

def test_large_graph_consistency():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test that results are consistent across multiple queries on same large graph.'
    graph = DiGraph()
    num_nodes = 200
    node_indices = []
    for i in range(num_nodes):
        node_name = f'step_node_{i}'
        controls_flow_value = i % 3 == 0
        node_output = MockNodeOutput(node_category=NodeCategory.STEP_NODE, controls_flow_value=controls_flow_value)
        graph.add_node(node_name)
        graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
        node_indices.append(i)
    for i in node_indices:
        node_name = f'step_node_{i}'
        expected_result = i % 3 == 0
        _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_large_graph_consistency', 'is_control_flow_step', '5_2', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
        codeflash_output = codeflash_return_value
        result1 = codeflash_output
        _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_large_graph_consistency', 'is_control_flow_step', '5_7', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
        codeflash_output = codeflash_return_value
        result2 = codeflash_output
        _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, node_name)
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_large_graph_consistency', 'is_control_flow_step', '5_12', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
        codeflash_output = codeflash_return_value
        result3 = codeflash_output

def test_all_node_categories_large_scale():
    codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
    'Test all node categories at scale.'
    graph = DiGraph()
    categories = [(NodeCategory.STEP_NODE, 'step', True), (NodeCategory.INPUT_NODE, 'input', False), (NodeCategory.OUTPUT_NODE, 'output', False)]
    for category, prefix, expected_all_false in categories:
        for i in range(100):
            node_name = f'{prefix}_{i}'
            controls_flow_value = not expected_all_false and i % 2 == 0
            node_output = MockNodeOutput(node_category=category, controls_flow_value=controls_flow_value)
            graph.add_node(node_name)
            graph.nodes[node_name][NODE_COMPILATION_OUTPUT_PROPERTY] = node_output
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, 'step_0')
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_all_node_categories_large_scale', 'is_control_flow_step', '4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, 'step_1')
    _call__bound__arguments.apply_defaults()
    codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_all_node_categories_large_scale', 'is_control_flow_step', '5', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
    codeflash_output = codeflash_return_value
    for i in range(100):
        _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, f'input_{i}')
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_all_node_categories_large_scale', 'is_control_flow_step', '6_0', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
        codeflash_output = codeflash_return_value
        _call__bound__arguments = inspect.signature(is_control_flow_step).bind(graph, f'output_{i}')
        _call__bound__arguments.apply_defaults()
        codeflash_return_value = codeflash_wrap(is_control_flow_step, 'tests.inference.unit_tests.test_is_control_flow_step__unit_test_1', None, 'test_all_node_categories_large_scale', 'is_control_flow_step', '6_4', codeflash_loop_index, *_call__bound__arguments.args, **_call__bound__arguments.kwargs)
        codeflash_output = codeflash_return_value