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

/* Variables and functions */
int /*<<< orphan*/ *X509V3_EXT_conf(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                    char *, char *);
int /*<<< orphan*/ X509_EXTENSION_free(int /*<<< orphan*/ *);
int X509_add_ext(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int ssl_x509_v3ext_add(X509V3_CTX *ctx, X509 *crt, char *k, char *v) {
  X509_EXTENSION *ext;
  if (!(ext = X509V3_EXT_conf(NULL, ctx, k, v))) {
    return -1;
  }
  if (X509_add_ext(crt, ext, -1) != 1) {
    X509_EXTENSION_free(ext);
    return -1;
  }
  X509_EXTENSION_free(ext);
  return 0;
}


x86 assembly (clang, -O0):
<ssl_x509_v3ext_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
call   1030 <X509V3_EXT_conf@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1177 <ssl_x509_v3ext_add+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <ssl_x509_v3ext_add+0x87>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0xffffffff,%edx
call   1040 <X509_add_ext@plt>
cmp    $0x1,%eax
je     11a7 <ssl_x509_v3ext_add+0x77>
mov    -0x30(%rbp),%rdi
call   1050 <X509_EXTENSION_free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <ssl_x509_v3ext_add+0x87>
mov    -0x30(%rbp),%rdi
call   1050 <X509_EXTENSION_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_x509_v3ext_add>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rsi
xor    %edi,%edi
call   1030 <X509V3_EXT_conf@plt>
test   %rax,%rax
je     116e <ssl_x509_v3ext_add+0x3e>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0xffffffff,%edx
call   1040 <X509_add_ext@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
setne  %bpl
mov    %rbx,%rdi
call   1050 <X509_EXTENSION_free@plt>
neg    %ebp
jmp    1173 <ssl_x509_v3ext_add+0x43>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ssl_x509_v3ext_add(i32* %0, i32* %1, i8* %2, i8* %3) {
%5 = tail call i32* @X509V3_EXT_conf(i32* null, i32* %0, i8* %2, i8* %3)
%6 = icmp eq i32* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i32 @X509_add_ext(i32* %1, i32* %5, i32 -1)
%9 = icmp ne i32 %8, 1
%10 = tail call i32 @X509_EXTENSION_free(i32* %5)
%11 = sext i1 %9 to i32
br label %12
12: ; preds = %7, %4
%13 = phi i32 [ -1, %4 ], [ %11, %7 ]
ret i32 %13
}