#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_REQ;
typedef int /*<<< orphan*/ X509_NAME;

/* Variables and functions */
int /*<<< orphan*/ X509_NAME_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_REQ_set_subject_name(int /*<<< orphan*/ *,
                                             int /*<<< orphan*/ *);
int /*<<< orphan*/ *parse_name(char *, unsigned long, int);
int build_subject(X509_REQ *req, char *subject, unsigned long chtype,
                  int multirdn) {
  X509_NAME *n;
  if (!(n = parse_name(subject, chtype, multirdn)))
    return 0;
  if (!X509_REQ_set_subject_name(req, n)) {
    X509_NAME_free(n);
    return 0;
  }
  X509_NAME_free(n);
  return 1;
}


x86 assembly (clang, -O0):
<build_subject>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <parse_name@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1171 <build_subject+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11ac <build_subject+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <X509_REQ_set_subject_name@plt>
cmp    $0x0,%eax
jne    119c <build_subject+0x6c>
mov    -0x30(%rbp),%rdi
call   1050 <X509_NAME_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ac <build_subject+0x7c>
mov    -0x30(%rbp),%rdi
call   1050 <X509_NAME_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_subject>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1030 <parse_name@plt>
test   %rax,%rax
je     1168 <build_subject+0x38>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <X509_REQ_set_subject_name@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
mov    %rbx,%rdi
call   1050 <X509_NAME_free@plt>
jmp    116a <build_subject+0x3a>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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