#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 char uint8_t;
typedef int /*<<< orphan*/ seed;
typedef int /*<<< orphan*/ digest;
typedef int /*<<< orphan*/ EVP_MD;
typedef int /*<<< orphan*/ EC_POINT;
typedef int /*<<< orphan*/ EC_GROUP;
typedef int /*<<< orphan*/ BN_CTX;

/* Variables and functions */
int /*<<< orphan*/ EVP_Digest(char *, int, char *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int EVP_MD_size(int /*<<< orphan*/ const *);
int /*<<< orphan*/ *attempt(int /*<<< orphan*/ const *, char *, int,
                            int /*<<< orphan*/ *);
int snprintf(char *, int, char *, char const *, char);
int strlen(char *);
EC_POINT *make_constant(const EC_GROUP *grp, const EVP_MD *md, const char *oid,
                        char var, BN_CTX *ctx) {
  EC_POINT *p = NULL;
  int len;
  if (grp == NULL || md == NULL || oid == NULL)
    return NULL;
  len = snprintf(NULL, 0, "%s point generation seed (%c)", oid, var);
  if (len < 1)
    return NULL;
  char seed[len + 1];
  if (snprintf(seed, sizeof(seed), "%s point generation seed (%c)", oid, var) !=
      len)
    return NULL;
  uint8_t digest[EVP_MD_size(md)];
  if (!EVP_Digest(seed, strlen(seed), digest, NULL, md, NULL))
    return NULL;
  for (size_t i = 0; i < 1000 && p == NULL; i++) {
    p = attempt(grp, digest, sizeof(digest), ctx);
    EVP_Digest(digest, sizeof(digest), digest, NULL, md, NULL);
  }
  return p;
}


x86 assembly (clang, -O0):
<make_constant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    %r8,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1199 <make_constant+0x49>
cmpq   $0x0,-0x18(%rbp)
je     1199 <make_constant+0x49>
cmpq   $0x0,-0x20(%rbp)
jne    11a6 <make_constant+0x56>
movq   $0x0,-0x8(%rbp)
jmp    1346 <make_constant+0x1f6>
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe49(%rip),%rdx
movsbl -0x21(%rbp),%r8d
call   1060 <snprintf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x3c(%rbp)
jge    11db <make_constant+0x8b>
movq   $0x0,-0x8(%rbp)
jmp    1346 <make_constant+0x1f6>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
mov    %eax,%esi
mov    -0x20(%rbp),%rcx
lea    0xdef(%rip),%rdx
movsbl -0x21(%rbp),%r8d
call   1060 <snprintf@plt>
cmp    -0x3c(%rbp),%eax
je     1238 <make_constant+0xe8>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    133f <make_constant+0x1ef>
mov    -0x18(%rbp),%rdi
call   1030 <EVP_MD_size@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%eax
mov    %rax,-0x80(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    %eax,%esi
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%rcx
call   1070 <EVP_Digest@plt>
cmp    $0x0,%eax
jne    12a4 <make_constant+0x154>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    133f <make_constant+0x1ef>
movq   $0x0,-0x68(%rbp)
xor    %eax,%eax
cmpq   $0x3e8,-0x68(%rbp)
mov    %al,-0x81(%rbp)
jae    12d0 <make_constant+0x180>
cmpq   $0x0,-0x38(%rbp)
sete   %al
mov    %al,-0x81(%rbp)
mov    -0x81(%rbp),%al
test   $0x1,%al
jne    12e3 <make_constant+0x193>
jmp    1330 <make_constant+0x1e0>
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    %eax,%edx
mov    -0x30(%rbp),%rcx
call   1040 <attempt@plt>
mov    -0x78(%rbp),%rdx
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
mov    %rcx,-0x38(%rbp)
mov    %eax,%esi
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
mov    %rdx,%rdi
mov    %r9,%rcx
call   1070 <EVP_Digest@plt>
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    12ac <make_constant+0x15c>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_constant>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,-0x40(%rbp)
xor    %ebx,%ebx
mov    %rdi,-0x38(%rbp)
test   %rdi,%rdi
je     1286 <make_constant+0x136>
mov    %rsi,%r12
test   %rsi,%rsi
je     1286 <make_constant+0x136>
mov    %rdx,%r14
test   %rdx,%rdx
je     1286 <make_constant+0x136>
movsbl %cl,%r15d
lea    0xe69(%rip),%rdx
xor    %ebx,%ebx
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rcx
mov    %r15d,%r8d
call   1060 <snprintf@plt>
test   %eax,%eax
jle    1286 <make_constant+0x136>
mov    %eax,%r13d
mov    %rsp,%rbx
lea    0x1(%r13),%esi
mov    %eax,%eax
mov    %r15d,%r8d
mov    %rsp,%r15
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe29(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rcx
call   1060 <snprintf@plt>
cmp    %r13d,%eax
mov    %rbx,-0x30(%rbp)
jne    1280 <make_constant+0x130>
mov    %r12,%rdi
call   1030 <EVP_MD_size@plt>
mov    %eax,%r13d
mov    %eax,%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r15,%rdi
call   1050 <strlen@plt>
xor    %ebx,%ebx
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    %r12,%r8
xor    %r9d,%r9d
call   1070 <EVP_Digest@plt>
test   %eax,%eax
je     1282 <make_constant+0x132>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x38(%rbp),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
mov    -0x40(%rbp),%rcx
call   1040 <attempt@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r13d,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
mov    %r12,%r8
xor    %r9d,%r9d
call   1070 <EVP_Digest@plt>
cmp    $0x3e6,%r15
ja     1282 <make_constant+0x132>
add    $0x1,%r15
test   %rbx,%rbx
je     1240 <make_constant+0xf0>
jmp    1282 <make_constant+0x132>
xor    %ebx,%ebx
mov    -0x30(%rbp),%rsp
mov    %rbx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"%s point generation seed (%c)\00"
define i32* @make_constant(i32* %0, i32* %1, i8* %2, i8 signext %3, i32* %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i32
%17 = alloca i64
%18 = alloca i64
store i32* %0, i32** %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i8 %3, i8* %10
store i32* %4, i32** %11
store i32* null, i32** %12
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %27, label %21
21: ; preds = %5
%22 = load i32*, i32** %8
%23 = icmp eq i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i8*, i8** %9
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %24, %21, %5
store i32* null, i32** %6
br label %82
28: ; preds = %24
%29 = load i8*, i8** %9
%30 = load i8, i8* %10
%31 = call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %29, i8 signext %30)
store i32 %31, i32* %13
%32 = load i32, i32* %13
%33 = icmp slt i32 %32, 1
br i1 %33, label %34, label %35
34: ; preds = %28
store i32* null, i32** %6
br label %82
35: ; preds = %28
%36 = load i32, i32* %13
%37 = add nsw i32 %36, 1
%38 = zext i32 %37 to i64
%39 = call i8* @llvm.stacksave()
store i8* %39, i8** %14
%40 = alloca i8, i64 %38
store i64 %38, i64* %15
%41 = trunc i64 %38 to i32
%42 = load i8*, i8** %9
%43 = load i8, i8* %10
%44 = call i32 @snprintf(i8* %40, i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %42, i8 signext %43)
%45 = load i32, i32* %13
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %35
store i32* null, i32** %6
store i32 1, i32* %16
br label %80
48: ; preds = %35
%49 = load i32*, i32** %8
%50 = call i32 @EVP_MD_size(i32* %49)
%51 = zext i32 %50 to i64
%52 = alloca i8, i64 %51
store i64 %51, i64* %17
%53 = call i32 @strlen(i8* %40)
%54 = load i32*, i32** %8
%55 = call i32 @EVP_Digest(i8* %40, i32 %53, i8* %52, i32* null, i32* %54, i32* null)
%56 = icmp ne i32 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %48
store i32* null, i32** %6
store i32 1, i32* %16
br label %80
58: ; preds = %48
store i64 0, i64* %18
br label %59
59: ; preds = %75, %58
%60 = load i64, i64* %18
%61 = icmp ult i64 %60, 1000
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i32*, i32** %12
%64 = icmp eq i32* %63, null
br label %65
65: ; preds = %62, %59
%66 = phi i1 [ false, %59 ], [ %64, %62 ]
br i1 %66, label %67, label %78
67: ; preds = %65
%68 = load i32*, i32** %7
%69 = trunc i64 %51 to i32
%70 = load i32*, i32** %11
%71 = call i32* @attempt(i32* %68, i8* %52, i32 %69, i32* %70)
store i32* %71, i32** %12
%72 = trunc i64 %51 to i32
%73 = load i32*, i32** %8
%74 = call i32 @EVP_Digest(i8* %52, i32 %72, i8* %52, i32* null, i32* %73, i32* null)
br label %75
75: ; preds = %67
%76 = load i64, i64* %18
%77 = add i64 %76, 1
store i64 %77, i64* %18
br label %59
78: ; preds = %65
%79 = load i32*, i32** %12
store i32* %79, i32** %6
store i32 1, i32* %16
br label %80
80: ; preds = %78, %57, %47
%81 = load i8*, i8** %14
br label %82
82: ; preds = %80, %34, %27
%83 = load i32*, i32** %6
ret i32* %83
}

LLVM IR (-O2):
@.str = [30 x i8] c"%s point generation seed (%c)\00"
define i32* @make_constant(i32* %0, i32* %1, i8* %2, i8 signext %3, i32* %4) {
%6 = icmp eq i32* %0, null
%7 = icmp eq i32* %1, null
%8 = or i1 %6, %7
%9 = icmp eq i8* %2, null
%10 = or i1 %8, %9
br i1 %10, label %38, label %11
11: ; preds = %5
%12 = tail call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %2, i8 signext %3)
%13 = icmp slt i32 %12, 1
br i1 %13, label %38, label %14
14: ; preds = %11
%15 = add nuw nsw i32 %12, 1
%16 = zext i32 %15 to i64
%17 = tail call i8* @llvm.stacksave()
%18 = alloca i8, i64 %16
%19 = call i32 @snprintf(i8* %18, i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %2, i8 signext %3)
%20 = icmp eq i32 %19, %12
br i1 %20, label %21, label %36
21: ; preds = %14
%22 = call i32 @EVP_MD_size(i32* %1)
%23 = zext i32 %22 to i64
%24 = alloca i8, i64 %23
%25 = call i32 @strlen(i8* %18)
%26 = call i32 @EVP_Digest(i8* %18, i32 %25, i8* %24, i32* null, i32* %1, i32* null)
%27 = icmp eq i32 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %21, %28
%29 = phi i64 [ %32, %28 ], [ 0, %21 ]
%30 = call i32* @attempt(i32* %0, i8* %24, i32 %22, i32* %4)
%31 = call i32 @EVP_Digest(i8* %24, i32 %22, i8* %24, i32* null, i32* %1, i32* null)
%32 = add nuw nsw i64 %29, 1
%33 = icmp ult i64 %29, 999
%34 = icmp eq i32* %30, null
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %28, label %36
36: ; preds = %28, %21, %14
%37 = phi i32* [ null, %14 ], [ null, %21 ], [ %30, %28 ]
br label %38
38: ; preds = %11, %5, %36
%39 = phi i32* [ %37, %36 ], [ null, %5 ], [ null, %11 ]
ret i32* %39
}