#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int /*<<< orphan*/ nid;
};
typedef int /*<<< orphan*/ EVP_MD;
typedef TYPE_1__ EC_builtin_curve;
typedef int /*<<< orphan*/ EC_POINT;
typedef int /*<<< orphan*/ EC_GROUP;
typedef int /*<<< orphan*/ BN_CTX;

/* Variables and functions */
int /*<<< orphan*/ EC_GROUP_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_GROUP_new_by_curve_name(int /*<<< orphan*/);
int /*<<< orphan*/ EC_POINT_free(int /*<<< orphan*/ *);
char *EC_POINT_point2hex(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                         int /*<<< orphan*/, int /*<<< orphan*/ *);
int EVP_MD_type(int /*<<< orphan*/ const *);
int /*<<< orphan*/ OPENSSL_free(char *);
int /*<<< orphan*/ POINT_CONVERSION_COMPRESSED;
int /*<<< orphan*/ *find_digest(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *make_constant(int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ const *, char *, char,
                                  int /*<<< orphan*/ *);
char *make_oid(int /*<<< orphan*/ *);
bool output_curve(EC_builtin_curve *curve, BN_CTX *ctx, void *misc,
                  bool (*writer)(void *misc, EC_builtin_curve *curve,
                                 int digest, const char *oid, const char *m,
                                 const char *n)) {
  const EVP_MD *md = NULL;
  EC_GROUP *grp = NULL;
  EC_POINT *m = NULL;
  EC_POINT *n = NULL;
  char *hexm = NULL;
  char *hexn = NULL;
  char *oid = NULL;
  int ret = false;
  grp = EC_GROUP_new_by_curve_name(curve->nid);
  if (grp == NULL)
    goto error;
  oid = make_oid(grp);
  if (oid == NULL) {
    ret = true;
    goto error;
  }
  md = find_digest(grp, ctx);
  if (md == NULL)
    goto error;
  m = make_constant(grp, md, oid, 'M', ctx);
  n = make_constant(grp, md, oid, 'N', ctx);
  if (m == NULL || n == NULL)
    goto error;
  hexm = EC_POINT_point2hex(grp, m, POINT_CONVERSION_COMPRESSED, ctx);
  hexn = EC_POINT_point2hex(grp, n, POINT_CONVERSION_COMPRESSED, ctx);
  if (hexm == NULL || hexn == NULL)
    goto error;
  ret = writer(misc, curve, EVP_MD_type(md), oid, hexm, hexn);
error:
  OPENSSL_free(hexn);
  OPENSSL_free(hexm);
  EC_POINT_free(n);
  EC_POINT_free(m);
  OPENSSL_free(oid);
  EC_GROUP_free(grp);
  return ret;
}


x86 assembly (clang, -O0):
<output_curve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1060 <EC_GROUP_new_by_curve_name@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1209 <output_curve+0x79>
jmp    133c <output_curve+0x1ac>
mov    -0x30(%rbp),%rdi
call   10b0 <make_oid@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    122d <output_curve+0x9d>
movl   $0x1,-0x5c(%rbp)
jmp    133c <output_curve+0x1ac>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <find_digest@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    124e <output_curve+0xbe>
jmp    133c <output_curve+0x1ac>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x10(%rbp),%r8
mov    $0x4d,%ecx
call   1050 <make_constant@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    -0x10(%rbp),%r8
mov    $0x4e,%ecx
call   1050 <make_constant@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12a0 <output_curve+0x110>
cmpq   $0x0,-0x40(%rbp)
jne    12a5 <output_curve+0x115>
jmp    133c <output_curve+0x1ac>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    0x2d34(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
call   1070 <EC_POINT_point2hex@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    0x2d16(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
call   1070 <EC_POINT_point2hex@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12f7 <output_curve+0x167>
cmpq   $0x0,-0x50(%rbp)
jne    12fc <output_curve+0x16c>
jmp    133c <output_curve+0x1ac>
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <EVP_MD_type@plt>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
mov    -0x68(%rbp),%rax
mov    -0x58(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x50(%rbp),%r9
call   *%rax
mov    %eax,-0x5c(%rbp)
mov    -0x50(%rbp),%rdi
call   1090 <OPENSSL_free@plt>
mov    -0x48(%rbp),%rdi
call   1090 <OPENSSL_free@plt>
mov    -0x40(%rbp),%rdi
call   10a0 <EC_POINT_free@plt>
mov    -0x38(%rbp),%rdi
call   10a0 <EC_POINT_free@plt>
mov    -0x58(%rbp),%rdi
call   1090 <OPENSSL_free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <EC_GROUP_free@plt>
mov    -0x5c(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_curve>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
mov    (%rdi),%edi
call   1060 <EC_GROUP_new_by_curve_name@plt>
test   %rax,%rax
mov    %rax,0x30(%rsp)
je     12cd <output_curve+0x13d>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <make_oid@plt>
test   %rax,%rax
je     12df <output_curve+0x14f>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <find_digest@plt>
test   %rax,%rax
je     12f4 <output_curve+0x164>
mov    %r15,0x28(%rsp)
mov    %r12,0x20(%rsp)
mov    %rbx,%rdi
mov    %rax,%r15
mov    %rax,%rsi
mov    %rbp,%rdx
mov    $0x4d,%ecx
mov    %r13,%r8
call   1050 <make_constant@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r15,0x18(%rsp)
mov    %r15,%rsi
mov    %rbp,%rdx
mov    $0x4e,%ecx
mov    %r13,%r8
call   1050 <make_constant@plt>
mov    %r12,(%rsp)
test   %r12,%r12
je     1304 <output_curve+0x174>
test   %rax,%rax
je     1304 <output_curve+0x174>
mov    %rbp,0x8(%rsp)
mov    0x2d9b(%rip),%r15
mov    (%r15),%edx
mov    %rax,%rbp
mov    %rbx,%rdi
mov    (%rsp),%rsi
mov    %r13,%rcx
call   1070 <EC_POINT_point2hex@plt>
mov    %rax,%r12
mov    (%r15),%edx
mov    %rbx,%rdi
mov    %rbp,0x10(%rsp)
mov    %rbp,%rsi
mov    %r13,%rcx
call   1070 <EC_POINT_point2hex@plt>
mov    %rax,%r13
test   %r12,%r12
je     1316 <output_curve+0x186>
mov    0x28(%rsp),%rbx
test   %r13,%r13
mov    $0x0,%r15d
je     131f <output_curve+0x18f>
mov    0x18(%rsp),%rdi
call   1080 <EVP_MD_type@plt>
mov    0x20(%rsp),%rdi
mov    %r14,%rsi
mov    %eax,%edx
mov    0x8(%rsp),%rbp
mov    %rbp,%rcx
mov    %r12,%r8
mov    %r13,%r9
call   *%rbx
mov    %eax,%r15d
mov    (%rsp),%rbx
mov    0x10(%rsp),%r14
jmp    132d <output_curve+0x19d>
xor    %ebx,%ebx
xor    %r14d,%r14d
xor    %r12d,%r12d
xor    %r13d,%r13d
xor    %ebp,%ebp
xor    %r15d,%r15d
jmp    132d <output_curve+0x19d>
mov    $0x1,%r15d
xor    %ebx,%ebx
xor    %r14d,%r14d
xor    %r12d,%r12d
xor    %r13d,%r13d
xor    %ebp,%ebp
jmp    132d <output_curve+0x19d>
xor    %ebx,%ebx
xor    %r14d,%r14d
xor    %r12d,%r12d
xor    %r13d,%r13d
xor    %r15d,%r15d
jmp    132d <output_curve+0x19d>
xor    %r12d,%r12d
xor    %r13d,%r13d
mov    (%rsp),%rbx
xor    %r15d,%r15d
mov    %rax,%r14
jmp    132d <output_curve+0x19d>
mov    (%rsp),%rbx
xor    %r15d,%r15d
jmp    1323 <output_curve+0x193>
mov    (%rsp),%rbx
mov    0x10(%rsp),%r14
mov    0x8(%rsp),%rbp
mov    %r13,%rdi
call   1090 <OPENSSL_free@plt>
mov    %r12,%rdi
call   1090 <OPENSSL_free@plt>
mov    %r14,%rdi
call   10a0 <EC_POINT_free@plt>
mov    %rbx,%rdi
call   10a0 <EC_POINT_free@plt>
mov    %rbp,%rdi
call   1090 <OPENSSL_free@plt>
mov    0x30(%rsp),%rdi
call   1030 <EC_GROUP_free@plt>
mov    %r15d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
@POINT_CONVERSION_COMPRESSED = global i32 0
define i32 @output_curve(%struct.TYPE_5__* %0, i32* %1, i8* %2, i32 (i8*, %struct.TYPE_5__*, i32, i8*, i8*, i8*)* %3) {
%5 = alloca %struct.TYPE_5__*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32 (i8*, %struct.TYPE_5__*, i32, i8*, i8*, i8*)*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
store %struct.TYPE_5__* %0, %struct.TYPE_5__** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i32 (i8*, %struct.TYPE_5__*, i32, i8*, i8*, i8*)* %3, i32 (i8*, %struct.TYPE_5__*, i32, i8*, i8*, i8*)** %8
store i32* null, i32** %9
store i32* null, i32** %10
store i32* null, i32** %11
store i32* null, i32** %12
store i8* null, i8** %13
store i8* null, i8** %14
store i8* null, i8** %15
store i32 0, i32* %16
%17 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32* @EC_GROUP_new_by_curve_name(i32 %19)
store i32* %20, i32** %10
%21 = load i32*, i32** %10
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %24
23: ; preds = %4
br label %81
24: ; preds = %4
%25 = load i32*, i32** %10
%26 = call i8* @make_oid(i32* %25)
store i8* %26, i8** %15
%27 = load i8*, i8** %15
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 1, i32* %16
br label %81
30: ; preds = %24
%31 = load i32*, i32** %10
%32 = load i32*, i32** %6
%33 = call i32* @find_digest(i32* %31, i32* %32)
store i32* %33, i32** %9
%34 = load i32*, i32** %9
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %37
36: ; preds = %30
br label %81
37: ; preds = %30
%38 = load i32*, i32** %10
%39 = load i32*, i32** %9
%40 = load i8*, i8** %15
%41 = load i32*, i32** %6
%42 = call i32* @make_constant(i32* %38, i32* %39, i8* %40, i8 signext 77, i32* %41)
store i32* %42, i32** %11
%43 = load i32*, i32** %10
%44 = load i32*, i32** %9
%45 = load i8*, i8** %15
%46 = load i32*, i32** %6
%47 = call i32* @make_constant(i32* %43, i32* %44, i8* %45, i8 signext 78, i32* %46)
store i32* %47, i32** %12
%48 = load i32*, i32** %11
%49 = icmp eq i32* %48, null
br i1 %49, label %53, label %50
50: ; preds = %37
%51 = load i32*, i32** %12
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %54
53: ; preds = %50, %37
br label %81
54: ; preds = %50
%55 = load i32*, i32** %10
%56 = load i32*, i32** %11
%57 = load i32, i32* @POINT_CONVERSION_COMPRESSED
%58 = load i32*, i32** %6
%59 = call i8* @EC_POINT_point2hex(i32* %55, i32* %56, i32 %57, i32* %58)
store i8* %59, i8** %13
%60 = load i32*, i32** %10
%61 = load i32*, i32** %12
%62 = load i32, i32* @POINT_CONVERSION_COMPRESSED
%63 = load i32*, i32** %6
%64 = call i8* @EC_POINT_point2hex(i32* %60, i32* %61, i32 %62, i32* %63)
store i8* %64, i8** %14
%65 = load i8*, i8** %13
%66 = icmp eq i8* %65, null
br i1 %66, label %70, label %67
67: ; preds = %54
%68 = load i8*, i8** %14
%69 = icmp eq i8* %68, null
br i1 %69, label %70, label %71
70: ; preds = %67, %54
br label %81
71: ; preds = %67
%72 = load i32 (i8*, %struct.TYPE_5__*, i32, i8*, i8*, i8*)*, i32 (i8*, %struct.TYPE_5__*, i32, i8*, i8*, i8*)** %8
%73 = load i8*, i8** %7
%74 = load %struct.TYPE_5__*, %struct.TYPE_5__** %5
%75 = load i32*, i32** %9
%76 = call i32 @EVP_MD_type(i32* %75)
%77 = load i8*, i8** %15
%78 = load i8*, i8** %13
%79 = load i8*, i8** %14
%80 = call i32 %72(i8* %73, %struct.TYPE_5__* %74, i32 %76, i8* %77, i8* %78, i8* %79)
store i32 %80, i32* %16
br label %81
81: ; preds = %71, %70, %53, %36, %29, %23
%82 = load i8*, i8** %14
%83 = call i32 @OPENSSL_free(i8* %82)
%84 = load i8*, i8** %13
%85 = call i32 @OPENSSL_free(i8* %84)
%86 = load i32*, i32** %12
%87 = call i32 @EC_POINT_free(i32* %86)
%88 = load i32*, i32** %11
%89 = call i32 @EC_POINT_free(i32* %88)
%90 = load i8*, i8** %15
%91 = call i32 @OPENSSL_free(i8* %90)
%92 = load i32*, i32** %10
%93 = call i32 @EC_GROUP_free(i32* %92)
%94 = load i32, i32* %16
ret i32 %94
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32 }
@POINT_CONVERSION_COMPRESSED = global i32 0
define i32 @output_curve(%struct.TYPE_5__* %0, i32* %1, i8* %2, i32 (i8*, %struct.TYPE_5__*, i32, i8*, i8*, i8*)* nocapture %3) {
%5 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i32* @EC_GROUP_new_by_curve_name(i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %32, label %9
9: ; preds = %4
%10 = tail call i8* @make_oid(i32* %7)
%11 = icmp eq i8* %10, null
br i1 %11, label %32, label %12
12: ; preds = %9
%13 = tail call i32* @find_digest(i32* %7, i32* %1)
%14 = icmp eq i32* %13, null
br i1 %14, label %32, label %15
15: ; preds = %12
%16 = tail call i32* @make_constant(i32* %7, i32* %13, i8* %10, i8 signext 77, i32* %1)
%17 = tail call i32* @make_constant(i32* %7, i32* %13, i8* %10, i8 signext 78, i32* %1)
%18 = icmp eq i32* %16, null
%19 = icmp eq i32* %17, null
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %32, label %21
21: ; preds = %15
%22 = load i32, i32* @POINT_CONVERSION_COMPRESSED
%23 = tail call i8* @EC_POINT_point2hex(i32* %7, i32* %16, i32 %22, i32* %1)
%24 = load i32, i32* @POINT_CONVERSION_COMPRESSED
%25 = tail call i8* @EC_POINT_point2hex(i32* %7, i32* %17, i32 %24, i32* %1)
%26 = icmp eq i8* %23, null
%27 = icmp eq i8* %25, null
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %32, label %29
29: ; preds = %21
%30 = tail call i32 @EVP_MD_type(i32* %13)
%31 = tail call i32 %3(i8* %2, %struct.TYPE_5__* %0, i32 %30, i8* %10, i8* %23, i8* %25)
br label %32
32: ; preds = %9, %21, %15, %12, %4, %29
%33 = phi i32* [ null, %4 ], [ null, %12 ], [ %16, %15 ], [ %16, %21 ], [ %16, %29 ], [ null, %9 ]
%34 = phi i32* [ null, %4 ], [ null, %12 ], [ %17, %15 ], [ %17, %21 ], [ %17, %29 ], [ null, %9 ]
%35 = phi i8* [ null, %4 ], [ null, %12 ], [ null, %15 ], [ %23, %21 ], [ %23, %29 ], [ null, %9 ]
%36 = phi i8* [ null, %4 ], [ null, %12 ], [ null, %15 ], [ %25, %21 ], [ %25, %29 ], [ null, %9 ]
%37 = phi i8* [ null, %4 ], [ %10, %12 ], [ %10, %15 ], [ %10, %21 ], [ %10, %29 ], [ null, %9 ]
%38 = phi i32 [ 0, %4 ], [ 0, %12 ], [ 0, %15 ], [ 0, %21 ], [ %31, %29 ], [ 1, %9 ]
%39 = tail call i32 @OPENSSL_free(i8* %36)
%40 = tail call i32 @OPENSSL_free(i8* %35)
%41 = tail call i32 @EC_POINT_free(i32* %34)
%42 = tail call i32 @EC_POINT_free(i32* %33)
%43 = tail call i32 @OPENSSL_free(i8* %37)
%44 = tail call i32 @EC_GROUP_free(i32* %7)
ret i32 %38
}