Fix recursion issues including stack overflows and incorrect results
Help me debug issues with my recursive function.
**Programming Language:** {{LANGUAGE}}
**Recursive function:**
```{{LANGUAGE}}
{{CODE}}
```
**Problem:** {{PROBLEM}}
**Input that causes the issue:** {{INPUT}}
**Expected output:** {{EXPECTED}}
**Actual output/error:** {{ACTUAL}}
Please provide:
1. **Base Case Analysis**: Verify base case correctness
2. **Recursive Case Check**: Ensure progress toward base case
3. **Stack Trace**: Show recursive call stack for problematic input
4. **Termination Proof**: Verify the recursion will terminate
5. **Fixed Function**: Provide corrected recursive code
6. **Tail Recursion**: Convert to tail recursion if possible
7. **Iterative Alternative**: Provide iterative solution if appropriate
8. **Stack Optimization**: Techniques to prevent stack overflowOr press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[{LANGUAGE][{CODE][{PROBLEM][{INPUT][{EXPECTED][{ACTUAL]