#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*/ EC_KEY;
typedef int /*<<< orphan*/ ECDSA_SIG;

/* Variables and functions */
int /*<<< orphan*/ *ECDSA_do_sign(unsigned char const *, int,
                                  int /*<<< orphan*/ *);
unsigned long ERR_get_error();
ECDSA_SIG *openssl_ECDSA_do_sign(const unsigned char *digest, int len,
                                 EC_KEY *key, unsigned long *e) {
  ECDSA_SIG *sig = ECDSA_do_sign(digest, len, key);
  if (sig != NULL) {
    *e = 0;
    return sig;
  }
  *e = ERR_get_error();
  return NULL;
}


x86 assembly (clang, -O0):
<openssl_ECDSA_do_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <ECDSA_do_sign@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     116e <openssl_ECDSA_do_sign+0x4e>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1187 <openssl_ECDSA_do_sign+0x67>
mov    $0x0,%al
call   1040 <ERR_get_error@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openssl_ECDSA_do_sign>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
call   1030 <ECDSA_do_sign@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1138 <openssl_ECDSA_do_sign+0x18>
xor    %eax,%eax
jmp    113f <openssl_ECDSA_do_sign+0x1f>
xor    %eax,%eax
call   1040 <ERR_get_error@plt>
mov    %rax,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32* @openssl_ECDSA_do_sign(i8* %0, i32 %1, i32* %2, i64* nocapture writeonly %3) {
%5 = tail call i32* @ECDSA_do_sign(i8* %0, i32 %1, i32* %2)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i64 (...) @ERR_get_error()
br label %9
9: ; preds = %4, %7
%10 = phi i64 [ %8, %7 ], [ 0, %4 ]
store i64 %10, i64* %3
ret i32* %5
}