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

/* Variables and functions */
int /*<<< orphan*/ DSA_SIG_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *DSA_do_sign(unsigned char const *, int,
                                int /*<<< orphan*/ *);
unsigned int i2d_DSA_SIG(int /*<<< orphan*/ *, unsigned char **);
int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
             unsigned int *siglen, DSA *dsa) {
  DSA_SIG *s;
  s = DSA_do_sign(dgst, dlen, dsa);
  if (s == NULL) {
    *siglen = 0;
    return (0);
  }
  *siglen = i2d_DSA_SIG(s, &sig);
  DSA_SIG_free(s);
  return (1);
}


x86 assembly (clang, -O0):
<DSA_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1050 <DSA_do_sign@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1183 <DSA_sign+0x53>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11a8 <DSA_sign+0x78>
mov    -0x38(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <i2d_DSA_SIG@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rdi
call   1030 <DSA_SIG_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DSA_sign>:
push   %r14
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rsi,%rdi
mov    %rcx,(%rsp)
mov    %edx,%esi
mov    %r9,%rdx
call   1050 <DSA_do_sign@plt>
test   %rax,%rax
je     116d <DSA_sign+0x3d>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1040 <i2d_DSA_SIG@plt>
mov    %eax,(%r14)
mov    %rbx,%rdi
call   1030 <DSA_SIG_free@plt>
mov    $0x1,%eax
jmp    1176 <DSA_sign+0x46>
movl   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @DSA_sign(i32 %0, i8* %1, i32 %2, i8* %3, i32* nocapture writeonly %4, i32* %5) {
%7 = alloca i8*
store i8* %3, i8** %7
%8 = tail call i32* @DSA_do_sign(i8* %1, i32 %2, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %6
store i32 0, i32* %4
br label %14
11: ; preds = %6
%12 = call i32 @i2d_DSA_SIG(i32* %8, i8** %7)
store i32 %12, i32* %4
%13 = call i32 @DSA_SIG_free(i32* %8)
br label %14
14: ; preds = %11, %10
%15 = phi i32 [ 0, %10 ], [ 1, %11 ]
ret i32 %15
}