#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_SIG_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *ECDSA_SIG_new();
int ECDSA_do_verify(unsigned char const *, int, int /*<<< orphan*/ *,
                    int /*<<< orphan*/ *);
int /*<<< orphan*/ *d2i_ECDSA_SIG(int /*<<< orphan*/ **, unsigned char const **,
                                  int);
int /*<<< orphan*/ freezero(unsigned char *, int);
int i2d_ECDSA_SIG(int /*<<< orphan*/ *, unsigned char **);
scalar_t__ memcmp(unsigned char const *, unsigned char *, int);
int ECDSA_verify(int type, const unsigned char *dgst, int dgst_len,
                 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey) {
  ECDSA_SIG *s;
  unsigned char *der = NULL;
  const unsigned char *p = sigbuf;
  int derlen = -1;
  int ret = -1;
  s = ECDSA_SIG_new();
  if (s == NULL)
    return (ret);
  if (d2i_ECDSA_SIG(&s, &p, sig_len) == NULL)
    goto err;
  derlen = i2d_ECDSA_SIG(s, &der);
  if (derlen != sig_len || memcmp(sigbuf, der, derlen))
    goto err;
  ret = ECDSA_do_verify(dgst, dgst_len, s, eckey);
err:
  freezero(der, derlen);
  ECDSA_SIG_free(s);
  return (ret);
}


x86 assembly (clang, -O0):
<ECDSA_verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0xffffffff,-0x4c(%rbp)
movl   $0xffffffff,-0x50(%rbp)
mov    $0x0,%al
call   1080 <ECDSA_SIG_new@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11cd <ECDSA_verify+0x5d>
mov    -0x50(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1259 <ECDSA_verify+0xe9>
mov    -0x24(%rbp),%edx
lea    -0x38(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1090 <d2i_ECDSA_SIG@plt>
cmp    $0x0,%rax
jne    11ec <ECDSA_verify+0x7c>
jmp    123e <ECDSA_verify+0xce>
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <i2d_ECDSA_SIG@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    1222 <ECDSA_verify+0xb2>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     1227 <ECDSA_verify+0xb7>
jmp    123e <ECDSA_verify+0xce>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <ECDSA_do_verify@plt>
mov    %eax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x4c(%rbp),%esi
call   1030 <freezero@plt>
mov    -0x38(%rbp),%rdi
call   1060 <ECDSA_SIG_free@plt>
mov    -0x50(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ECDSA_verify>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8d,%ebx
mov    %rcx,%rbp
mov    %edx,%r15d
mov    %rsi,%r12
movq   $0x0,0x8(%rsp)
mov    %rcx,0x10(%rsp)
xor    %eax,%eax
call   1080 <ECDSA_SIG_new@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     1202 <ECDSA_verify+0x92>
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    %ebx,%edx
call   1090 <d2i_ECDSA_SIG@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
je     120a <ECDSA_verify+0x9a>
mov    (%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1050 <i2d_ECDSA_SIG@plt>
cmp    %ebx,%eax
jne    1211 <ECDSA_verify+0xa1>
mov    0x8(%rsp),%rsi
mov    %rbp,%rdi
mov    %ebx,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    1213 <ECDSA_verify+0xa3>
mov    (%rsp),%rdx
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14,%rcx
call   1040 <ECDSA_do_verify@plt>
mov    %eax,%r13d
jmp    1213 <ECDSA_verify+0xa3>
mov    $0xffffffff,%r13d
jmp    1228 <ECDSA_verify+0xb8>
mov    $0xffffffff,%ebx
jmp    1213 <ECDSA_verify+0xa3>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
mov    %ebx,%esi
call   1030 <freezero@plt>
mov    (%rsp),%rdi
call   1060 <ECDSA_SIG_free@plt>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ECDSA_verify(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*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32
%18 = 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
store i8* null, i8** %15
%19 = load i8*, i8** %11
store i8* %19, i8** %16
store i32 -1, i32* %17
store i32 -1, i32* %18
%20 = call i32* (...) @ECDSA_SIG_new()
store i32* %20, i32** %14
%21 = load i32*, i32** %14
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %6
%24 = load i32, i32* %18
store i32 %24, i32* %7
br label %56
25: ; preds = %6
%26 = load i32, i32* %12
%27 = call i32* @d2i_ECDSA_SIG(i32** %14, i8** %16, i32 %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %30
29: ; preds = %25
br label %49
30: ; preds = %25
%31 = load i32*, i32** %14
%32 = call i32 @i2d_ECDSA_SIG(i32* %31, i8** %15)
store i32 %32, i32* %17
%33 = load i32, i32* %17
%34 = load i32, i32* %12
%35 = icmp ne i32 %33, %34
br i1 %35, label %42, label %36
36: ; preds = %30
%37 = load i8*, i8** %11
%38 = load i8*, i8** %15
%39 = load i32, i32* %17
%40 = call i64 @memcmp(i8* %37, i8* %38, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %36, %30
br label %49
43: ; preds = %36
%44 = load i8*, i8** %9
%45 = load i32, i32* %10
%46 = load i32*, i32** %14
%47 = load i32*, i32** %13
%48 = call i32 @ECDSA_do_verify(i8* %44, i32 %45, i32* %46, i32* %47)
store i32 %48, i32* %18
br label %49
49: ; preds = %43, %42, %29
%50 = load i8*, i8** %15
%51 = load i32, i32* %17
%52 = call i32 @freezero(i8* %50, i32 %51)
%53 = load i32*, i32** %14
%54 = call i32 @ECDSA_SIG_free(i32* %53)
%55 = load i32, i32* %18
store i32 %55, i32* %7
br label %56
56: ; preds = %49, %23
%57 = load i32, i32* %7
ret i32 %57
}

LLVM IR (-O2):
define i32 @ECDSA_verify(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4, i32* %5) {
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = bitcast i32** %7 to i8*
%11 = bitcast i8** %8 to i8*
store i8* null, i8** %8
%12 = bitcast i8** %9 to i8*
store i8* %3, i8** %9
%13 = tail call i32* (...) @ECDSA_SIG_new()
store i32* %13, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %36, label %15
15: ; preds = %6
%16 = call i32* @d2i_ECDSA_SIG(i32** %7, i8** %9, i32 %4)
%17 = icmp eq i32* %16, null
br i1 %17, label %29, label %18
18: ; preds = %15
%19 = load i32*, i32** %7
%20 = call i32 @i2d_ECDSA_SIG(i32* %19, i8** %8)
%21 = icmp eq i32 %20, %4
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = load i8*, i8** %8
%24 = call i64 @memcmp(i8* %3, i8* %23, i32 %4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32*, i32** %7
%28 = call i32 @ECDSA_do_verify(i8* %1, i32 %2, i32* %27, i32* %5)
br label %29
29: ; preds = %18, %22, %15, %26
%30 = phi i32 [ -1, %15 ], [ %20, %18 ], [ %4, %22 ], [ %4, %26 ]
%31 = phi i32 [ -1, %15 ], [ -1, %18 ], [ -1, %22 ], [ %28, %26 ]
%32 = load i8*, i8** %8
%33 = call i32 @freezero(i8* %32, i32 %30)
%34 = load i32*, i32** %7
%35 = call i32 @ECDSA_SIG_free(i32* %34)
br label %36
36: ; preds = %6, %29
%37 = phi i32 [ %31, %29 ], [ -1, %6 ]
ret i32 %37
}