#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 */
struct goldilocks_public_key_t {
  int dummy;
};

/* Variables and functions */
int goldilocks_verify(unsigned char const *, unsigned char const *,
                      unsigned long long,
                      struct goldilocks_public_key_t const *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *,
                          unsigned long long);
int crypto_sign_open(unsigned char *m, unsigned long long *mlen,
                     const unsigned char *sm, unsigned long long smlen,
                     const unsigned char pk[(448 / 8)]) {
  int ret = goldilocks_verify(sm, sm + (2 * (448 / 8)), smlen - (2 * (448 / 8)),
                              (const struct goldilocks_public_key_t *)pk);
  if (!ret) {
    *mlen = smlen - (2 * (448 / 8));
    memcpy(m, sm + (2 * (448 / 8)), *mlen);
  }
  return ret ? -1 : 0;
}


x86 assembly (clang, -O0):
<crypto_sign_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x70,%rsi
mov    -0x20(%rbp),%rdx
sub    $0x70,%rdx
mov    -0x28(%rbp),%rcx
call   1040 <goldilocks_verify@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    118d <crypto_sign_open+0x6d>
mov    -0x20(%rbp),%rcx
sub    $0x70,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x70,%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
call   1030 <memcpy@plt>
mov    -0x2c(%rbp),%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_sign_open>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    %rsi,%r12
mov    %rdi,%r15
lea    0x70(%rdx),%r14
add    $0xffffffffffffff90,%rbx
mov    %rdx,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r8,%rcx
call   1040 <goldilocks_verify@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1162 <crypto_sign_open+0x42>
mov    %rbx,(%r12)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
neg    %ebp
sbb    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.goldilocks_public_key_t = type { i32 }
define i32 @crypto_sign_open(i8* %0, i64* %1, i8* %2, i64 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %6
store i64* %1, i64** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i8* %4, i8** %10
%12 = load i8*, i8** %8
%13 = load i8*, i8** %8
%14 = getelementptr inbounds i8, i8* %13, i64 112
%15 = load i64, i64* %9
%16 = sub i64 %15, 112
%17 = load i8*, i8** %10
%18 = bitcast i8* %17 to %struct.goldilocks_public_key_t*
%19 = call i32 @goldilocks_verify(i8* %12, i8* %14, i64 %16, %struct.goldilocks_public_key_t* %18)
store i32 %19, i32* %11
%20 = load i32, i32* %11
%21 = icmp ne i32 %20, 0
br i1 %21, label %32, label %22
22: ; preds = %5
%23 = load i64, i64* %9
%24 = sub i64 %23, 112
%25 = load i64*, i64** %7
store i64 %24, i64* %25
%26 = load i8*, i8** %6
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i64 112
%29 = load i64*, i64** %7
%30 = load i64, i64* %29
%31 = call i32 @memcpy(i8* %26, i8* %28, i64 %30)
br label %32
32: ; preds = %22, %5
%33 = load i32, i32* %11
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i32 -1, i32 0
ret i32 %36
}

LLVM IR (-O2):
%struct.goldilocks_public_key_t = type { i32 }
define i32 @crypto_sign_open(i8* %0, i64* nocapture writeonly %1, i8* %2, i64 %3, i8* %4) {
%6 = getelementptr inbounds i8, i8* %2, i64 112
%7 = add i64 %3, -112
%8 = bitcast i8* %4 to %struct.goldilocks_public_key_t*
%9 = tail call i32 @goldilocks_verify(i8* %2, i8* %6, i64 %7, %struct.goldilocks_public_key_t* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %5
store i64 %7, i64* %1
%12 = tail call i32 @memcpy(i8* %0, i8* %6, i64 %7)
br label %13
13: ; preds = %11, %5
%14 = xor i1 %10, true
%15 = sext i1 %14 to i32
ret i32 %15
}