#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 */

/* Variables and functions */
unsigned long atoi(char *);
int /*<<< orphan*/ free(unsigned long *);
int /*<<< orphan*/ gf2x_mul(unsigned long *, unsigned long *, unsigned long,
                            unsigned long *, unsigned long);
unsigned long *malloc(int);
int /*<<< orphan*/ printf(char *, unsigned long, double, unsigned long, double);
unsigned long rand();
double runtime();
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  unsigned long i;
  unsigned long n0 = 1;
  unsigned long n = 200;
  if (argc > 1) {
    n = atoi(argv[1]);
  }
  if (argc > 2) {
    n0 = n;
    n = atoi(argv[2]);
  }
  setbuf(stdout, NULL);
  unsigned long *a, *b, *c;
  a = malloc(n * sizeof(unsigned long));
  b = malloc(n * sizeof(unsigned long));
  c = malloc(2 * n * sizeof(unsigned long));
  for (i = 0; i < n; i++) {
    a[i] = rand();
    b[i] = rand();
  }
  unsigned long jmax = 100000;
  for (i = n0; i < n; i <<= 1) {
    gf2x_mul(c, a, i, b, i);
    gf2x_mul(c, a, i, b, i);
    gf2x_mul(c, a, i, b, i);
    double t = runtime();
    unsigned long j;
    double d;
    for (j = 0; (d = runtime() - t) < 1 && (j < 2000 || d < 0.2); j++) {
      gf2x_mul(c, a, i, b, i);
    }
    printf("%u %e\t%u %.2f\n", i, d / j, j, d);
  }
  free(a);
  free(b);
  free(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x20(%rbp)
movq   $0xc8,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11e4 <main+0x64>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %rax,-0x28(%rbp)
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <setbuf@plt>
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1286 <main+0x106>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    123b <main+0xbb>
movq   $0x186a0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    13ee <main+0x26e>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1040 <gf2x_mul@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1040 <gf2x_mul@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1040 <gf2x_mul@plt>
mov    $0x0,%al
call   1050 <runtime@plt>
movsd  %xmm0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    $0x0,%al
call   1050 <runtime@plt>
movaps %xmm0,%xmm1
subsd  -0x50(%rbp),%xmm1
movsd  %xmm1,-0x60(%rbp)
xor    %eax,%eax
movsd  0xcdf(%rip),%xmm0
ucomisd %xmm1,%xmm0
mov    %al,-0x61(%rbp)
jbe    135a <main+0x1da>
mov    $0x1,%al
cmpq   $0x7d0,-0x58(%rbp)
mov    %al,-0x62(%rbp)
jb     1354 <main+0x1d4>
movsd  0xcbf(%rip),%xmm0
ucomisd -0x60(%rbp),%xmm0
seta   %al
mov    %al,-0x62(%rbp)
mov    -0x62(%rbp),%al
mov    %al,-0x61(%rbp)
mov    -0x61(%rbp),%al
test   $0x1,%al
jne    136a <main+0x1ea>
jmp    1394 <main+0x214>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%r8
call   1040 <gf2x_mul@plt>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1303 <main+0x183>
mov    -0x18(%rbp),%rsi
movsd  -0x60(%rbp),%xmm0
movaps 0xc6c(%rip),%xmm2
movq   -0x58(%rbp),%xmm1
punpckldq %xmm2,%xmm1
movapd 0xc6b(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mov    -0x58(%rbp),%rdx
movsd  -0x60(%rbp),%xmm1
lea    0xc58(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1296 <main+0x116>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
mov    $0xc8,%r14d
cmp    $0x2,%edi
jl     11c7 <main+0x47>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %rax,%rbx
cmp    $0x2,%ebp
jne    11bb <main+0x3b>
mov    %rbx,%r14
mov    $0x1,%ebx
jmp    11c7 <main+0x47>
mov    0x10(%r15),%rdi
call   1090 <atoi@plt>
mov    %rax,%r14
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <setbuf@plt>
lea    0x0(,%r14,8),%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %r14d,%edi
shl    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
test   %r14,%r14
je     127e <main+0xfe>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rax,(%r15,%rbp,8)
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %rax,(%r12,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1210 <main+0x90>
jmp    127e <main+0xfe>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movq   %rbp,%xmm0
punpckldq 0xdc3(%rip),%xmm0
subpd  0xdcb(%rip),%xmm0
movapd %xmm0,%xmm2
unpckhpd %xmm0,%xmm2
addsd  %xmm0,%xmm2
movapd %xmm1,%xmm0
divsd  %xmm2,%xmm0
lea    0xdc0(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1070 <printf@plt>
add    %rbx,%rbx
cmp    %r14,%rbx
jae    134a <main+0x1ca>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
call   1040 <gf2x_mul@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
call   1040 <gf2x_mul@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
call   1040 <gf2x_mul@plt>
xor    %eax,%eax
call   1050 <runtime@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <runtime@plt>
movsd  (%rsp),%xmm2
movapd %xmm0,%xmm1
subsd  %xmm2,%xmm1
movsd  0xd15(%rip),%xmm0
xor    %ebp,%ebp
jmp    1324 <main+0x1a4>
nop
mov    %r13,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %rbx,%r8
call   1040 <gf2x_mul@plt>
add    $0x1,%rbp
xor    %eax,%eax
call   1050 <runtime@plt>
movsd  (%rsp),%xmm2
movapd %xmm0,%xmm1
subsd  %xmm2,%xmm1
movsd  0xcdc(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1240 <main+0xc0>
cmp    $0x7d0,%rbp
jb     12f0 <main+0x170>
movsd  0xcc9(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     12f0 <main+0x170>
jmp    1240 <main+0xc0>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [15 x i8] c"%u %e\09%u %.2f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i64*
%12 = alloca i64
%13 = alloca double
%14 = alloca i64
%15 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1, i64* %7
store i64 200, i64* %8
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @atoi(i8* %21)
store i64 %22, i64* %8
br label %23
23: ; preds = %18, %2
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 2
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i64, i64* %8
store i64 %27, i64* %7
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i64 @atoi(i8* %30)
store i64 %31, i64* %8
br label %32
32: ; preds = %26, %23
%33 = load i32, i32* @stdout
%34 = call i32 @setbuf(i32 %33, i32* null)
%35 = load i64, i64* %8
%36 = mul i64 %35, 8
%37 = trunc i64 %36 to i32
%38 = call i64* @malloc(i32 %37)
store i64* %38, i64** %9
%39 = load i64, i64* %8
%40 = mul i64 %39, 8
%41 = trunc i64 %40 to i32
%42 = call i64* @malloc(i32 %41)
store i64* %42, i64** %10
%43 = load i64, i64* %8
%44 = mul i64 2, %43
%45 = mul i64 %44, 8
%46 = trunc i64 %45 to i32
%47 = call i64* @malloc(i32 %46)
store i64* %47, i64** %11
store i64 0, i64* %6
br label %48
48: ; preds = %61, %32
%49 = load i64, i64* %6
%50 = load i64, i64* %8
%51 = icmp ult i64 %49, %50
br i1 %51, label %52, label %64
52: ; preds = %48
%53 = call i64 (...) @rand()
%54 = load i64*, i64** %9
%55 = load i64, i64* %6
%56 = getelementptr inbounds i64, i64* %54, i64 %55
store i64 %53, i64* %56
%57 = call i64 (...) @rand()
%58 = load i64*, i64** %10
%59 = load i64, i64* %6
%60 = getelementptr inbounds i64, i64* %58, i64 %59
store i64 %57, i64* %60
br label %61
61: ; preds = %52
%62 = load i64, i64* %6
%63 = add i64 %62, 1
store i64 %63, i64* %6
br label %48
64: ; preds = %48
store i64 100000, i64* %12
%65 = load i64, i64* %7
store i64 %65, i64* %6
br label %66
66: ; preds = %124, %64
%67 = load i64, i64* %6
%68 = load i64, i64* %8
%69 = icmp ult i64 %67, %68
br i1 %69, label %70, label %127
70: ; preds = %66
%71 = load i64*, i64** %11
%72 = load i64*, i64** %9
%73 = load i64, i64* %6
%74 = load i64*, i64** %10
%75 = load i64, i64* %6
%76 = call i32 @gf2x_mul(i64* %71, i64* %72, i64 %73, i64* %74, i64 %75)
%77 = load i64*, i64** %11
%78 = load i64*, i64** %9
%79 = load i64, i64* %6
%80 = load i64*, i64** %10
%81 = load i64, i64* %6
%82 = call i32 @gf2x_mul(i64* %77, i64* %78, i64 %79, i64* %80, i64 %81)
%83 = load i64*, i64** %11
%84 = load i64*, i64** %9
%85 = load i64, i64* %6
%86 = load i64*, i64** %10
%87 = load i64, i64* %6
%88 = call i32 @gf2x_mul(i64* %83, i64* %84, i64 %85, i64* %86, i64 %87)
%89 = call double (...) @runtime()
store double %89, double* %13
store i64 0, i64* %14
br label %90
90: ; preds = %112, %70
%91 = call double (...) @runtime()
%92 = load double, double* %13
%93 = fsub double %91, %92
store double %93, double* %15
%94 = fcmp olt double %93, 1.000000e+00
br i1 %94, label %95, label %103
95: ; preds = %90
%96 = load i64, i64* %14
%97 = icmp ult i64 %96, 2000
br i1 %97, label %101, label %98
98: ; preds = %95
%99 = load double, double* %15
%100 = fcmp olt double %99, 2.000000e-01
br label %101
101: ; preds = %98, %95
%102 = phi i1 [ true, %95 ], [ %100, %98 ]
br label %103
103: ; preds = %101, %90
%104 = phi i1 [ false, %90 ], [ %102, %101 ]
br i1 %104, label %105, label %115
105: ; preds = %103
%106 = load i64*, i64** %11
%107 = load i64*, i64** %9
%108 = load i64, i64* %6
%109 = load i64*, i64** %10
%110 = load i64, i64* %6
%111 = call i32 @gf2x_mul(i64* %106, i64* %107, i64 %108, i64* %109, i64 %110)
br label %112
112: ; preds = %105
%113 = load i64, i64* %14
%114 = add i64 %113, 1
store i64 %114, i64* %14
br label %90
115: ; preds = %103
%116 = load i64, i64* %6
%117 = load double, double* %15
%118 = load i64, i64* %14
%119 = uitofp i64 %118 to double
%120 = fdiv double %117, %119
%121 = load i64, i64* %14
%122 = load double, double* %15
%123 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %116, double %120, i64 %121, double %122)
br label %124
124: ; preds = %115
%125 = load i64, i64* %6
%126 = shl i64 %125, 1
store i64 %126, i64* %6
br label %66
127: ; preds = %66
%128 = load i64*, i64** %9
%129 = call i32 @free(i64* %128)
%130 = load i64*, i64** %10
%131 = call i32 @free(i64* %130)
%132 = load i64*, i64** %11
%133 = call i32 @free(i64* %132)
%134 = load i32, i32* %3
ret i32 %134
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [15 x i8] c"%u %e\09%u %.2f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @atoi(i8* %6)
%8 = icmp eq i32 %0, 2
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i64 @atoi(i8* %11)
br label %13
13: ; preds = %2, %9, %4
%14 = phi i64 [ %12, %9 ], [ %7, %4 ], [ 200, %2 ]
%15 = phi i64 [ %7, %9 ], [ 1, %4 ], [ 1, %2 ]
%16 = load i32, i32* @stdout
%17 = tail call i32 @setbuf(i32 %16, i32* null)
%18 = trunc i64 %14 to i32
%19 = shl i32 %18, 3
%20 = tail call i64* @malloc(i32 %19)
%21 = tail call i64* @malloc(i32 %19)
%22 = shl i32 %18, 4
%23 = tail call i64* @malloc(i32 %22)
%24 = icmp eq i64 %14, 0
br i1 %24, label %25, label %27
25: ; preds = %27, %13
%26 = icmp ult i64 %15, %14
br i1 %26, label %35, label %64
27: ; preds = %13, %27
%28 = phi i64 [ %33, %27 ], [ 0, %13 ]
%29 = tail call i64 (...) @rand()
%30 = getelementptr inbounds i64, i64* %20, i64 %28
store i64 %29, i64* %30
%31 = tail call i64 (...) @rand()
%32 = getelementptr inbounds i64, i64* %21, i64 %28
store i64 %31, i64* %32
%33 = add nuw i64 %28, 1
%34 = icmp eq i64 %33, %14
br i1 %34, label %25, label %27
35: ; preds = %25, %56
%36 = phi i64 [ %62, %56 ], [ %15, %25 ]
%37 = tail call i32 @gf2x_mul(i64* %23, i64* %20, i64 %36, i64* %21, i64 %36)
%38 = tail call i32 @gf2x_mul(i64* %23, i64* %20, i64 %36, i64* %21, i64 %36)
%39 = tail call i32 @gf2x_mul(i64* %23, i64* %20, i64 %36, i64* %21, i64 %36)
%40 = tail call double (...) @runtime()
%41 = tail call double (...) @runtime()
%42 = fsub double %41, %40
%43 = fcmp olt double %42, 1.000000e+00
br i1 %43, label %44, label %56
44: ; preds = %35, %50
%45 = phi double [ %54, %50 ], [ %42, %35 ]
%46 = phi i64 [ %52, %50 ], [ 0, %35 ]
%47 = icmp ult i64 %46, 2000
%48 = fcmp olt double %45, 2.000000e-01
%49 = select i1 %47, i1 true, i1 %48
br i1 %49, label %50, label %56
50: ; preds = %44
%51 = tail call i32 @gf2x_mul(i64* %23, i64* %20, i64 %36, i64* %21, i64 %36)
%52 = add i64 %46, 1
%53 = tail call double (...) @runtime()
%54 = fsub double %53, %40
%55 = fcmp olt double %54, 1.000000e+00
br i1 %55, label %44, label %56
56: ; preds = %44, %50, %35
%57 = phi i64 [ 0, %35 ], [ %52, %50 ], [ %46, %44 ]
%58 = phi double [ %42, %35 ], [ %54, %50 ], [ %45, %44 ]
%59 = uitofp i64 %57 to double
%60 = fdiv double %58, %59
%61 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %36, double %60, i64 %57, double %58)
%62 = shl i64 %36, 1
%63 = icmp ult i64 %62, %14
br i1 %63, label %35, label %64
64: ; preds = %56, %25
%65 = tail call i32 @free(i64* %20)
%66 = tail call i32 @free(i64* %21)
%67 = tail call i32 @free(i64* %23)
ret i32 0
}