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

/* Variables and functions */
int BN_num_bytes(int /*<<< orphan*/ const *);
int /*<<< orphan*/ DSA_get0_key(int /*<<< orphan*/ *,
                                int /*<<< orphan*/ const **,
                                int /*<<< orphan*/ const **);
int /*<<< orphan*/ DSA_get0_pqg(int /*<<< orphan*/ *,
                                int /*<<< orphan*/ const **,
                                int /*<<< orphan*/ const **,
                                int /*<<< orphan*/ const **);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ write_lebn(unsigned char **, int /*<<< orphan*/ const *,
                              int);
void write_dsa(unsigned char **out, DSA *dsa, int ispub) {
  int nbyte;
  const BIGNUM *p = NULL, *q = NULL, *g = NULL;
  const BIGNUM *pub_key = NULL, *priv_key = NULL;
  DSA_get0_pqg(dsa, &p, &q, &g);
  DSA_get0_key(dsa, &pub_key, &priv_key);
  nbyte = BN_num_bytes(p);
  write_lebn(out, p, nbyte);
  write_lebn(out, q, 20);
  write_lebn(out, g, nbyte);
  if (ispub)
    write_lebn(out, pub_key, nbyte);
  else
    write_lebn(out, priv_key, 20);
  memset(*out, 0xff, 24);
  *out += 24;
  return;
}


x86 assembly (clang, -O0):
<write_dsa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1070 <DSA_get0_pqg@plt>
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1040 <DSA_get0_key@plt>
mov    -0x20(%rbp),%rdi
call   1050 <BN_num_bytes@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <write_lebn@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x14,%edx
call   1060 <write_lebn@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <write_lebn@plt>
cmpl   $0x0,-0x14(%rbp)
je     120e <write_dsa+0xbe>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <write_lebn@plt>
jmp    1220 <write_dsa+0xd0>
mov    -0x8(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x14,%edx
call   1060 <write_lebn@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    $0xff,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x18,%rcx
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_dsa>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x20(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rsi
lea    0x28(%rsp),%rdx
lea    0x20(%rsp),%rcx
mov    %rbp,%rdi
call   1070 <DSA_get0_pqg@plt>
lea    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rbp,%rdi
call   1040 <DSA_get0_key@plt>
mov    0x8(%rsp),%rdi
call   1050 <BN_num_bytes@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1060 <write_lebn@plt>
mov    0x28(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x14,%edx
call   1060 <write_lebn@plt>
mov    0x20(%rsp),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1060 <write_lebn@plt>
test   %r14d,%r14d
je     1204 <write_dsa+0xb4>
mov    0x18(%rsp),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
jmp    1211 <write_dsa+0xc1>
mov    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x14,%edx
call   1060 <write_lebn@plt>
mov    (%rbx),%rdi
mov    $0xff,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
addq   $0x18,(%rbx)
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @write_dsa(i8** %0, i32* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32* null, i32** %8
store i32* null, i32** %9
store i32* null, i32** %10
store i32* null, i32** %11
store i32* null, i32** %12
%13 = load i32*, i32** %5
%14 = call i32 @DSA_get0_pqg(i32* %13, i32** %8, i32** %9, i32** %10)
%15 = load i32*, i32** %5
%16 = call i32 @DSA_get0_key(i32* %15, i32** %11, i32** %12)
%17 = load i32*, i32** %8
%18 = call i32 @BN_num_bytes(i32* %17)
store i32 %18, i32* %7
%19 = load i8**, i8*** %4
%20 = load i32*, i32** %8
%21 = load i32, i32* %7
%22 = call i32 @write_lebn(i8** %19, i32* %20, i32 %21)
%23 = load i8**, i8*** %4
%24 = load i32*, i32** %9
%25 = call i32 @write_lebn(i8** %23, i32* %24, i32 20)
%26 = load i8**, i8*** %4
%27 = load i32*, i32** %10
%28 = load i32, i32* %7
%29 = call i32 @write_lebn(i8** %26, i32* %27, i32 %28)
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %3
%33 = load i8**, i8*** %4
%34 = load i32*, i32** %11
%35 = load i32, i32* %7
%36 = call i32 @write_lebn(i8** %33, i32* %34, i32 %35)
br label %41
37: ; preds = %3
%38 = load i8**, i8*** %4
%39 = load i32*, i32** %12
%40 = call i32 @write_lebn(i8** %38, i32* %39, i32 20)
br label %41
41: ; preds = %37, %32
%42 = load i8**, i8*** %4
%43 = load i8*, i8** %42
%44 = call i32 @memset(i8* %43, i32 255, i32 24)
%45 = load i8**, i8*** %4
%46 = load i8*, i8** %45
%47 = getelementptr inbounds i8, i8* %46, i64 24
store i8* %47, i8** %45
ret void
}

LLVM IR (-O2):
define void @write_dsa(i8** %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = bitcast i32** %4 to i8*
store i32* null, i32** %4
%10 = bitcast i32** %5 to i8*
store i32* null, i32** %5
%11 = bitcast i32** %6 to i8*
store i32* null, i32** %6
%12 = bitcast i32** %7 to i8*
store i32* null, i32** %7
%13 = bitcast i32** %8 to i8*
store i32* null, i32** %8
%14 = call i32 @DSA_get0_pqg(i32* %1, i32** %4, i32** %5, i32** %6)
%15 = call i32 @DSA_get0_key(i32* %1, i32** %7, i32** %8)
%16 = load i32*, i32** %4
%17 = call i32 @BN_num_bytes(i32* %16)
%18 = load i32*, i32** %4
%19 = call i32 @write_lebn(i8** %0, i32* %18, i32 %17)
%20 = load i32*, i32** %5
%21 = call i32 @write_lebn(i8** %0, i32* %20, i32 20)
%22 = load i32*, i32** %6
%23 = call i32 @write_lebn(i8** %0, i32* %22, i32 %17)
%24 = icmp eq i32 %2, 0
br i1 %24, label %28, label %25
25: ; preds = %3
%26 = load i32*, i32** %7
%27 = call i32 @write_lebn(i8** %0, i32* %26, i32 %17)
br label %31
28: ; preds = %3
%29 = load i32*, i32** %8
%30 = call i32 @write_lebn(i8** %0, i32* %29, i32 20)
br label %31
31: ; preds = %28, %25
%32 = load i8*, i8** %0
%33 = call i32 @memset(i8* %32, i32 255, i32 24)
%34 = load i8*, i8** %0
%35 = getelementptr inbounds i8, i8* %34, i64 24
store i8* %35, i8** %0
ret void
}