Implement atoi function You already know that the atoi function of stdlib.h converts a string to an integer.

atoi

(copied from here)

 int atoi (const char * str);



  Convert string to integer
  
  Parses the C-string str interpreting its content as an integral number, which is returned as a value of type int.


Example

#include &lt;stdio.h&gt;      /* printf, fgets */
#include &lt;stdlib.h&gt;     /* atoi */

int main ()
{
  int i;
  char buffer[256];
  printf ("Enter a number: ");
  fgets (buffer, 256, stdin);
  i = atoi (buffer);
  printf ("The value entered is %d. Its double is %d.\n",i,i*2);
  return 0;
}


Your task is to implement it, making sure it works for all negative integers in the range, and try to make the code as small as you can.
Python 3 - multicore or go home

# The venerable C atoi function hails from a more innocent time. These days,
# we have multicore processors and programs must adapt or be left behind.
import re
import multiprocessing as mp

def atoi(a):
    m = re.match(r"^\s*(-?)(\d+).*$", a)
    if m is None:
        raise ValueError(a)
    sign = -(m.group(1) == "-") * 2 + 1
    places = enumerate(reversed(bytes(m.group(2), "ascii")))
    with mp.Pool(processes=mp.cpu_count()) as pool:
        return sign * sum(pool.map(_digit, places))

def _digit(t):
    i, b = t
    return 10 ** i * (b - 48)

if __name__ == '__main__':
    import unittest
    error_case = unittest.TestCase().assertRaises(ValueError)
    assert atoi(" -4555553") == -4555553
    assert atoi("1") == 1
    assert atoi("    0") == 0
    assert atoi("100asdf") == 100
    assert atoi("-5") == -5
    assert atoi("1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz") == 1
    assert atoi("1.2") == 1
    with error_case:
        atoi("foobar")
    with error_case:
        atoi("a1234")


Now I have 2 + cpu_count() problems.