#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_R_EXTENSION_NOT_FOUND;
int /*<<< orphan*/ X509V3error(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))) {
    X509V3error(X509V3_R_EXTENSION_NOT_FOUND);
    return 0;
  }
  if (!(tmpext = malloc(sizeof(X509V3_EXT_METHOD)))) {
    X509V3error(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   1060 <X509V3_EXT_get_nid@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    117e <X509V3_EXT_add_alias+0x3e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1030 <X509V3error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <X509V3_EXT_add_alias+0xa6>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b0 <X509V3_EXT_add_alias+0x70>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1030 <X509V3error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <X509V3_EXT_add_alias+0xa6>
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    0x2dfa(%rip),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
or     0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <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   1060 <X509V3_EXT_get_nid@plt>
test   %rax,%rax
je     1182 <X509V3_EXT_add_alias+0x42>
mov    %rax,%rbx
mov    $0x8,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     118b <X509V3_EXT_add_alias+0x4b>
mov    0x4(%rbx),%ecx
mov    %ebp,(%rax)
mov    0x2e59(%rip),%rdx
or     (%rdx),%ecx
mov    %ecx,0x4(%rax)
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <X509V3_EXT_add@plt>
mov    0x2e4f(%rip),%rax
jmp    1192 <X509V3_EXT_add_alias+0x52>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1030 <X509V3error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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