#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 nid;
};
typedef TYPE_1__ EC_builtin_curve;
typedef int /*<<< orphan*/ EC_GROUP;

/* Variables and functions */
int /*<<< orphan*/ EC_GROUP_check(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_GROUP_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EC_GROUP_new_by_curve_name(int);
size_t EC_get_builtin_curves(TYPE_1__ *, size_t);
char *OBJ_nid2sn(int);
int /*<<< orphan*/ OPENSSL_free(TYPE_1__ *);
TYPE_1__ *OPENSSL_malloc(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stdout;
void internal_curve_test(void) {
  EC_builtin_curve *curves = NULL;
  size_t crv_len = 0, n = 0;
  int ok = 1;
  crv_len = EC_get_builtin_curves(NULL, 0);
  curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len);
  if (curves == NULL)
    return;
  if (!EC_get_builtin_curves(curves, crv_len)) {
    OPENSSL_free(curves);
    return;
  }
  fprintf(stdout, "testing internal curves: ");
  for (n = 0; n < crv_len; n++) {
    EC_GROUP *group = NULL;
    int nid = curves[n].nid;
    if ((group = EC_GROUP_new_by_curve_name(nid)) == NULL) {
      ok = 0;
      fprintf(stdout,
              "\nEC_GROUP_new_curve_name() failed with"
              " curve %s\n",
              OBJ_nid2sn(nid));
      continue;
    }
    if (!EC_GROUP_check(group, NULL)) {
      ok = 0;
      fprintf(stdout,
              "\nEC_GROUP_check() failed with"
              " curve %s\n",
              OBJ_nid2sn(nid));
      EC_GROUP_free(group);
      continue;
    }
    fprintf(stdout, ".");
    fflush(stdout);
    EC_GROUP_free(group);
  }
  if (ok)
    fprintf(stdout, " ok\n");
  else
    fprintf(stdout, " failed\n");
  OPENSSL_free(curves);
  return;
}


x86 assembly (clang, -O0):
<internal_curve_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%esi
mov    %rsi,%rdi
call   10a0 <EC_get_builtin_curves@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <OPENSSL_malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11ea <internal_curve_test+0x5a>
jmp    1374 <internal_curve_test+0x1e4>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <EC_get_builtin_curves@plt>
cmp    $0x0,%rax
jne    120f <internal_curve_test+0x7f>
mov    -0x8(%rbp),%rdi
call   10b0 <OPENSSL_free@plt>
jmp    1374 <internal_curve_test+0x1e4>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    132e <internal_curve_test+0x19e>
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <EC_GROUP_new_by_curve_name@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    129c <internal_curve_test+0x10c>
movl   $0x0,-0x1c(%rbp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <OBJ_nid2sn@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    131d <internal_curve_test+0x18d>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <EC_GROUP_check@plt>
cmp    $0x0,%eax
jne    12ef <internal_curve_test+0x15f>
movl   $0x0,-0x1c(%rbp)
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <OBJ_nid2sn@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xd71(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <EC_GROUP_free@plt>
jmp    131d <internal_curve_test+0x18d>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
lea    0xd74(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    -0x28(%rbp),%rdi
call   1030 <EC_GROUP_free@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    122e <internal_curve_test+0x9e>
cmpl   $0x0,-0x1c(%rbp)
je     1354 <internal_curve_test+0x1c4>
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
lea    0xd2d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    136b <internal_curve_test+0x1db>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
lea    0xd16(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <OPENSSL_free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<internal_curve_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
xor    %esi,%esi
call   10a0 <EC_get_builtin_curves@plt>
mov    %rax,%r14
lea    0x0(,%rax,4),%edi
call   1090 <OPENSSL_malloc@plt>
test   %rax,%rax
je     12c9 <internal_curve_test+0x139>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   10a0 <EC_get_builtin_curves@plt>
test   %rax,%rax
je     1301 <internal_curve_test+0x171>
mov    0x2e03(%rip),%rbx
mov    (%rbx),%edi
lea    0xe1a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
test   %r14,%r14
je     12f1 <internal_curve_test+0x161>
movl   $0x1,0xc(%rsp)
xor    %r13d,%r13d
mov    %r14,0x10(%rsp)
jmp    1242 <internal_curve_test+0xb2>
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%ebp
mov    %r12d,%edi
call   1040 <OBJ_nid2sn@plt>
movl   $0x0,0xc(%rsp)
mov    %ebp,%edi
lea    0xdef(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r14
je     12d8 <internal_curve_test+0x148>
mov    (%r15,%r13,4),%r12d
mov    %r12d,%edi
call   1050 <EC_GROUP_new_by_curve_name@plt>
test   %rax,%rax
je     1210 <internal_curve_test+0x80>
mov    %rax,%rbp
mov    %r15,%r14
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <EC_GROUP_check@plt>
mov    (%rbx),%r15d
test   %eax,%eax
je     1290 <internal_curve_test+0x100>
mov    %r15d,%edi
lea    0xdff(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
call   1080 <fflush@plt>
jmp    12b4 <internal_curve_test+0x124>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12d,%edi
call   1040 <OBJ_nid2sn@plt>
movl   $0x0,0xc(%rsp)
mov    %r15d,%edi
lea    0xda1(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <EC_GROUP_free@plt>
mov    %r14,%r15
mov    0x10(%rsp),%r14
jmp    1235 <internal_curve_test+0xa5>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmpl   $0x0,0xc(%rsp)
lea    0xd96(%rip),%rax
lea    0xd8a(%rip),%rsi
cmove  %rax,%rsi
jmp    12f8 <internal_curve_test+0x168>
lea    0xd7d(%rip),%rsi
mov    (%rbx),%edi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <OPENSSL_free@plt>

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
@stdout = global i32 0
@.str = [26 x i8] c"testing internal curves: \00"
@.str.1 = [49 x i8] c"\0AEC_GROUP_new_curve_name() failed with curve %s\0A\00"
@.str.2 = [40 x i8] c"\0AEC_GROUP_check() failed with curve %s\0A\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [5 x i8] c" ok\0A\00"
@.str.5 = [9 x i8] c" failed\0A\00"
define void @internal_curve_test() {
%1 = alloca %struct.TYPE_5__*
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store %struct.TYPE_5__* null, %struct.TYPE_5__** %1
store i64 0, i64* %2
store i64 0, i64* %3
store i32 1, i32* %4
%7 = call i64 @EC_get_builtin_curves(%struct.TYPE_5__* null, i64 0)
store i64 %7, i64* %2
%8 = load i64, i64* %2
%9 = mul i64 4, %8
%10 = trunc i64 %9 to i32
%11 = call %struct.TYPE_5__* @OPENSSL_malloc(i32 %10)
store %struct.TYPE_5__* %11, %struct.TYPE_5__** %1
%12 = load %struct.TYPE_5__*, %struct.TYPE_5__** %1
%13 = icmp eq %struct.TYPE_5__* %12, null
br i1 %13, label %14, label %15
14: ; preds = %0
br label %77
15: ; preds = %0
%16 = load %struct.TYPE_5__*, %struct.TYPE_5__** %1
%17 = load i64, i64* %2
%18 = call i64 @EC_get_builtin_curves(%struct.TYPE_5__* %16, i64 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load %struct.TYPE_5__*, %struct.TYPE_5__** %1
%22 = call i32 @OPENSSL_free(%struct.TYPE_5__* %21)
br label %77
23: ; preds = %15
%24 = load i32, i32* @stdout
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %3
br label %26
26: ; preds = %62, %23
%27 = load i64, i64* %3
%28 = load i64, i64* %2
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %65
30: ; preds = %26
store i32* null, i32** %5
%31 = load %struct.TYPE_5__*, %struct.TYPE_5__** %1
%32 = load i64, i64* %3
%33 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %31, i64 %32
%34 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %33, i32 0, i32 0
%35 = load i32, i32* %34
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = call i32* @EC_GROUP_new_by_curve_name(i32 %36)
store i32* %37, i32** %5
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %44
39: ; preds = %30
store i32 0, i32* %4
%40 = load i32, i32* @stdout
%41 = load i32, i32* %6
%42 = call i8* @OBJ_nid2sn(i32 %41)
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %62
44: ; preds = %30
%45 = load i32*, i32** %5
%46 = call i32 @EC_GROUP_check(i32* %45, i32* null)
%47 = icmp ne i32 %46, 0
br i1 %47, label %55, label %48
48: ; preds = %44
store i32 0, i32* %4
%49 = load i32, i32* @stdout
%50 = load i32, i32* %6
%51 = call i8* @OBJ_nid2sn(i32 %50)
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = load i32*, i32** %5
%54 = call i32 @EC_GROUP_free(i32* %53)
br label %62
55: ; preds = %44
%56 = load i32, i32* @stdout
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* @stdout
%59 = call i32 @fflush(i32 %58)
%60 = load i32*, i32** %5
%61 = call i32 @EC_GROUP_free(i32* %60)
br label %62
62: ; preds = %55, %48, %39
%63 = load i64, i64* %3
%64 = add i64 %63, 1
store i64 %64, i64* %3
br label %26
65: ; preds = %26
%66 = load i32, i32* %4
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32, i32* @stdout
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %74
71: ; preds = %65
%72 = load i32, i32* @stdout
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %74
74: ; preds = %71, %68
%75 = load %struct.TYPE_5__*, %struct.TYPE_5__** %1
%76 = call i32 @OPENSSL_free(%struct.TYPE_5__* %75)
br label %77
77: ; preds = %74, %20, %14
ret void
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32 }
@stdout = global i32 0
@.str = [26 x i8] c"testing internal curves: \00"
@.str.1 = [49 x i8] c"\0AEC_GROUP_new_curve_name() failed with curve %s\0A\00"
@.str.2 = [40 x i8] c"\0AEC_GROUP_check() failed with curve %s\0A\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [5 x i8] c" ok\0A\00"
@.str.5 = [9 x i8] c" failed\0A\00"
define void @internal_curve_test() {
%1 = tail call i64 @EC_get_builtin_curves(%struct.TYPE_5__* null, i64 0)
%2 = trunc i64 %1 to i32
%3 = shl i32 %2, 2
%4 = tail call %struct.TYPE_5__* @OPENSSL_malloc(i32 %3)
%5 = icmp eq %struct.TYPE_5__* %4, null
br i1 %5, label %50, label %6
6: ; preds = %0
%7 = tail call i64 @EC_get_builtin_curves(%struct.TYPE_5__* %4, i64 %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %48, label %9
9: ; preds = %6
%10 = load i32, i32* @stdout
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %1, 0
br i1 %12, label %44, label %13
13: ; preds = %9, %37
%14 = phi i32 [ %38, %37 ], [ 1, %9 ]
%15 = phi i64 [ %39, %37 ], [ 0, %9 ]
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 %15, i32 0
%17 = load i32, i32* %16
%18 = tail call i32* @EC_GROUP_new_by_curve_name(i32 %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = load i32, i32* @stdout
%22 = tail call i8* @OBJ_nid2sn(i32 %17)
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %37
24: ; preds = %13
%25 = tail call i32 @EC_GROUP_check(i32* %18, i32* null)
%26 = icmp eq i32 %25, 0
%27 = load i32, i32* @stdout
br i1 %26, label %28, label %32
28: ; preds = %24
%29 = tail call i8* @OBJ_nid2sn(i32 %17)
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = tail call i32 @EC_GROUP_free(i32* %18)
br label %37
32: ; preds = %24
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @stdout
%35 = tail call i32 @fflush(i32 %34)
%36 = tail call i32 @EC_GROUP_free(i32* %18)
br label %37
37: ; preds = %32, %28, %20
%38 = phi i32 [ 0, %20 ], [ %14, %32 ], [ 0, %28 ]
%39 = add nuw i64 %15, 1
%40 = icmp eq i64 %39, %1
br i1 %40, label %41, label %13
41: ; preds = %37
%42 = icmp eq i32 %38, 0
%43 = select i1 %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0)
br label %44
44: ; preds = %41, %9
%45 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %9 ], [ %43, %41 ]
%46 = load i32, i32* @stdout
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* %45)
br label %48
48: ; preds = %6, %44
%49 = tail call i32 @OPENSSL_free(%struct.TYPE_5__* %4)
br label %50
50: ; preds = %48, %0
ret void
}