Đáp án:
Xét \( \int_0^{\frac{\pi}{4}} f(\tan x) \, dx \).
Đặt \( t = \tan x \implies dt = (1 + \tan^2 x) dx = (1 + t^2) dx \),
\( \Rightarrow dx = \frac{1}{1 + t^2} \, dt. \)
\( \begin{cases} x = 0 \Rightarrow t = 0 \\ x = \frac{\pi}{4} \Rightarrow t = 1 \end{cases}\).
\( 4 = \int_0^{\frac{\pi}{4}} f(\tan x) \, dx = \int_0^1 \frac{f(t)}{1 + t^2} \, dt. \)
\( 2 = \int_0^1 \frac{x^2 f(x)}{x^2 + 1} \, dx = \int_0^1 \frac{(x^2 + 1 - 1) f(x)}{x^2 + 1} \, dx. \)
\( = \int_0^1 f(x) \, dx - \int_0^1 \frac{f(x)}{x^2 + 1} \, dx. \)
\( \Rightarrow \int_0^1 f(x) \, dx = 2 + \int_0^1 \frac{f(x)}{x^2 + 1} \, dx = 2 + 4 = 6 \Rightarrow \boxed{B} \)