#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*/ EVP_MD;
typedef int /*<<< orphan*/ EVP_CIPHER_CTX;
typedef int /*<<< orphan*/ EVP_CIPHER;
typedef int /*<<< orphan*/ EC_KEY;
typedef int /*<<< orphan*/ BIGNUM;

/* Variables and functions */
int /*<<< orphan*/ BN_bn2bin(int /*<<< orphan*/ *, unsigned char *);
int /*<<< orphan*/ *BN_new();
size_t BN_num_bytes(int /*<<< orphan*/ *);
int /*<<< orphan*/ BN_print_fp(int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ EC_KEY_public_derive_S(int /*<<< orphan*/ const *,
                                  int /*<<< orphan*/, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_CIPHER_CTX_new();
size_t EVP_CIPHER_iv_length(int /*<<< orphan*/ const *);
size_t EVP_CIPHER_key_length(int /*<<< orphan*/ const *);
int /*<<< orphan*/ EVP_EncryptFinal_ex(int /*<<< orphan*/ *, unsigned char *,
                                       int *);
int /*<<< orphan*/ EVP_EncryptInit_ex(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ const *,
                                      int /*<<< orphan*/ *, unsigned char *,
                                      unsigned char *);
int /*<<< orphan*/ EVP_EncryptUpdate(int /*<<< orphan*/ *, unsigned char *,
                                     int *, unsigned char const *, int);
size_t EVP_MD_block_size(int /*<<< orphan*/ const *);
int /*<<< orphan*/ *EVP_aes_256_cbc();
int /*<<< orphan*/ *EVP_sha1();
int /*<<< orphan*/ HMAC(int /*<<< orphan*/ const *, unsigned char *, size_t,
                        unsigned char *, size_t, unsigned char *,
                        unsigned int *);
int /*<<< orphan*/ PKCS5_PBKDF2_HMAC(char const *, size_t,
                                     unsigned char const *, size_t, int,
                                     int /*<<< orphan*/ const *, size_t,
                                     unsigned char *);
int /*<<< orphan*/ POINT_CONVERSION_COMPRESSED;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int encipher(const EC_KEY *key, unsigned char *R_out, size_t *R_len,
             unsigned char *c_out, size_t *c_len, unsigned char *d_out,
             size_t *d_len, const unsigned char *salt, size_t salt_len) {
  BIGNUM *R = BN_new();
  BIGNUM *S = BN_new();
  while (EC_KEY_public_derive_S(key, POINT_CONVERSION_COMPRESSED, S, R) != 0)
    ;
  printf("R = ");
  BN_print_fp(stdout, R);
  printf("\n");
  printf("S_encipher = ");
  BN_print_fp(stdout, S);
  printf("\n");
  size_t S_len = BN_num_bytes(S);
  unsigned char password[S_len];
  BN_bn2bin(S, password);
  const EVP_MD *md = EVP_sha1();
  const EVP_CIPHER *cipher = EVP_aes_256_cbc();
  size_t ke_len = EVP_CIPHER_key_length(cipher) + EVP_CIPHER_iv_length(cipher);
  size_t km_len = EVP_MD_block_size(md);
  unsigned char ke_km[ke_len + km_len];
  *c_len = 0;
  int outl = 0;
  PKCS5_PBKDF2_HMAC((const char *)password, S_len, salt, salt_len, 2000, md,
                    ke_len + km_len, ke_km);
  EVP_CIPHER_CTX *ectx = EVP_CIPHER_CTX_new();
  EVP_EncryptInit_ex(ectx, cipher, NULL, ke_km,
                     ke_km + EVP_CIPHER_key_length(cipher));
  EVP_EncryptUpdate(ectx, c_out + *c_len, &outl,
                    (const unsigned char *)"super secret message", 20);
  *c_len += outl;
  EVP_EncryptFinal_ex(ectx, c_out + *c_len, &outl);
  *c_len += outl;
  unsigned int len;
  HMAC(md, ke_km + ke_len, km_len, c_out, *c_len, d_out, &len);
  *d_len = len;
  *R_len = BN_num_bytes(R);
  BN_bn2bin(R, R_out);
  return 0;
}


x86 assembly (clang, -O0):
<encipher>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <BN_new@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
call   1030 <EC_KEY_public_derive_S@plt>
cmp    $0x0,%rax
je     127e <encipher+0x6e>
jmp    1255 <encipher+0x45>
lea    0xd7b(%rip),%rdi
call   1080 <printf@plt>
mov    0x2d47(%rip),%rax
mov    %rax,-0xd8(%rbp)
mov    (%rax),%edi
mov    -0x38(%rbp),%rsi
call   10a0 <BN_print_fp@plt>
lea    0xd5b(%rip),%rdi
mov    %rdi,-0xd0(%rbp)
call   1080 <printf@plt>
lea    0xd4a(%rip),%rdi
call   1080 <printf@plt>
mov    -0xd8(%rbp),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rsi
call   10a0 <BN_print_fp@plt>
mov    -0xd0(%rbp),%rdi
call   1080 <printf@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <BN_num_bytes@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0xb8(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rdi
call   10f0 <BN_bn2bin@plt>
xor    %eax,%eax
mov    %al,-0xc1(%rbp)
call   1070 <EVP_sha1@plt>
mov    %rax,%rcx
mov    -0xc1(%rbp),%al
mov    %rcx,-0x60(%rbp)
call   1050 <EVP_aes_256_cbc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
call   1120 <EVP_CIPHER_key_length@plt>
mov    %rax,-0xc0(%rbp)
mov    -0x68(%rbp),%rdi
call   1090 <EVP_CIPHER_iv_length@plt>
mov    %rax,%rcx
mov    -0xc0(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x70(%rbp)
mov    -0x60(%rbp),%rdi
call   1130 <EVP_MD_block_size@plt>
mov    -0xb8(%rbp),%rdi
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rax
mov    -0x78(%rbp),%rdx
mov    %rax,%rcx
add    %rdx,%rcx
lea    0xf(%rax,%rdx,1),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0xa0(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x80(%rbp)
mov    -0x28(%rbp),%rcx
movq   $0x0,(%rcx)
movl   $0x0,-0x84(%rbp)
mov    -0x48(%rbp),%rsi
mov    0x18(%rbp),%rdx
mov    0x20(%rbp),%rcx
mov    -0x60(%rbp),%r9
mov    -0x70(%rbp),%r10
add    -0x78(%rbp),%r10
mov    $0x7d0,%r8d
sub    $0x10,%rsp
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <PKCS5_PBKDF2_HMAC@plt>
add    $0x10,%rsp
mov    $0x0,%al
call   1110 <EVP_CIPHER_CTX_new@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x68(%rbp),%rdi
call   1120 <EVP_CIPHER_key_length@plt>
mov    -0xb0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
mov    -0xa0(%rbp),%rcx
mov    %rcx,%r8
add    %rax,%r8
xor    %eax,%eax
mov    %eax,%edx
call   1100 <EVP_EncryptInit_ex@plt>
mov    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
add    (%rax),%rsi
lea    -0x84(%rbp),%rdx
lea    0xbac(%rip),%rcx
mov    $0x14,%r8d
call   10b0 <EVP_EncryptUpdate@plt>
movslq -0x84(%rbp),%rcx
mov    -0x28(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
add    (%rax),%rsi
lea    -0x84(%rbp),%rdx
call   10d0 <EVP_EncryptFinal_ex@plt>
mov    -0xa0(%rbp),%rsi
movslq -0x84(%rbp),%rcx
mov    -0x28(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x60(%rbp),%rdi
add    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    (%rax),%r8
mov    -0x30(%rbp),%r9
lea    -0x94(%rbp),%rax
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   10c0 <HMAC@plt>
add    $0x10,%rsp
mov    -0x94(%rbp),%eax
mov    %eax,%ecx
mov    0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
call   10e0 <BN_num_bytes@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10f0 <BN_bn2bin@plt>
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encipher>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r9,-0x70(%rbp)
mov    %r8,-0x60(%rbp)
mov    %rcx,-0x68(%rbp)
mov    %rdx,-0x78(%rbp)
mov    %rsi,-0x80(%rbp)
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <BN_new@plt>
mov    %rax,%r15
mov    0x2d85(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <EC_KEY_public_derive_S@plt>
test   %rax,%rax
jne    1270 <encipher+0x50>
lea    0xd72(%rip),%rdi
call   1090 <printf@plt>
mov    0x2d3e(%rip),%rbx
mov    (%rbx),%edi
mov    %r14,%rsi
call   10b0 <BN_print_fp@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xd50(%rip),%rdi
call   1090 <printf@plt>
mov    (%rbx),%edi
mov    %r15,%rsi
call   10b0 <BN_print_fp@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
call   10f0 <BN_num_bytes@plt>
mov    %rax,-0x48(%rbp)
mov    %rsp,%r13
lea    0xf(%rax),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
mov    %r15,%rdi
mov    %r13,%rsi
call   1100 <BN_bn2bin@plt>
xor    %eax,%eax
call   1080 <EVP_sha1@plt>
mov    %rax,%r15
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
call   1060 <EVP_aes_256_cbc@plt>
mov    %rax,%rbx
mov    %rax,-0x40(%rbp)
mov    %rax,%rdi
call   1130 <EVP_CIPHER_key_length@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   10a0 <EVP_CIPHER_iv_length@plt>
add    %rax,%r12
mov    %r15,%rdi
call   1140 <EVP_MD_block_size@plt>
mov    %rax,-0x58(%rbp)
mov    %r12,-0x50(%rbp)
lea    (%r12,%rax,1),%r10
lea    (%rax,%r12,1),%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%r15
sub    %rcx,%r15
mov    %r15,%rsp
mov    -0x60(%rbp),%r12
movq   $0x0,(%r12)
movl   $0x0,-0x2c(%rbp)
mov    %r13,%rdi
mov    -0x48(%rbp),%rsi
mov    0x18(%rbp),%rdx
mov    0x20(%rbp),%rcx
mov    $0x7d0,%r8d
mov    -0x38(%rbp),%r9
push   %r15
push   %r10
call   1070 <PKCS5_PBKDF2_HMAC@plt>
add    $0x10,%rsp
xor    %eax,%eax
call   1120 <EVP_CIPHER_CTX_new@plt>
mov    %rax,%r13
mov    -0x40(%rbp),%rbx
mov    %rbx,%rdi
call   1130 <EVP_CIPHER_key_length@plt>
lea    (%rax,%r15,1),%r8
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %r15,%rcx
call   1110 <EVP_EncryptInit_ex@plt>
mov    (%r12),%rsi
mov    -0x68(%rbp),%rbx
add    %rbx,%rsi
lea    0xc4d(%rip),%rcx
lea    -0x2c(%rbp),%rdx
mov    %r13,%rdi
mov    $0x14,%r8d
call   10c0 <EVP_EncryptUpdate@plt>
movslq -0x2c(%rbp),%rsi
add    (%r12),%rsi
mov    %rsi,(%r12)
add    %rbx,%rsi
mov    %r13,%rdi
lea    -0x2c(%rbp),%rdx
call   10e0 <EVP_EncryptFinal_ex@plt>
movslq -0x2c(%rbp),%r8
add    (%r12),%r8
mov    %r8,(%r12)
add    -0x50(%rbp),%r15
sub    $0x8,%rsp
lea    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rdi
mov    %r15,%rsi
mov    -0x58(%rbp),%rdx
mov    %rbx,%rcx
mov    -0x70(%rbp),%r9
push   %rax
call   10d0 <HMAC@plt>
add    $0x10,%rsp
mov    -0x30(%rbp),%eax
mov    0x10(%rbp),%rcx
mov    %rax,(%rcx)
mov    %r14,%rdi
call   10f0 <BN_num_bytes@plt>
mov    -0x78(%rbp),%rcx
mov    %rax,(%rcx)
mov    %r14,%rdi
mov    -0x80(%rbp),%rsi
call   1100 <BN_bn2bin@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@POINT_CONVERSION_COMPRESSED = global i32 0
@.str = [5 x i8] c"R = \00"
@stdout = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [14 x i8] c"S_encipher = \00"
@.str.3 = [21 x i8] c"super secret message\00"
define i32 @encipher(i32* %0, i8* %1, i64* %2, i8* %3, i64* %4, i8* %5, i64* %6, i8* %7, i64 %8) {
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i64*
%13 = alloca i8*
%14 = alloca i64*
%15 = alloca i8*
%16 = alloca i64*
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i32*
%20 = alloca i32*
%21 = alloca i64
%22 = alloca i8*
%23 = alloca i64
%24 = alloca i32*
%25 = alloca i32*
%26 = alloca i64
%27 = alloca i64
%28 = alloca i64
%29 = alloca i32
%30 = alloca i32*
%31 = alloca i32
store i32* %0, i32** %10
store i8* %1, i8** %11
store i64* %2, i64** %12
store i8* %3, i8** %13
store i64* %4, i64** %14
store i8* %5, i8** %15
store i64* %6, i64** %16
store i8* %7, i8** %17
store i64 %8, i64* %18
%32 = call i32* (...) @BN_new()
store i32* %32, i32** %19
%33 = call i32* (...) @BN_new()
store i32* %33, i32** %20
br label %34
34: ; preds = %41, %9
%35 = load i32*, i32** %10
%36 = load i32, i32* @POINT_CONVERSION_COMPRESSED
%37 = load i32*, i32** %20
%38 = load i32*, i32** %19
%39 = call i64 @EC_KEY_public_derive_S(i32* %35, i32 %36, i32* %37, i32* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %34
br label %34
42: ; preds = %34
%43 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%44 = load i32, i32* @stdout
%45 = load i32*, i32** %19
%46 = call i32 @BN_print_fp(i32 %44, i32* %45)
%47 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%48 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* @stdout
%50 = load i32*, i32** %20
%51 = call i32 @BN_print_fp(i32 %49, i32* %50)
%52 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%53 = load i32*, i32** %20
%54 = call i64 @BN_num_bytes(i32* %53)
store i64 %54, i64* %21
%55 = load i64, i64* %21
%56 = call i8* @llvm.stacksave()
store i8* %56, i8** %22
%57 = alloca i8, i64 %55
store i64 %55, i64* %23
%58 = load i32*, i32** %20
%59 = call i32 @BN_bn2bin(i32* %58, i8* %57)
%60 = call i32* (...) @EVP_sha1()
store i32* %60, i32** %24
%61 = call i32* (...) @EVP_aes_256_cbc()
store i32* %61, i32** %25
%62 = load i32*, i32** %25
%63 = call i64 @EVP_CIPHER_key_length(i32* %62)
%64 = load i32*, i32** %25
%65 = call i64 @EVP_CIPHER_iv_length(i32* %64)
%66 = add i64 %63, %65
store i64 %66, i64* %26
%67 = load i32*, i32** %24
%68 = call i64 @EVP_MD_block_size(i32* %67)
store i64 %68, i64* %27
%69 = load i64, i64* %26
%70 = load i64, i64* %27
%71 = add i64 %69, %70
%72 = alloca i8, i64 %71
store i64 %71, i64* %28
%73 = load i64*, i64** %14
store i64 0, i64* %73
store i32 0, i32* %29
%74 = load i64, i64* %21
%75 = load i8*, i8** %17
%76 = load i64, i64* %18
%77 = load i32*, i32** %24
%78 = load i64, i64* %26
%79 = load i64, i64* %27
%80 = add i64 %78, %79
%81 = call i32 @PKCS5_PBKDF2_HMAC(i8* %57, i64 %74, i8* %75, i64 %76, i32 2000, i32* %77, i64 %80, i8* %72)
%82 = call i32* (...) @EVP_CIPHER_CTX_new()
store i32* %82, i32** %30
%83 = load i32*, i32** %30
%84 = load i32*, i32** %25
%85 = load i32*, i32** %25
%86 = call i64 @EVP_CIPHER_key_length(i32* %85)
%87 = getelementptr inbounds i8, i8* %72, i64 %86
%88 = call i32 @EVP_EncryptInit_ex(i32* %83, i32* %84, i32* null, i8* %72, i8* %87)
%89 = load i32*, i32** %30
%90 = load i8*, i8** %13
%91 = load i64*, i64** %14
%92 = load i64, i64* %91
%93 = getelementptr inbounds i8, i8* %90, i64 %92
%94 = call i32 @EVP_EncryptUpdate(i32* %89, i8* %93, i32* %29, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 20)
%95 = load i32, i32* %29
%96 = sext i32 %95 to i64
%97 = load i64*, i64** %14
%98 = load i64, i64* %97
%99 = add i64 %98, %96
store i64 %99, i64* %97
%100 = load i32*, i32** %30
%101 = load i8*, i8** %13
%102 = load i64*, i64** %14
%103 = load i64, i64* %102
%104 = getelementptr inbounds i8, i8* %101, i64 %103
%105 = call i32 @EVP_EncryptFinal_ex(i32* %100, i8* %104, i32* %29)
%106 = load i32, i32* %29
%107 = sext i32 %106 to i64
%108 = load i64*, i64** %14
%109 = load i64, i64* %108
%110 = add i64 %109, %107
store i64 %110, i64* %108
%111 = load i32*, i32** %24
%112 = load i64, i64* %26
%113 = getelementptr inbounds i8, i8* %72, i64 %112
%114 = load i64, i64* %27
%115 = load i8*, i8** %13
%116 = load i64*, i64** %14
%117 = load i64, i64* %116
%118 = load i8*, i8** %15
%119 = call i32 @HMAC(i32* %111, i8* %113, i64 %114, i8* %115, i64 %117, i8* %118, i32* %31)
%120 = load i32, i32* %31
%121 = zext i32 %120 to i64
%122 = load i64*, i64** %16
store i64 %121, i64* %122
%123 = load i32*, i32** %19
%124 = call i64 @BN_num_bytes(i32* %123)
%125 = load i64*, i64** %12
store i64 %124, i64* %125
%126 = load i32*, i32** %19
%127 = load i8*, i8** %11
%128 = call i32 @BN_bn2bin(i32* %126, i8* %127)
%129 = load i8*, i8** %22
ret i32 0
}

LLVM IR (-O2):
@POINT_CONVERSION_COMPRESSED = global i32 0
@.str = [5 x i8] c"R = \00"
@stdout = global i32 0
@.str.2 = [14 x i8] c"S_encipher = \00"
@.str.3 = [21 x i8] c"super secret message\00"
define i32 @encipher(i32* %0, i8* %1, i64* nocapture writeonly %2, i8* %3, i64* nocapture %4, i8* %5, i64* nocapture writeonly %6, i8* %7, i64 %8) {
%10 = alloca i32
%11 = alloca i32
%12 = tail call i32* (...) @BN_new()
%13 = tail call i32* (...) @BN_new()
br label %14
14: ; preds = %14, %9
%15 = load i32, i32* @POINT_CONVERSION_COMPRESSED
%16 = tail call i64 @EC_KEY_public_derive_S(i32* %0, i32 %15, i32* %13, i32* %12)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %14
18: ; preds = %14
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @stdout
%21 = tail call i32 @BN_print_fp(i32 %20, i32* %12)
%22 = tail call i32 @putchar(i32 10)
%23 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @stdout
%25 = tail call i32 @BN_print_fp(i32 %24, i32* %13)
%26 = tail call i32 @putchar(i32 10)
%27 = tail call i64 @BN_num_bytes(i32* %13)
%28 = alloca i8, i64 %27
%29 = call i32 @BN_bn2bin(i32* %13, i8* %28)
%30 = call i32* (...) @EVP_sha1()
%31 = call i32* (...) @EVP_aes_256_cbc()
%32 = call i64 @EVP_CIPHER_key_length(i32* %31)
%33 = call i64 @EVP_CIPHER_iv_length(i32* %31)
%34 = add i64 %33, %32
%35 = call i64 @EVP_MD_block_size(i32* %30)
%36 = add i64 %34, %35
%37 = alloca i8, i64 %36
store i64 0, i64* %4
%38 = bitcast i32* %10 to i8*
store i32 0, i32* %10
%39 = call i32 @PKCS5_PBKDF2_HMAC(i8* %28, i64 %27, i8* %7, i64 %8, i32 2000, i32* %30, i64 %36, i8* %37)
%40 = call i32* (...) @EVP_CIPHER_CTX_new()
%41 = call i64 @EVP_CIPHER_key_length(i32* %31)
%42 = getelementptr inbounds i8, i8* %37, i64 %41
%43 = call i32 @EVP_EncryptInit_ex(i32* %40, i32* %31, i32* null, i8* %37, i8* %42)
%44 = load i64, i64* %4
%45 = getelementptr inbounds i8, i8* %3, i64 %44
%46 = call i32 @EVP_EncryptUpdate(i32* %40, i8* %45, i32* %10, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 20)
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = load i64, i64* %4
%50 = add i64 %49, %48
store i64 %50, i64* %4
%51 = getelementptr inbounds i8, i8* %3, i64 %50
%52 = call i32 @EVP_EncryptFinal_ex(i32* %40, i8* %51, i32* %10)
%53 = load i32, i32* %10
%54 = sext i32 %53 to i64
%55 = load i64, i64* %4
%56 = add i64 %55, %54
store i64 %56, i64* %4
%57 = bitcast i32* %11 to i8*
%58 = getelementptr inbounds i8, i8* %37, i64 %34
%59 = call i32 @HMAC(i32* %30, i8* %58, i64 %35, i8* %3, i64 %56, i8* %5, i32* %11)
%60 = load i32, i32* %11
%61 = zext i32 %60 to i64
store i64 %61, i64* %6
%62 = call i64 @BN_num_bytes(i32* %12)
store i64 %62, i64* %2
%63 = call i32 @BN_bn2bin(i32* %12, i8* %1)
ret i32 0
}