#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 */
scalar_t__ memcmp(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ scalarmult(unsigned char *, unsigned char const *,
                              unsigned char const *);
void test_scalarmult(unsigned char const *x, unsigned char const *a,
                     unsigned char const *b, char const *test) {
  unsigned char q[32];
  scalarmult(q, a, b);
  if (memcmp(q, x, 32)) {
    printf("FAILED X25519(%s)\n", test);
  } else {
    printf("passed X25519(%s)\n", test);
  }
}


x86 assembly (clang, -O0):
<test_scalarmult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <scalarmult@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x20,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     118a <test_scalarmult+0x5a>
mov    -0x20(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
jmp    119a <test_scalarmult+0x6a>
mov    -0x20(%rbp),%rsi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_scalarmult>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <scalarmult@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
lea    0xeaf(%rip),%rax
lea    0xe95(%rip),%rdi
cmove  %rax,%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"FAILED X25519(%s)\0A\00"
@.str.1 = [19 x i8] c"passed X25519(%s)\0A\00"
define void @test_scalarmult(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [32 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %6
%12 = load i8*, i8** %7
%13 = call i32 @scalarmult(i8* %10, i8* %11, i8* %12)
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = call i64 @memcmp(i8* %14, i8* %15, i32 32)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i8*, i8** %8
%20 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %24
21: ; preds = %4
%22 = load i8*, i8** %8
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %18
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"FAILED X25519(%s)\0A\00"
@.str.1 = [19 x i8] c"passed X25519(%s)\0A\00"
define void @test_scalarmult(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%7 = call i32 @scalarmult(i8* %6, i8* %1, i8* %2)
%8 = call i64 @memcmp(i8* %6, i8* %0, i32 32)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0)
%11 = call i32 @printf(i8* %10, i8* %3)
ret void
}