#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*/ explicit_bzero(unsigned char *, int);
int /*<<< orphan*/ free(unsigned char *);
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:
  if (derlen > 0) {
    explicit_bzero(der, derlen);
    free(der);
  }
  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    11dd <ECDSA_verify+0x5d>
mov    -0x50(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    127c <ECDSA_verify+0xfc>
mov    -0x24(%rbp),%edx
lea    -0x38(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   10a0 <d2i_ECDSA_SIG@plt>
cmp    $0x0,%rax
jne    11fc <ECDSA_verify+0x7c>
jmp    124e <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    1232 <ECDSA_verify+0xb2>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x4c(%rbp),%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     1237 <ECDSA_verify+0xb7>
jmp    124e <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)
cmpl   $0x0,-0x4c(%rbp)
jle    126d <ECDSA_verify+0xed>
mov    -0x40(%rbp),%rdi
mov    -0x4c(%rbp),%esi
call   1090 <explicit_bzero@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@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    $0x28,%rsp
mov    %r9,%r14
mov    %r8d,%ebx
mov    %rcx,%rbp
mov    %edx,%r15d
mov    %rsi,%r12
movq   $0x0,0x8(%rsp)
mov    %rcx,0x20(%rsp)
xor    %eax,%eax
call   1080 <ECDSA_SIG_new@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     1241 <ECDSA_verify+0xc1>
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    %ebx,%edx
call   10a0 <d2i_ECDSA_SIG@plt>
test   %rax,%rax
je     1249 <ECDSA_verify+0xc9>
mov    %r14,0x18(%rsp)
mov    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1050 <i2d_ECDSA_SIG@plt>
mov    %eax,%r14d
mov    $0xffffffff,%r13d
cmp    %ebx,%eax
jne    1223 <ECDSA_verify+0xa3>
mov    0x8(%rsp),%rsi
mov    %rbp,%rdi
mov    %ebx,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    1223 <ECDSA_verify+0xa3>
mov    0x10(%rsp),%rdx
mov    %r12,%rdi
mov    %r15d,%esi
mov    0x18(%rsp),%rcx
call   1040 <ECDSA_do_verify@plt>
mov    %eax,%r13d
test   %r14d,%r14d
jle    124f <ECDSA_verify+0xcf>
mov    0x8(%rsp),%rdi
mov    %r14d,%esi
call   1090 <explicit_bzero@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    124f <ECDSA_verify+0xcf>
mov    $0xffffffff,%r13d
jmp    1259 <ECDSA_verify+0xd9>
mov    $0xffffffff,%r13d
mov    0x10(%rsp),%rdi
call   1060 <ECDSA_SIG_free@plt>
mov    %r13d,%eax
add    $0x28,%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 %62
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 i32, i32* %17
%51 = icmp sgt i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i8*, i8** %15
%54 = load i32, i32* %17
%55 = call i32 @explicit_bzero(i8* %53, i32 %54)
%56 = load i8*, i8** %15
%57 = call i32 @free(i8* %56)
br label %58
58: ; preds = %52, %49
%59 = load i32*, i32** %14
%60 = call i32 @ECDSA_SIG_free(i32* %59)
%61 = load i32, i32* %18
store i32 %61, i32* %7
br label %62
62: ; preds = %58, %23
%63 = load i32, i32* %7
ret i32 %63
}

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 %41, 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 %37, 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, %26
%30 = phi i32 [ -1, %18 ], [ -1, %22 ], [ %28, %26 ]
%31 = icmp sgt i32 %20, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i8*, i8** %8
%34 = call i32 @explicit_bzero(i8* %33, i32 %20)
%35 = load i8*, i8** %8
%36 = call i32 @free(i8* %35)
br label %37
37: ; preds = %15, %32, %29
%38 = phi i32 [ %30, %32 ], [ %30, %29 ], [ -1, %15 ]
%39 = load i32*, i32** %7
%40 = call i32 @ECDSA_SIG_free(i32* %39)
br label %41
41: ; preds = %6, %37
%42 = phi i32 [ %38, %37 ], [ -1, %6 ]
ret i32 %42
}