#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 uint64_t;

/* Variables and functions */
int /*<<< orphan*/ curve25519_donna(unsigned char *, unsigned char *,
                                    unsigned char const *);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ printf(char *, int);
int time_now();
int main() {
  static const unsigned char basepoint[32] = {9};
  unsigned char mysecret[32], mypublic[32];
  unsigned i;
  memset(mysecret, 42, 32);
  mysecret[0] &= 248;
  mysecret[31] &= 127;
  mysecret[31] |= 64;
  for (i = 0; i < 1000; ++i) {
    curve25519_donna(mypublic, mysecret, basepoint);
  }
  uint64_t start = time_now();
  for (i = 0; i < 30000; ++i) {
    curve25519_donna(mypublic, mysecret, basepoint);
  }
  uint64_t end = time_now();
  printf("%luus\n", (end - start) / 30000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x2a,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
movzbl -0x30(%rbp),%eax
and    $0xf8,%eax
mov    %al,-0x30(%rbp)
movzbl -0x11(%rbp),%eax
and    $0x7f,%eax
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
or     $0x40,%eax
mov    %al,-0x11(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x3e8,-0x54(%rbp)
jae    11b8 <main+0x78>
lea    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    0xe5b(%rip),%rdx
call   1030 <curve25519_donna@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1189 <main+0x49>
mov    $0x0,%al
call   1060 <time_now@plt>
mov    %eax,-0x58(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x7530,-0x54(%rbp)
jae    11f8 <main+0xb8>
lea    -0x50(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    0xe1b(%rip),%rdx
call   1030 <curve25519_donna@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11c9 <main+0x89>
mov    $0x0,%al
call   1060 <time_now@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
sub    -0x58(%rbp),%eax
mov    $0x7530,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x2a,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
andb   $0xf8,(%rsp)
mov    0x1f(%rsp),%al
and    $0x3f,%al
or     $0x40,%al
mov    %al,0x1f(%rsp)
mov    $0x3e8,%ebp
lea    0xe83(%rip),%r15
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <curve25519_donna@plt>
add    $0xffffffff,%ebp
jne    1190 <main+0x50>
xor    %eax,%eax
call   1060 <time_now@plt>
mov    %eax,%r14d
mov    $0x7530,%ebp
lea    0xe47(%rip),%r15
lea    0x20(%rsp),%r12
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <curve25519_donna@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0x90>
xor    %eax,%eax
call   1060 <time_now@plt>
sub    %r14d,%eax
cltq
imul   $0x45e7b273,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x2d,%rsi
add    %eax,%esi
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.basepoint = internal constant <{ i8, [31 x i8] }> <{ i8 9, [31 x i8] zeroinitializer }>
@.str = [7 x i8] c"%luus\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 42, i32 32)
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = and i32 %11, 248
%13 = trunc i32 %12 to i8
store i8 %13, i8* %9
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 31
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = and i32 %16, 127
%18 = trunc i32 %17 to i8
store i8 %18, i8* %14
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 31
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = or i32 %21, 64
%23 = trunc i32 %22 to i8
store i8 %23, i8* %19
store i32 0, i32* %4
br label %24
24: ; preds = %31, %0
%25 = load i32, i32* %4
%26 = icmp ult i32 %25, 1000
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%30 = call i32 @curve25519_donna(i8* %28, i8* %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* bitcast (<{ i8, [31 x i8] }>* @main.basepoint to [32 x i8]*), i64 0, i64 0))
br label %31
31: ; preds = %27
%32 = load i32, i32* %4
%33 = add i32 %32, 1
store i32 %33, i32* %4
br label %24
34: ; preds = %24
%35 = call i32 (...) @time_now()
store i32 %35, i32* %5
store i32 0, i32* %4
br label %36
36: ; preds = %43, %34
%37 = load i32, i32* %4
%38 = icmp ult i32 %37, 30000
br i1 %38, label %39, label %46
39: ; preds = %36
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%42 = call i32 @curve25519_donna(i8* %40, i8* %41, i8* getelementptr inbounds ([32 x i8], [32 x i8]* bitcast (<{ i8, [31 x i8] }>* @main.basepoint to [32 x i8]*), i64 0, i64 0))
br label %43
43: ; preds = %39
%44 = load i32, i32* %4
%45 = add i32 %44, 1
store i32 %45, i32* %4
br label %36
46: ; preds = %36
%47 = call i32 (...) @time_now()
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = load i32, i32* %5
%50 = sub nsw i32 %48, %49
%51 = sdiv i32 %50, 30000
%52 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %51)
ret i32 0
}

LLVM IR (-O2):
@main.basepoint = internal constant <{ i8, [31 x i8] }> <{ i8 9, [31 x i8] zeroinitializer }>
@.str = [7 x i8] c"%luus\0A\00"
define i32 @main() {
%1 = alloca [32 x i8]
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = call i32 @memset(i8* %3, i32 42, i32 32)
%6 = load i8, i8* %3
%7 = and i8 %6, -8
store i8 %7, i8* %3
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 31
%9 = load i8, i8* %8
%10 = and i8 %9, 63
%11 = or i8 %10, 64
store i8 %11, i8* %8
br label %12
12: ; preds = %0, %12
%13 = phi i32 [ 0, %0 ], [ %15, %12 ]
%14 = call i32 @curve25519_donna(i8* %4, i8* %3, i8* getelementptr inbounds (<{ i8, [31 x i8] }>, <{ i8, [31 x i8] }>* @main.basepoint, i64 0, i32 0))
%15 = add nuw nsw i32 %13, 1
%16 = icmp eq i32 %15, 1000
br i1 %16, label %17, label %12
17: ; preds = %12
%18 = call i32 (...) @time_now()
br label %19
19: ; preds = %17, %19
%20 = phi i32 [ 0, %17 ], [ %22, %19 ]
%21 = call i32 @curve25519_donna(i8* %4, i8* %3, i8* getelementptr inbounds (<{ i8, [31 x i8] }>, <{ i8, [31 x i8] }>* @main.basepoint, i64 0, i32 0))
%22 = add nuw nsw i32 %20, 1
%23 = icmp eq i32 %22, 30000
br i1 %23, label %24, label %19
24: ; preds = %19
%25 = call i32 (...) @time_now()
%26 = sub nsw i32 %25, %18
%27 = sdiv i32 %26, 30000
%28 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %27)
ret i32 0
}