#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*/ EVP_MD;

/* Variables and functions */
int EVP_MD_type(int /*<<< orphan*/ const *);
#define NID_md2 138
#define NID_md4 137
#define NID_md5 136
#define NID_md5_sha1 135
#define NID_mdc2 134
#define NID_ripemd160 133
#define NID_sha1 132
#define NID_sha224 131
#define NID_sha256 130
#define NID_sha384 129
#define NID_sha512 128
int /*<<< orphan*/ RSA_F_CHECK_PADDING_MD;
int RSA_NO_PADDING;
int /*<<< orphan*/ RSA_R_INVALID_DIGEST;
int /*<<< orphan*/ RSA_R_INVALID_PADDING_MODE;
int /*<<< orphan*/ RSA_R_INVALID_X931_DIGEST;
int RSA_X931_PADDING;
int RSA_X931_hash_id(int);
int /*<<< orphan*/ RSAerr(int /*<<< orphan*/, int /*<<< orphan*/);
int check_padding_md(const EVP_MD *md, int padding) {
  int mdnid;
  if (!md)
    return 1;
  mdnid = EVP_MD_type(md);
  if (padding == RSA_NO_PADDING) {
    RSAerr(RSA_F_CHECK_PADDING_MD, RSA_R_INVALID_PADDING_MODE);
    return 0;
  }
  if (padding == RSA_X931_PADDING) {
    if (RSA_X931_hash_id(mdnid) == -1) {
      RSAerr(RSA_F_CHECK_PADDING_MD, RSA_R_INVALID_X931_DIGEST);
      return 0;
    }
  } else {
    switch (mdnid) {
    case NID_sha1:
    case NID_sha224:
    case NID_sha256:
    case NID_sha384:
    case NID_sha512:
    case NID_md5:
    case NID_md5_sha1:
    case NID_md2:
    case NID_md4:
    case NID_mdc2:
    case NID_ripemd160:
      return 1;
    default:
      RSAerr(RSA_F_CHECK_PADDING_MD, RSA_R_INVALID_DIGEST);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<check_padding_md>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1156 <check_padding_md+0x26>
movl   $0x1,-0x4(%rbp)
jmp    122c <check_padding_md+0xfc>
mov    -0x10(%rbp),%rdi
call   1040 <EVP_MD_type@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%eax
jne    1197 <check_padding_md+0x67>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    122c <check_padding_md+0xfc>
mov    -0x14(%rbp),%eax
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%eax
jne    11e2 <check_padding_md+0xb2>
mov    -0x18(%rbp),%edi
call   1030 <RSA_X931_hash_id@plt>
cmp    $0xffffffff,%eax
jne    11dd <check_padding_md+0xad>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    122c <check_padding_md+0xfc>
jmp    1225 <check_padding_md+0xf5>
mov    -0x18(%rbp),%eax
add    $0xffffff80,%eax
sub    $0xa,%eax
ja     1202 <check_padding_md+0xd2>
jmp    11f6 <check_padding_md+0xc6>
movl   $0x1,-0x4(%rbp)
jmp    122c <check_padding_md+0xfc>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    122c <check_padding_md+0xfc>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_padding_md>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebx
test   %rdi,%rdi
je     1168 <check_padding_md+0x38>
mov    %esi,%ebp
call   1040 <EVP_MD_type@plt>
mov    0x2e95(%rip),%rcx
cmp    %ebp,(%rcx)
jne    1171 <check_padding_md+0x41>
mov    0x2e72(%rip),%rax
mov    0x2e7b(%rip),%rcx
mov    (%rcx),%edi
mov    (%rax),%esi
call   1050 <RSAerr@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e70(%rip),%rcx
cmp    %ebp,(%rcx)
jne    1191 <check_padding_md+0x61>
mov    %eax,%edi
call   1030 <RSA_X931_hash_id@plt>
cmp    $0xffffffff,%eax
jne    1168 <check_padding_md+0x38>
mov    0x2e31(%rip),%rax
jmp    1156 <check_padding_md+0x26>
add    $0xffffff80,%eax
cmp    $0xb,%eax
jb     1168 <check_padding_md+0x38>
mov    0x2e18(%rip),%rax
jmp    1156 <check_padding_md+0x26>

LLVM IR (-O0):
@RSA_NO_PADDING = global i32 0
@RSA_F_CHECK_PADDING_MD = global i32 0
@RSA_R_INVALID_PADDING_MODE = global i32 0
@RSA_X931_PADDING = global i32 0
@RSA_R_INVALID_X931_DIGEST = global i32 0
@RSA_R_INVALID_DIGEST = global i32 0
define i32 @check_padding_md(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 1, i32* %3
br label %41
10: ; preds = %2
%11 = load i32*, i32** %4
%12 = call i32 @EVP_MD_type(i32* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %5
%14 = load i32, i32* @RSA_NO_PADDING
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i32, i32* @RSA_F_CHECK_PADDING_MD
%18 = load i32, i32* @RSA_R_INVALID_PADDING_MODE
%19 = call i32 @RSAerr(i32 %17, i32 %18)
store i32 0, i32* %3
br label %41
20: ; preds = %10
%21 = load i32, i32* %5
%22 = load i32, i32* @RSA_X931_PADDING
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i32, i32* %6
%26 = call i32 @RSA_X931_hash_id(i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i32, i32* @RSA_F_CHECK_PADDING_MD
%30 = load i32, i32* @RSA_R_INVALID_X931_DIGEST
%31 = call i32 @RSAerr(i32 %29, i32 %30)
store i32 0, i32* %3
br label %41
32: ; preds = %24
br label %40
33: ; preds = %20
%34 = load i32, i32* %6
switch i32 %34, label %36 [
i32 132, label %35
i32 131, label %35
i32 130, label %35
i32 129, label %35
i32 128, label %35
i32 136, label %35
i32 135, label %35
i32 138, label %35
i32 137, label %35
i32 134, label %35
i32 133, label %35
]
35: ; preds = %33, %33, %33, %33, %33, %33, %33, %33, %33, %33, %33
store i32 1, i32* %3
br label %41
36: ; preds = %33
%37 = load i32, i32* @RSA_F_CHECK_PADDING_MD
%38 = load i32, i32* @RSA_R_INVALID_DIGEST
%39 = call i32 @RSAerr(i32 %37, i32 %38)
store i32 0, i32* %3
br label %41
40: ; preds = %32
store i32 1, i32* %3
br label %41
41: ; preds = %40, %36, %35, %28, %16, %9
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@RSA_NO_PADDING = global i32 0
@RSA_F_CHECK_PADDING_MD = global i32 0
@RSA_R_INVALID_PADDING_MODE = global i32 0
@RSA_X931_PADDING = global i32 0
@RSA_R_INVALID_X931_DIGEST = global i32 0
@RSA_R_INVALID_DIGEST = global i32 0
define i32 @check_padding_md(i32* %0, i32 %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %22, label %4
4: ; preds = %2
%5 = tail call i32 @EVP_MD_type(i32* %0)
%6 = load i32, i32* @RSA_NO_PADDING
%7 = icmp eq i32 %6, %1
br i1 %7, label %17, label %8
8: ; preds = %4
%9 = load i32, i32* @RSA_X931_PADDING
%10 = icmp eq i32 %9, %1
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @RSA_X931_hash_id(i32 %5)
%13 = icmp eq i32 %12, -1
br i1 %13, label %17, label %22
14: ; preds = %8
%15 = add i32 %5, -128
%16 = icmp ult i32 %15, 11
br i1 %16, label %22, label %17
17: ; preds = %14, %11, %4
%18 = phi i32* [ @RSA_R_INVALID_PADDING_MODE, %4 ], [ @RSA_R_INVALID_X931_DIGEST, %11 ], [ @RSA_R_INVALID_DIGEST, %14 ]
%19 = load i32, i32* @RSA_F_CHECK_PADDING_MD
%20 = load i32, i32* %18
%21 = tail call i32 @RSAerr(i32 %19, i32 %20)
br label %22
22: ; preds = %17, %11, %14, %2
%23 = phi i32 [ 1, %2 ], [ 1, %14 ], [ 1, %11 ], [ 0, %17 ]
ret i32 %23
}