#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*/ EC_GROUP;
typedef int /*<<< orphan*/ ASN1_OBJECT;

/* Variables and functions */
int /*<<< orphan*/ ASN1_OBJECT_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ EC_GROUP_get_curve_name(int /*<<< orphan*/ const *);
int /*<<< orphan*/ *OBJ_nid2obj(int /*<<< orphan*/);
int OBJ_obj2txt(char *, int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ OPENSSL_free(char *);
char *OPENSSL_malloc(int);
char *make_oid(const EC_GROUP *grp) {
  ASN1_OBJECT *obj = NULL;
  char *oid = NULL;
  int size;
  obj = OBJ_nid2obj(EC_GROUP_get_curve_name(grp));
  if (obj == NULL)
    return NULL;
  size = OBJ_obj2txt(NULL, 0, obj, 1);
  if (size != 0) {
    oid = OPENSSL_malloc(size + 1);
    if (oid != NULL) {
      if (OBJ_obj2txt(oid, size + 1, obj, 1) != size) {
        OPENSSL_free(oid);
        oid = NULL;
      }
    }
  }
  ASN1_OBJECT_free(obj);
  return oid;
}


x86 assembly (clang, -O0):
<make_oid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <EC_GROUP_get_curve_name@plt>
mov    %eax,%edi
call   1030 <OBJ_nid2obj@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a8 <make_oid+0x48>
movq   $0x0,-0x8(%rbp)
jmp    1230 <make_oid+0xd0>
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
mov    $0x1,%ecx
call   1040 <OBJ_obj2txt@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     121f <make_oid+0xbf>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1050 <OPENSSL_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     121a <make_oid+0xba>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    -0x18(%rbp),%rdx
mov    $0x1,%ecx
call   1040 <OBJ_obj2txt@plt>
cmp    -0x24(%rbp),%eax
je     1215 <make_oid+0xb5>
mov    -0x20(%rbp),%rdi
call   1080 <OPENSSL_free@plt>
movq   $0x0,-0x20(%rbp)
jmp    121a <make_oid+0xba>
jmp    121f <make_oid+0xbf>
mov    -0x18(%rbp),%rdi
call   1070 <ASN1_OBJECT_free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_oid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1060 <EC_GROUP_get_curve_name@plt>
mov    %eax,%edi
call   1030 <OBJ_nid2obj@plt>
test   %rax,%rax
je     11d3 <make_oid+0x73>
mov    %rax,%r14
xor    %ebx,%ebx
xor    %edi,%edi
xor    %esi,%esi
mov    %rax,%rdx
mov    $0x1,%ecx
call   1040 <OBJ_obj2txt@plt>
test   %eax,%eax
je     11c9 <make_oid+0x69>
mov    %eax,%r15d
lea    0x1(%r15),%ebp
mov    %ebp,%edi
call   1050 <OPENSSL_malloc@plt>
test   %rax,%rax
je     11c7 <make_oid+0x67>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    $0x1,%ecx
call   1040 <OBJ_obj2txt@plt>
cmp    %r15d,%eax
je     11c9 <make_oid+0x69>
mov    %rbx,%rdi
call   1080 <OPENSSL_free@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1070 <ASN1_OBJECT_free@plt>
jmp    11d5 <make_oid+0x75>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @make_oid(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %3
store i32* null, i32** %4
store i8* null, i8** %5
%7 = load i32*, i32** %3
%8 = call i32 @EC_GROUP_get_curve_name(i32* %7)
%9 = call i32* @OBJ_nid2obj(i32 %8)
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i8* null, i8** %2
br label %41
13: ; preds = %1
%14 = load i32*, i32** %4
%15 = call i32 @OBJ_obj2txt(i8* null, i32 0, i32* %14, i32 1)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %13
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
%21 = call i8* @OPENSSL_malloc(i32 %20)
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %36
24: ; preds = %18
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
%28 = load i32*, i32** %4
%29 = call i32 @OBJ_obj2txt(i8* %25, i32 %27, i32* %28, i32 1)
%30 = load i32, i32* %6
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i8*, i8** %5
%34 = call i32 @OPENSSL_free(i8* %33)
store i8* null, i8** %5
br label %35
35: ; preds = %32, %24
br label %36
36: ; preds = %35, %18
br label %37
37: ; preds = %36, %13
%38 = load i32*, i32** %4
%39 = call i32 @ASN1_OBJECT_free(i32* %38)
%40 = load i8*, i8** %5
store i8* %40, i8** %2
br label %41
41: ; preds = %37, %12
%42 = load i8*, i8** %2
ret i8* %42
}

LLVM IR (-O2):
define i8* @make_oid(i32* %0) {
%2 = tail call i32 @EC_GROUP_get_curve_name(i32* %0)
%3 = tail call i32* @OBJ_nid2obj(i32 %2)
%4 = icmp eq i32* %3, null
br i1 %4, label %20, label %5
5: ; preds = %1
%6 = tail call i32 @OBJ_obj2txt(i8* null, i32 0, i32* %3, i32 1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = add nsw i32 %6, 1
%10 = tail call i8* @OPENSSL_malloc(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = tail call i32 @OBJ_obj2txt(i8* %10, i32 %9, i32* %3, i32 1)
%14 = icmp eq i32 %13, %6
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @OPENSSL_free(i8* %10)
br label %17
17: ; preds = %8, %15, %12, %5
%18 = phi i8* [ null, %15 ], [ %10, %12 ], [ null, %8 ], [ null, %5 ]
%19 = tail call i32 @ASN1_OBJECT_free(i32* %3)
br label %20
20: ; preds = %1, %17
%21 = phi i8* [ %18, %17 ], [ null, %1 ]
ret i8* %21
}