#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*/ X509_EXTENSION;
typedef int /*<<< orphan*/ X509;

/* Variables and functions */
int X509_add_ext(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ *X509_get_ext(int /*<<< orphan*/ *, int);
int X509_get_ext_by_NID(int /*<<< orphan*/ *, int, int);
int ssl_x509_v3ext_copy_by_nid(X509 *crt, X509 *origcrt, int nid) {
  X509_EXTENSION *ext;
  int pos;
  pos = X509_get_ext_by_NID(origcrt, nid, -1);
  if (pos == -1)
    return 0;
  ext = X509_get_ext(origcrt, pos);
  if (!ext)
    return -1;
  if (X509_add_ext(crt, ext, -1) != 1)
    return -1;
  return 1;
}


x86 assembly (clang, -O0):
<ssl_x509_v3ext_copy_by_nid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0xffffffff,%edx
call   1040 <X509_get_ext_by_NID@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    116d <ssl_x509_v3ext_copy_by_nid+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <ssl_x509_v3ext_copy_by_nid+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <X509_get_ext@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1194 <ssl_x509_v3ext_copy_by_nid+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <ssl_x509_v3ext_copy_by_nid+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0xffffffff,%edx
call   1050 <X509_add_ext@plt>
cmp    $0x1,%eax
je     11bb <ssl_x509_v3ext_copy_by_nid+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <ssl_x509_v3ext_copy_by_nid+0x92>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_x509_v3ext_copy_by_nid>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0xffffffff,%ebp
mov    %rsi,%rdi
mov    %edx,%esi
mov    $0xffffffff,%edx
call   1040 <X509_get_ext_by_NID@plt>
cmp    $0xffffffff,%eax
je     1182 <ssl_x509_v3ext_copy_by_nid+0x52>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <X509_get_ext@plt>
test   %rax,%rax
je     1184 <ssl_x509_v3ext_copy_by_nid+0x54>
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0xffffffff,%edx
call   1050 <X509_add_ext@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
lea    (%rcx,%rcx,1),%ebp
add    $0xffffffff,%ebp
jmp    1184 <ssl_x509_v3ext_copy_by_nid+0x54>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ssl_x509_v3ext_copy_by_nid(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%10 = load i32*, i32** %6
%11 = load i32, i32* %7
%12 = call i32 @X509_get_ext_by_NID(i32* %10, i32 %11, i32 -1)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 0, i32* %4
br label %30
16: ; preds = %3
%17 = load i32*, i32** %6
%18 = load i32, i32* %9
%19 = call i32* @X509_get_ext(i32* %17, i32 %18)
store i32* %19, i32** %8
%20 = load i32*, i32** %8
%21 = icmp ne i32* %20, null
br i1 %21, label %23, label %22
22: ; preds = %16
store i32 -1, i32* %4
br label %30
23: ; preds = %16
%24 = load i32*, i32** %5
%25 = load i32*, i32** %8
%26 = call i32 @X509_add_ext(i32* %24, i32* %25, i32 -1)
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 -1, i32* %4
br label %30
29: ; preds = %23
store i32 1, i32* %4
br label %30
30: ; preds = %29, %28, %22, %15
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @ssl_x509_v3ext_copy_by_nid(i32* %0, i32* %1, i32 %2) {
%4 = tail call i32 @X509_get_ext_by_NID(i32* %1, i32 %2, i32 -1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i32* @X509_get_ext(i32* %1, i32 %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = tail call i32 @X509_add_ext(i32* %0, i32* %7, i32 -1)
%11 = icmp eq i32 %10, 1
%12 = select i1 %11, i32 1, i32 -1
br label %13
13: ; preds = %9, %6, %3
%14 = phi i32 [ 0, %3 ], [ -1, %6 ], [ %12, %9 ]
ret i32 %14
}