#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
int clock();
char *column_mul(char *, char *);
char *copy_argv(char *);
int /*<<< orphan*/ free(char *);
char *karatsuba(char **, char **);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  char *x, *y;
  char *result_karatsuba;
  char *result_column_mul;
  clock_t start, end;
  unsigned long long time_karatsuba, time_column_mul;
  start = clock();
  result_column_mul = column_mul(argv[1], argv[2]);
  end = clock();
  time_column_mul = (unsigned long long)((end - start) / CLOCKS_PER_SEC);
  x = copy_argv(argv[1]);
  y = copy_argv(argv[2]);
  start = clock();
  result_karatsuba = karatsuba(&x, &y);
  end = clock();
  time_karatsuba = (unsigned long long)((end - start) / CLOCKS_PER_SEC);
  if (!strcmp(result_column_mul, result_karatsuba)) {
    printf("\nProducts match: %s\n", result_column_mul);
  } else {
    printf("\nProducts don't match!\n");
    printf("Column product: %s\n", result_column_mul);
    printf("Karatsuba  product: %s\n", result_karatsuba);
  }
  printf("Column multiplication time: %llus\n", time_column_mul);
  printf("Karatsuba multiplication time: %llus\n", time_karatsuba);
  free(result_column_mul);
  free(result_karatsuba);
  free(x);
  free(y);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1080 <column_mul@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
sub    -0x34(%rbp),%eax
mov    0x2e28(%rip),%rcx
cltd
idivl  (%rcx)
cltq
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <copy_argv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <copy_argv@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x34(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <karatsuba@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <clock@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
sub    -0x34(%rbp),%eax
mov    0x2dcb(%rip),%rcx
cltd
idivl  (%rcx)
cltq
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    1253 <main+0xe3>
mov    -0x30(%rbp),%rsi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1285 <main+0x115>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rsi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x40(%rbp),%rsi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1090 <column_mul@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%ebp
mov    0x2e2c(%rip),%r14
mov    (%r14),%eax
mov    %eax,(%rsp)
mov    0x8(%rbx),%rdi
call   1060 <copy_argv@plt>
mov    %rax,0x10(%rsp)
mov    0x10(%rbx),%rdi
call   1060 <copy_argv@plt>
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%r12d
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <karatsuba@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1070 <clock@plt>
mov    %eax,%ebx
mov    (%r14),%r14d
mov    %r15,%rdi
mov    %r13,%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     123e <main+0xbe>
lea    0xe6e(%rip),%rdi
call   1050 <puts@plt>
lea    0xded(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdf0(%rip),%rdi
mov    %r13,%rsi
jmp    1248 <main+0xc8>
lea    0xdbb(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
sub    %r12d,%ebx
mov    %ebx,%eax
cltd
idiv   %r14d
movslq %eax,%rbx
sub    0x4(%rsp),%ebp
mov    %ebp,%eax
cltd
idivl  (%rsp)
movslq %eax,%rsi
lea    0xdd2(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xde7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r13,%rdi
call   1040 <free@plt>
mov    0x10(%rsp),%rdi
call   1040 <free@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global i32 0
@.str = [21 x i8] c"\0AProducts match: %s\0A\00"
@.str.1 = [24 x i8] c"\0AProducts don't match!\0A\00"
@.str.2 = [20 x i8] c"Column product: %s\0A\00"
@.str.3 = [24 x i8] c"Karatsuba product: %s\0A\00"
@.str.4 = [35 x i8] c"Column multiplication time: %llus\0A\00"
@.str.5 = [38 x i8] c"Karatsuba multiplication time: %llus\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (...) @clock()
store i32 %14, i32* %10
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i8* @column_mul(i8* %17, i8* %20)
store i8* %21, i8** %9
%22 = call i32 (...) @clock()
store i32 %22, i32* %11
%23 = load i32, i32* %11
%24 = load i32, i32* %10
%25 = sub nsw i32 %23, %24
%26 = load i32, i32* @CLOCKS_PER_SEC
%27 = sdiv i32 %25, %26
%28 = sext i32 %27 to i64
store i64 %28, i64* %13
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i8* @copy_argv(i8* %31)
store i8* %32, i8** %6
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i8* @copy_argv(i8* %35)
store i8* %36, i8** %7
%37 = call i32 (...) @clock()
store i32 %37, i32* %10
%38 = call i8* @karatsuba(i8** %6, i8** %7)
store i8* %38, i8** %8
%39 = call i32 (...) @clock()
store i32 %39, i32* %11
%40 = load i32, i32* %11
%41 = load i32, i32* %10
%42 = sub nsw i32 %40, %41
%43 = load i32, i32* @CLOCKS_PER_SEC
%44 = sdiv i32 %42, %43
%45 = sext i32 %44 to i64
store i64 %45, i64* %12
%46 = load i8*, i8** %9
%47 = load i8*, i8** %8
%48 = call i32 @strcmp(i8* %46, i8* %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %2
%51 = load i8*, i8** %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %51)
br label %59
53: ; preds = %2
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%55 = load i8*, i8** %9
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = load i8*, i8** %8
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %53, %50
%60 = load i64, i64* %13
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i64 %60)
%62 = load i64, i64* %12
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i64 %62)
%64 = load i8*, i8** %9
%65 = call i32 @free(i8* %64)
%66 = load i8*, i8** %8
%67 = call i32 @free(i8* %66)
%68 = load i8*, i8** %6
%69 = call i32 @free(i8* %68)
%70 = load i8*, i8** %7
%71 = call i32 @free(i8* %70)
ret i32 0
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global i32 0
@.str = [21 x i8] c"\0AProducts match: %s\0A\00"
@.str.2 = [20 x i8] c"Column product: %s\0A\00"
@.str.3 = [24 x i8] c"Karatsuba product: %s\0A\00"
@.str.4 = [35 x i8] c"Column multiplication time: %llus\0A\00"
@.str.5 = [38 x i8] c"Karatsuba multiplication time: %llus\0A\00"
@str = [23 x i8] c"\0AProducts don't match!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = tail call i32 (...) @clock()
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i8* @column_mul(i8* %9, i8* %11)
%13 = tail call i32 (...) @clock()
%14 = load i32, i32* @CLOCKS_PER_SEC
%15 = load i8*, i8** %8
%16 = tail call i8* @copy_argv(i8* %15)
store i8* %16, i8** %3
%17 = load i8*, i8** %10
%18 = tail call i8* @copy_argv(i8* %17)
store i8* %18, i8** %4
%19 = tail call i32 (...) @clock()
%20 = call i8* @karatsuba(i8** %3, i8** %4)
%21 = call i32 (...) @clock()
%22 = load i32, i32* @CLOCKS_PER_SEC
%23 = call i32 @strcmp(i8* dereferenceable(1) %12, i8* dereferenceable(1) %20)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %2
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %31
27: ; preds = %2
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %31
31: ; preds = %27, %25
%32 = sub nsw i32 %21, %19
%33 = sdiv i32 %32, %22
%34 = sext i32 %33 to i64
%35 = sub nsw i32 %13, %7
%36 = sdiv i32 %35, %14
%37 = sext i32 %36 to i64
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i64 %37)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i64 %34)
%40 = call i32 @free(i8* %12)
%41 = call i32 @free(i8* %20)
%42 = load i8*, i8** %3
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %4
%45 = call i32 @free(i8* %44)
ret i32 0
}