#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 ext_nid;
  int /*<<< orphan*/ ext_flags;
};
typedef TYPE_1__ X509V3_EXT_METHOD;

/* Variables and functions */
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ X509V3_EXT_DYNAMIC;
int X509V3_EXT_add(TYPE_1__ *);
TYPE_1__ *X509V3_EXT_get_nid(int);
int /*<<< orphan*/ X509V3_F_X509V3_EXT_ADD_ALIAS;
int /*<<< orphan*/ X509V3_R_EXTENSION_NOT_FOUND;
int /*<<< orphan*/ X509V3err(int /*<<< orphan*/, int /*<<< orphan*/);
TYPE_1__ *malloc(int);
int X509V3_EXT_add_alias(int nid_to, int nid_from) {
  const X509V3_EXT_METHOD *ext;
  X509V3_EXT_METHOD *tmpext;
  if (!(ext = X509V3_EXT_get_nid(nid_from))) {
    X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS, X509V3_R_EXTENSION_NOT_FOUND);
    return 0;
  }
  if (!(tmpext = malloc(sizeof(X509V3_EXT_METHOD)))) {
    X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS, ERR_R_MALLOC_FAILURE);
    return 0;
  }
  *tmpext = *ext;
  tmpext->ext_nid = nid_to;
  tmpext->ext_flags |= X509V3_EXT_DYNAMIC;
  return X509V3_EXT_add(tmpext);
}


x86 assembly (clang, -O0):
<X509V3_EXT_add_alias>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <X509V3_EXT_get_nid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1187 <X509V3_EXT_add_alias+0x47>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1060 <X509V3err@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f8 <X509V3_EXT_add_alias+0xb8>
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c2 <X509V3_EXT_add_alias+0x82>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
call   1060 <X509V3err@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f8 <X509V3_EXT_add_alias+0xb8>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2de0(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
or     0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <X509V3_EXT_add@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X509V3_EXT_add_alias>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %esi,%edi
call   1050 <X509V3_EXT_get_nid@plt>
test   %rax,%rax
je     1182 <X509V3_EXT_add_alias+0x42>
mov    %rax,%rbx
mov    $0x8,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1194 <X509V3_EXT_add_alias+0x54>
mov    0x4(%rbx),%ecx
mov    %ebp,(%rax)
mov    0x2e51(%rip),%rdx
or     (%rdx),%ecx
mov    %ecx,0x4(%rax)
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <X509V3_EXT_add@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
jmp    11a4 <X509V3_EXT_add_alias+0x64>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1060 <X509V3err@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i32 }
@X509V3_F_X509V3_EXT_ADD_ALIAS = global i32 0
@X509V3_R_EXTENSION_NOT_FOUND = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@X509V3_EXT_DYNAMIC = global i32 0
define i32 @X509V3_EXT_add_alias(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.TYPE_5__*
%7 = alloca %struct.TYPE_5__*
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = call %struct.TYPE_5__* @X509V3_EXT_get_nid(i32 %8)
store %struct.TYPE_5__* %9, %struct.TYPE_5__** %6
%10 = icmp ne %struct.TYPE_5__* %9, null
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @X509V3_F_X509V3_EXT_ADD_ALIAS
%13 = load i32, i32* @X509V3_R_EXTENSION_NOT_FOUND
%14 = call i32 @X509V3err(i32 %12, i32 %13)
store i32 0, i32* %3
br label %37
15: ; preds = %2
%16 = call %struct.TYPE_5__* @malloc(i32 8)
store %struct.TYPE_5__* %16, %struct.TYPE_5__** %7
%17 = icmp ne %struct.TYPE_5__* %16, null
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i32, i32* @X509V3_F_X509V3_EXT_ADD_ALIAS
%20 = load i32, i32* @ERR_R_MALLOC_FAILURE
%21 = call i32 @X509V3err(i32 %19, i32 %20)
store i32 0, i32* %3
br label %37
22: ; preds = %15
%23 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%24 = load %struct.TYPE_5__*, %struct.TYPE_5__** %6
%25 = bitcast %struct.TYPE_5__* %23 to i8*
%26 = bitcast %struct.TYPE_5__* %24 to i8*
%27 = load i32, i32* %4
%28 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%29 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* @X509V3_EXT_DYNAMIC
%31 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = or i32 %33, %30
store i32 %34, i32* %32
%35 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%36 = call i32 @X509V3_EXT_add(%struct.TYPE_5__* %35)
store i32 %36, i32* %3
br label %37
37: ; preds = %22, %18, %11
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32 }
@X509V3_F_X509V3_EXT_ADD_ALIAS = global i32 0
@X509V3_R_EXTENSION_NOT_FOUND = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@X509V3_EXT_DYNAMIC = global i32 0
define i32 @X509V3_EXT_add_alias(i32 %0, i32 %1) {
%3 = tail call %struct.TYPE_5__* @X509V3_EXT_get_nid(i32 %1)
%4 = icmp eq %struct.TYPE_5__* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @X509V3_F_X509V3_EXT_ADD_ALIAS
%7 = load i32, i32* @X509V3_R_EXTENSION_NOT_FOUND
%8 = tail call i32 @X509V3err(i32 %6, i32 %7)
br label %26
9: ; preds = %2
%10 = tail call %struct.TYPE_5__* @malloc(i32 8)
%11 = icmp eq %struct.TYPE_5__* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @X509V3_F_X509V3_EXT_ADD_ALIAS
%14 = load i32, i32* @ERR_R_MALLOC_FAILURE
%15 = tail call i32 @X509V3err(i32 %13, i32 %14)
br label %26
16: ; preds = %9
%17 = bitcast %struct.TYPE_5__* %3 to i64*
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i64 0, i32 0
store i32 %0, i32* %19
%20 = load i32, i32* @X509V3_EXT_DYNAMIC
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i64 0, i32 1
%22 = lshr i64 %18, 32
%23 = trunc i64 %22 to i32
%24 = or i32 %20, %23
store i32 %24, i32* %21
%25 = tail call i32 @X509V3_EXT_add(%struct.TYPE_5__* %10)
br label %26
26: ; preds = %16, %12, %5
%27 = phi i32 [ %25, %16 ], [ 0, %12 ], [ 0, %5 ]
ret i32 %27
}