input: Write a python function to optimize the indentation and remove redundant white spaces in a given code string.
  assert optimize_code('def example():\n  print("Hello")\n  if True:\n     print("World")\n') == 'def example():\n    print("Hello")\n    if True:\n        print("World")\n'
  assert optimize_code('def foo():\n  a = 1\n  if a:\n   print(a)\n') == 'def foo():\n    a = 1\n    if a:\n        print(a)\n'
  assert optimize_code('if True:\n  x = 1\n  if x:\n   print(x)\n') == 'if True:\n    x = 1\n    if x:\n        print(x)\n'
output: def optimize_code(code):
      lines = code.split('\n')
      optimized_lines = []
      indent_level = 0
      for line in lines:
          stripped_line = line.lstrip()
          if stripped_line:
              indent_level = (len(line) - len(stripped_line)) // 2
              optimized_lines.append('    ' * indent_level + stripped_line)
          else:
              optimized_lines.append('')
      return '\n'.join(optimized_lines)