#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*/ EVP_PKEY;
typedef int /*<<< orphan*/ DSA;

/* Variables and functions */
int /*<<< orphan*/ ASN1error(int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_PKEY_new();
int /*<<< orphan*/ EVP_PKEY_set1_DSA(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int i2d_PUBKEY(int /*<<< orphan*/ *, unsigned char **);
int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) {
  EVP_PKEY *pktmp;
  int ret;
  if (!a)
    return 0;
  pktmp = EVP_PKEY_new();
  if (!pktmp) {
    ASN1error(ERR_R_MALLOC_FAILURE);
    return 0;
  }
  EVP_PKEY_set1_DSA(pktmp, a);
  ret = i2d_PUBKEY(pktmp, pp);
  EVP_PKEY_free(pktmp);
  return ret;
}


x86 assembly (clang, -O0):
<i2d_DSA_PUBKEY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1177 <i2d_DSA_PUBKEY+0x27>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <i2d_DSA_PUBKEY+0x83>
mov    $0x0,%al
call   1050 <EVP_PKEY_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a7 <i2d_DSA_PUBKEY+0x57>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1070 <ASN1error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <i2d_DSA_PUBKEY+0x83>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <EVP_PKEY_set1_DSA@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <i2d_PUBKEY@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <EVP_PKEY_free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2d_DSA_PUBKEY>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a3 <i2d_DSA_PUBKEY+0x53>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <EVP_PKEY_new@plt>
test   %rax,%rax
je     1195 <i2d_DSA_PUBKEY+0x45>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <EVP_PKEY_set1_DSA@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <i2d_PUBKEY@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <EVP_PKEY_free@plt>
mov    %ebp,%eax
jmp    11a5 <i2d_DSA_PUBKEY+0x55>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <ASN1error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @i2d_DSA_PUBKEY(i32* %0, i8** %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = tail call i32* (...) @EVP_PKEY_new()
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @ERR_R_MALLOC_FAILURE
%9 = tail call i32 @ASN1error(i32 %8)
br label %14
10: ; preds = %4
%11 = tail call i32 @EVP_PKEY_set1_DSA(i32* %5, i32* %0)
%12 = tail call i32 @i2d_PUBKEY(i32* %5, i8** %1)
%13 = tail call i32 @EVP_PKEY_free(i32* %5)
br label %14
14: ; preds = %2, %10, %7
%15 = phi i32 [ %12, %10 ], [ 0, %7 ], [ 0, %2 ]
ret i32 %15
}