#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 /*<<< orphan*/ onetimesk;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ cleanup_(unsigned char *, int);
int /*<<< orphan*/ crypto_hash_sha512_tinynacl(unsigned char *, unsigned char *,
                                               int);
int crypto_kem_sntrup761_tinynacl_enc(unsigned char *, unsigned char *,
                                      unsigned char const *);
int crypto_scalarmult_curve25519_tinynacl(unsigned char *, unsigned char *,
                                          unsigned char const *);
int crypto_scalarmult_curve25519_tinynacl_base(unsigned char *,
                                               unsigned char *);
int /*<<< orphan*/ randombytes(unsigned char *, int);
unsigned char returnmask(int);
int crypto_kem_sntrup761x25519_tinynacl_enc(unsigned char *c, unsigned char *k,
                                            const unsigned char *pk) {
  int r = 0;
  long long i;
  unsigned char onetimesk[32];
  unsigned char buf[32 + 32];
  unsigned char tmp[32 + 32];
  unsigned char b;
  r |= crypto_kem_sntrup761_tinynacl_enc(c, buf, pk);
  pk += 1158;
  c += 1039;
  randombytes(onetimesk, sizeof onetimesk);
  r |= crypto_scalarmult_curve25519_tinynacl_base(c, onetimesk);
  r |= crypto_scalarmult_curve25519_tinynacl(buf + 32, onetimesk, pk);
  randombytes(tmp, sizeof tmp);
  b = returnmask(r);
  for (i = 0; i < 32 + 32; ++i)
    tmp[i] = b & (tmp[i] ^ buf[i]);
  for (i = 0; i < 32 + 32; ++i)
    buf[i] ^= tmp[i];
  crypto_hash_sha512_tinynacl(k, buf, sizeof buf);
  cleanup_((buf), sizeof(buf));
  cleanup_((onetimesk), sizeof(onetimesk));
  return r;
}


x86 assembly (clang, -O0):
<crypto_kem_sntrup761x25519_tinynacl_enc>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <crypto_kem_sntrup761_tinynacl_enc@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x486,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40f,%rax
mov    %rax,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x20,%esi
call   1050 <randombytes@plt>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1090 <crypto_scalarmult_curve25519_tinynacl_base@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x90(%rbp),%rdi
add    $0x20,%rdi
lea    -0x50(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <crypto_scalarmult_curve25519_tinynacl@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0xd0(%rbp),%rdi
mov    $0x40,%esi
call   1050 <randombytes@plt>
mov    -0x1c(%rbp),%edi
call   1060 <returnmask@plt>
mov    %al,-0xd1(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x40,-0x28(%rbp)
jge    1276 <crypto_kem_sntrup761x25519_tinynacl_enc+0x106>
movzbl -0xd1(%rbp),%eax
mov    -0x28(%rbp),%rcx
movzbl -0xd0(%rbp,%rcx,1),%ecx
ff
mov    -0x28(%rbp),%rdx
movzbl -0x90(%rbp,%rdx,1),%edx
ff
xor    %edx,%ecx
and    %ecx,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,-0xd0(%rbp,%rax,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    122a <crypto_kem_sntrup761x25519_tinynacl_enc+0xba>
movq   $0x0,-0x28(%rbp)
cmpq   $0x40,-0x28(%rbp)
jge    12bb <crypto_kem_sntrup761x25519_tinynacl_enc+0x14b>
mov    -0x28(%rbp),%rax
movzbl -0xd0(%rbp,%rax,1),%edx
ff
mov    -0x28(%rbp),%rax
movzbl -0x90(%rbp,%rax,1),%ecx
ff
xor    %edx,%ecx
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    127e <crypto_kem_sntrup761x25519_tinynacl_enc+0x10e>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x40,%edx
call   1070 <crypto_hash_sha512_tinynacl@plt>
lea    -0x90(%rbp),%rdi
mov    $0x40,%esi
call   1080 <cleanup_@plt>
lea    -0x50(%rbp),%rdi
mov    $0x20,%esi
call   1080 <cleanup_@plt>
mov    -0x1c(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_kem_sntrup761x25519_tinynacl_enc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rsi
call   1030 <crypto_kem_sntrup761_tinynacl_enc@plt>
mov    %eax,%r13d
add    $0x486,%rbp
add    $0x40f,%rbx
lea    0x80(%rsp),%r12
mov    %r12,%rdi
mov    $0x20,%esi
call   1050 <randombytes@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <crypto_scalarmult_curve25519_tinynacl_base@plt>
mov    %eax,%ebx
or     %r13d,%ebx
lea    0x20(%rsp),%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1040 <crypto_scalarmult_curve25519_tinynacl@plt>
mov    %eax,%ebp
or     %ebx,%ebp
lea    0x40(%rsp),%rdi
mov    $0x40,%esi
call   1050 <randombytes@plt>
mov    %ebp,%edi
call   1060 <returnmask@plt>
movzbl %al,%eax
movd   %eax,%xmm0
punpcklbw %xmm0,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm2
movdqa (%rsp),%xmm3
movdqa 0x10(%rsp),%xmm4
movdqa 0x20(%rsp),%xmm1
movdqa 0x30(%rsp),%xmm8
movdqa 0x40(%rsp),%xmm5
pxor   %xmm3,%xmm5
pand   %xmm2,%xmm5
movdqa %xmm5,0x40(%rsp)
movdqa 0x50(%rsp),%xmm6
pxor   %xmm4,%xmm6
pand   %xmm2,%xmm6
movdqa %xmm6,0x50(%rsp)
movdqa 0x60(%rsp),%xmm7
pxor   %xmm1,%xmm7
pand   %xmm2,%xmm7
movdqa %xmm7,0x60(%rsp)
movdqa 0x70(%rsp),%xmm0
pxor   %xmm8,%xmm0
pand   %xmm2,%xmm0
movdqa %xmm0,0x70(%rsp)
pxor   %xmm3,%xmm5
movdqa %xmm5,(%rsp)
pxor   %xmm4,%xmm6
movdqa %xmm6,0x10(%rsp)
pxor   %xmm1,%xmm7
movdqa %xmm7,0x20(%rsp)
pxor   %xmm8,%xmm0
movdqa %xmm0,0x30(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x40,%edx
call   1070 <crypto_hash_sha512_tinynacl@plt>
mov    %r14,%rdi
mov    $0x40,%esi
call   1080 <cleanup_@plt>
mov    %r12,%rdi
mov    $0x20,%esi
call   1080 <cleanup_@plt>
mov    %ebp,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @crypto_kem_sntrup761x25519_tinynacl_enc(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca [32 x i8]
%10 = alloca [64 x i8]
%11 = alloca [64 x i8]
%12 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%13 = load i8*, i8** %4
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = call i32 @crypto_kem_sntrup761_tinynacl_enc(i8* %13, i8* %14, i8* %15)
%17 = load i32, i32* %7
%18 = or i32 %17, %16
store i32 %18, i32* %7
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 1158
store i8* %20, i8** %6
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1039
store i8* %22, i8** %4
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%24 = call i32 @randombytes(i8* %23, i32 32)
%25 = load i8*, i8** %4
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%27 = call i32 @crypto_scalarmult_curve25519_tinynacl_base(i8* %25, i8* %26)
%28 = load i32, i32* %7
%29 = or i32 %28, %27
store i32 %29, i32* %7
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%31 = getelementptr inbounds i8, i8* %30, i64 32
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%33 = load i8*, i8** %6
%34 = call i32 @crypto_scalarmult_curve25519_tinynacl(i8* %31, i8* %32, i8* %33)
%35 = load i32, i32* %7
%36 = or i32 %35, %34
store i32 %36, i32* %7
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%38 = call i32 @randombytes(i8* %37, i32 64)
%39 = load i32, i32* %7
%40 = call zeroext i8 @returnmask(i32 %39)
store i8 %40, i8* %12
store i64 0, i64* %8
br label %41
41: ; preds = %60, %3
%42 = load i64, i64* %8
%43 = icmp slt i64 %42, 64
br i1 %43, label %44, label %63
44: ; preds = %41
%45 = load i8, i8* %12
%46 = zext i8 %45 to i32
%47 = load i64, i64* %8
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = load i64, i64* %8
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = xor i32 %50, %54
%56 = and i32 %46, %55
%57 = trunc i32 %56 to i8
%58 = load i64, i64* %8
%59 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 %58
store i8 %57, i8* %59
br label %60
60: ; preds = %44
%61 = load i64, i64* %8
%62 = add nsw i64 %61, 1
store i64 %62, i64* %8
br label %41
63: ; preds = %41
store i64 0, i64* %8
br label %64
64: ; preds = %78, %63
%65 = load i64, i64* %8
%66 = icmp slt i64 %65, 64
br i1 %66, label %67, label %81
67: ; preds = %64
%68 = load i64, i64* %8
%69 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = load i64, i64* %8
%73 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 %72
%74 = load i8, i8* %73
%75 = zext i8 %74 to i32
%76 = xor i32 %75, %71
%77 = trunc i32 %76 to i8
store i8 %77, i8* %73
br label %78
78: ; preds = %67
%79 = load i64, i64* %8
%80 = add nsw i64 %79, 1
store i64 %80, i64* %8
br label %64
81: ; preds = %64
%82 = load i8*, i8** %5
%83 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%84 = call i32 @crypto_hash_sha512_tinynacl(i8* %82, i8* %83, i32 64)
%85 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%86 = call i32 @cleanup_(i8* %85, i32 64)
%87 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%88 = call i32 @cleanup_(i8* %87, i32 32)
%89 = load i32, i32* %7
ret i32 %89
}

LLVM IR (-O2):
define i32 @crypto_kem_sntrup761x25519_tinynacl_enc(i8* %0, i8* %1, i8* %2) {
%4 = alloca [32 x i8]
%5 = alloca [64 x i8]
%6 = alloca [64 x i8]
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%10 = call i32 @crypto_kem_sntrup761_tinynacl_enc(i8* %0, i8* %8, i8* %2)
%11 = getelementptr inbounds i8, i8* %2, i64 1158
%12 = getelementptr inbounds i8, i8* %0, i64 1039
%13 = call i32 @randombytes(i8* %7, i32 32)
%14 = call i32 @crypto_scalarmult_curve25519_tinynacl_base(i8* %12, i8* %7)
%15 = or i32 %14, %10
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 32
%17 = call i32 @crypto_scalarmult_curve25519_tinynacl(i8* %16, i8* %7, i8* %11)
%18 = or i32 %15, %17
%19 = call i32 @randombytes(i8* %9, i32 64)
%20 = call zeroext i8 @returnmask(i32 %18)
%21 = insertelement <16 x i8> poison, i8 %20, i64 0
%22 = shufflevector <16 x i8> %21, <16 x i8> poison, <16 x i32> zeroinitializer
%23 = bitcast [64 x i8]* %6 to <16 x i8>*
%24 = load <16 x i8>, <16 x i8>* %23
%25 = bitcast [64 x i8]* %5 to <16 x i8>*
%26 = load <16 x i8>, <16 x i8>* %25
%27 = xor <16 x i8> %26, %24
%28 = and <16 x i8> %27, %22
%29 = bitcast [64 x i8]* %6 to <16 x i8>*
store <16 x i8> %28, <16 x i8>* %29
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 16
%31 = bitcast i8* %30 to <16 x i8>*
%32 = load <16 x i8>, <16 x i8>* %31
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 16
%34 = bitcast i8* %33 to <16 x i8>*
%35 = load <16 x i8>, <16 x i8>* %34
%36 = xor <16 x i8> %35, %32
%37 = and <16 x i8> %36, %22
%38 = bitcast i8* %30 to <16 x i8>*
store <16 x i8> %37, <16 x i8>* %38
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 32
%40 = bitcast i8* %39 to <16 x i8>*
%41 = load <16 x i8>, <16 x i8>* %40
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 32
%43 = bitcast i8* %42 to <16 x i8>*
%44 = load <16 x i8>, <16 x i8>* %43
%45 = xor <16 x i8> %44, %41
%46 = and <16 x i8> %45, %22
%47 = bitcast i8* %39 to <16 x i8>*
store <16 x i8> %46, <16 x i8>* %47
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 48
%49 = bitcast i8* %48 to <16 x i8>*
%50 = load <16 x i8>, <16 x i8>* %49
%51 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 48
%52 = bitcast i8* %51 to <16 x i8>*
%53 = load <16 x i8>, <16 x i8>* %52
%54 = xor <16 x i8> %53, %50
%55 = and <16 x i8> %54, %22
%56 = bitcast i8* %48 to <16 x i8>*
store <16 x i8> %55, <16 x i8>* %56
%57 = bitcast [64 x i8]* %6 to <16 x i8>*
%58 = load <16 x i8>, <16 x i8>* %57
%59 = bitcast [64 x i8]* %5 to <16 x i8>*
%60 = load <16 x i8>, <16 x i8>* %59
%61 = xor <16 x i8> %60, %58
%62 = bitcast [64 x i8]* %5 to <16 x i8>*
store <16 x i8> %61, <16 x i8>* %62
%63 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 16
%64 = bitcast i8* %63 to <16 x i8>*
%65 = load <16 x i8>, <16 x i8>* %64
%66 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 16
%67 = bitcast i8* %66 to <16 x i8>*
%68 = load <16 x i8>, <16 x i8>* %67
%69 = xor <16 x i8> %68, %65
%70 = bitcast i8* %66 to <16 x i8>*
store <16 x i8> %69, <16 x i8>* %70
%71 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 32
%72 = bitcast i8* %71 to <16 x i8>*
%73 = load <16 x i8>, <16 x i8>* %72
%74 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 32
%75 = bitcast i8* %74 to <16 x i8>*
%76 = load <16 x i8>, <16 x i8>* %75
%77 = xor <16 x i8> %76, %73
%78 = bitcast i8* %74 to <16 x i8>*
store <16 x i8> %77, <16 x i8>* %78
%79 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 48
%80 = bitcast i8* %79 to <16 x i8>*
%81 = load <16 x i8>, <16 x i8>* %80
%82 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 48
%83 = bitcast i8* %82 to <16 x i8>*
%84 = load <16 x i8>, <16 x i8>* %83
%85 = xor <16 x i8> %84, %81
%86 = bitcast i8* %82 to <16 x i8>*
store <16 x i8> %85, <16 x i8>* %86
%87 = call i32 @crypto_hash_sha512_tinynacl(i8* %1, i8* %8, i32 64)
%88 = call i32 @cleanup_(i8* %8, i32 64)
%89 = call i32 @cleanup_(i8* %7, i32 32)
ret i32 %18
}