#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 long cpucycles();
int /*<<< orphan*/ crypto_scalarmult_base_curve25519(unsigned char *,
                                                     unsigned char *);
int /*<<< orphan*/
crypto_scalarmult_curve25519(unsigned char *, unsigned char *, unsigned char *);
int /*<<< orphan*/ print_bench(char *, unsigned long long *, int);
void speed_curve25519() {
  unsigned long long t[20];
  int i;
  unsigned char s1[32];
  unsigned char p1[64];
  for (i = 0; i < 20; i++) {
    t[i] = cpucycles();
    crypto_scalarmult_base_curve25519(p1, s1);
  }
  print_bench("scalarmult_base", t, 20);
  for (i = 0; i < 20; i++) {
    t[i] = cpucycles();
    crypto_scalarmult_curve25519(p1, p1, s1);
  }
  print_bench("scalarmult", t, 20);
}


x86 assembly (clang, -O0):
<speed_curve25519>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0xa4(%rbp)
cmpl   $0x14,-0xa4(%rbp)
jge    11a2 <speed_curve25519+0x62>
mov    $0x0,%al
call   1060 <cpucycles@plt>
mov    %rax,%rcx
movslq -0xa4(%rbp),%rax
mov    %rcx,-0xa0(%rbp,%rax,8)
ff
lea    -0x110(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    1155 <speed_curve25519+0x15>
lea    -0xa0(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x14,%edx
call   1040 <print_bench@plt>
movl   $0x0,-0xa4(%rbp)
cmpl   $0x14,-0xa4(%rbp)
jge    1218 <speed_curve25519+0xd8>
mov    $0x0,%al
call   1060 <cpucycles@plt>
mov    %rax,%rcx
movslq -0xa4(%rbp),%rax
mov    %rcx,-0xa0(%rbp,%rax,8)
ff
lea    -0x110(%rbp),%rdi
lea    -0x110(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
call   1030 <crypto_scalarmult_curve25519@plt>
mov    -0xa4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa4(%rbp)
jmp    11c4 <speed_curve25519+0x84>
lea    -0xa0(%rbp),%rsi
lea    0xdea(%rip),%rdi
mov    $0x14,%edx
call   1040 <print_bench@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<speed_curve25519>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,(%rsp)
lea    0xc0(%rsp),%r15
lea    0xa0(%rsp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x10(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x18(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x20(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x28(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x30(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x38(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x40(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x48(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x50(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x58(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x60(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x68(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x70(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x78(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x80(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x88(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x90(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,0x98(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <crypto_scalarmult_base_curve25519@plt>
lea    0xcc6(%rip),%rdi
mov    %rsp,%rsi
mov    $0x14,%edx
call   1040 <print_bench@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <cpucycles@plt>
mov    %rax,(%rsp,%rbx,8)
mov    %r15,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <crypto_scalarmult_curve25519@plt>
add    $0x1,%rbx
cmp    $0x14,%rbx
jne    1350 <speed_curve25519+0x210>
lea    0xc96(%rip),%rdi
mov    %rsp,%rsi
mov    $0x14,%edx
call   1040 <print_bench@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"scalarmult_base\00"
@.str.1 = [11 x i8] c"scalarmult\00"
define void @speed_curve25519() {
%1 = alloca [20 x i64]
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca [64 x i8]
store i32 0, i32* %2
br label %5
5: ; preds = %16, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 20
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = call i64 (...) @cpucycles()
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 %11
store i64 %9, i64* %12
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%15 = call i32 @crypto_scalarmult_base_curve25519(i8* %13, i8* %14)
br label %16
16: ; preds = %8
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %5
19: ; preds = %5
%20 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 0
%21 = call i32 @print_bench(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64* %20, i32 20)
store i32 0, i32* %2
br label %22
22: ; preds = %34, %19
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 20
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = call i64 (...) @cpucycles()
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 %28
store i64 %26, i64* %29
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%33 = call i32 @crypto_scalarmult_curve25519(i8* %30, i8* %31, i8* %32)
br label %34
34: ; preds = %25
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %22
37: ; preds = %22
%38 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 0
%39 = call i32 @print_bench(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64* %38, i32 20)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"scalarmult_base\00"
@.str.1 = [11 x i8] c"scalarmult\00"
define void @speed_curve25519() {
%1 = alloca [20 x i64]
%2 = alloca [32 x i8]
%3 = alloca [64 x i8]
%4 = bitcast [20 x i64]* %1 to i8*
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%7 = call i64 (...) @cpucycles()
%8 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 0
store i64 %7, i64* %8
%9 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%10 = call i64 (...) @cpucycles()
%11 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 1
store i64 %10, i64* %11
%12 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%13 = call i64 (...) @cpucycles()
%14 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 2
store i64 %13, i64* %14
%15 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%16 = call i64 (...) @cpucycles()
%17 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 3
store i64 %16, i64* %17
%18 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%19 = call i64 (...) @cpucycles()
%20 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 4
store i64 %19, i64* %20
%21 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%22 = call i64 (...) @cpucycles()
%23 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 5
store i64 %22, i64* %23
%24 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%25 = call i64 (...) @cpucycles()
%26 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 6
store i64 %25, i64* %26
%27 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%28 = call i64 (...) @cpucycles()
%29 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 7
store i64 %28, i64* %29
%30 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%31 = call i64 (...) @cpucycles()
%32 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 8
store i64 %31, i64* %32
%33 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%34 = call i64 (...) @cpucycles()
%35 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 9
store i64 %34, i64* %35
%36 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%37 = call i64 (...) @cpucycles()
%38 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 10
store i64 %37, i64* %38
%39 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%40 = call i64 (...) @cpucycles()
%41 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 11
store i64 %40, i64* %41
%42 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%43 = call i64 (...) @cpucycles()
%44 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 12
store i64 %43, i64* %44
%45 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%46 = call i64 (...) @cpucycles()
%47 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 13
store i64 %46, i64* %47
%48 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%49 = call i64 (...) @cpucycles()
%50 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 14
store i64 %49, i64* %50
%51 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%52 = call i64 (...) @cpucycles()
%53 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 15
store i64 %52, i64* %53
%54 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%55 = call i64 (...) @cpucycles()
%56 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 16
store i64 %55, i64* %56
%57 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%58 = call i64 (...) @cpucycles()
%59 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 17
store i64 %58, i64* %59
%60 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%61 = call i64 (...) @cpucycles()
%62 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 18
store i64 %61, i64* %62
%63 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%64 = call i64 (...) @cpucycles()
%65 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 19
store i64 %64, i64* %65
%66 = call i32 @crypto_scalarmult_base_curve25519(i8* %6, i8* %5)
%67 = call i32 @print_bench(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i64* %8, i32 20)
br label %68
68: ; preds = %0, %68
%69 = phi i64 [ 0, %0 ], [ %73, %68 ]
%70 = call i64 (...) @cpucycles()
%71 = getelementptr inbounds [20 x i64], [20 x i64]* %1, i64 0, i64 %69
store i64 %70, i64* %71
%72 = call i32 @crypto_scalarmult_curve25519(i8* %6, i8* %6, i8* %5)
%73 = add nuw nsw i64 %69, 1
%74 = icmp eq i64 %73, 20
br i1 %74, label %75, label %68
75: ; preds = %68
%76 = call i32 @print_bench(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64* %8, i32 20)
ret void
}