#include "time.h"
#include "math.h"
#include "assert.h"

int num_tests = 5000000;

unsigned duck(unsigned x, unsigned y) {
    unsigned pow = 10;
    while(y >= pow)
        pow *= 10;
    return x * pow + y;        
}
int myPow(int x, int p)
{
     if (p == 0) return 1;
     if (p == 1) return x;

     int tmp = myPow(x, p/2);
     if (p%2 == 0) return tmp * tmp;
     else return x * tmp * tmp;
}
int david(int x, int y) {
    int power = log10(y);
    return x*myPow(10,power+1)+y;
}

int drummer(int x, int y) {
    int digits = log10(y)+1;
    int shifted = x * pow(10, digits);   // will be 1100 in your example
    return shifted + y;   // 1111
}

int shabeer(int x, int y) {
    int temp=0;
    int z=x;
    while(y>0)
    {
        // take reciprocal of y into temp
        temp=(temp*10)+(y%10);       
        y=y/10;
    }
    while(temp>0)
    {
        // take each number from last of temp and add to last of z
        z=(z*10)+(temp%10);      
        temp=temp/10;
    }
    return z;
}

int gokcehan(int x, int y) {
    int temp = y;
    while (y != 0) {
        x *= 10;
        y /= 10;
    }
    return x + temp;
}

void int_time(const char* name, unsigned(*func)(unsigned, unsigned)) {
    clock_t start = clock();
    unsigned r = 0;
    unsigned i = 0;
    for(; i<num_tests; ++i)
        r += func(i, i);
    printf("%s found %u in %d\n", name, r, clock()-start);
}

void uint_time(const char* name, int(*func)(int, int)) {
    clock_t start = clock();
    unsigned r = 0;
    unsigned i = 0;
    for(; i<num_tests; ++i)
        r += func(i, i);
    printf("%s found %u in %d\n", name, r, clock()-start);
}

void uint_accuracy(const char* name, unsigned(*func)(unsigned, unsigned)) {
    printf("testing %s accuracy: ", name);
    assert(func(0, 0) == 0);
    assert(func(0, 1) == 1);
    assert(func(0, 10) == 10);
    assert(func(1, 0) == 10);
    assert(func(1, 1) == 11);
    assert(func(1, 10) == 110);
    assert(func(10, 0) == 100);
    assert(func(10, 1) == 101);
    assert(func(10, 10) == 1010);
    assert(func(23, 456) == 23456);
    assert(func(234, 56) == 23456);
    printf("pass\n");
}

void int_accuracy(const char* name, int(*func)(int, int)) {
    printf("testing %s accuracy: ", name);
    assert(func(0, 0) == 0);
    assert(func(0, 1) == 1);
    assert(func(0, 10) == 10);
    assert(func(1, 0) == 10); //several fail this one
    assert(func(1, 1) == 11);
    assert(func(1, 10) == 110);
    assert(func(10, 0) == 100); //several fail this one
    assert(func(10, 1) == 101);
    assert(func(10, 10) == 1010);
    assert(func(23, 456) == 23456);
    assert(func(234, 56) == 23456);
    printf("pass\n");
}

int main() {
    uint_time("duck", duck);
    uint_time("duck", duck);
    int_time("david", david);
    int_time("david", david);
    int_time("drummer", drummer);
    int_time("drummer", drummer);
    int_time("shabeer", shabeer);
    int_time("shabeer", shabeer);
    int_time("gokcehan", gokcehan);
    int_time("gokcehan", gokcehan);
    uint_accuracy("duck", duck);
    //int_accuracy("gokcehan", gokcehan); //Assertion `func(1, 0) == 10' failed.
    //int_accuracy("drummer", drummer); //Assertion `func(1, 0) == 10' failed.
    //int_accuracy("david", david); //Assertion `func(1, 0) == 10' failed.
    //int_accuracy("shabeer", shabeer); //Assertion `func(0, 10) == 10' failed.
    return 0;
}