#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 /*<<< orphan*/ EVP_MD_type(int /*<<< orphan*/ const *);
int /*<<< orphan*/ RSA_F_CHECK_PADDING_MD;
int RSA_NO_PADDING;
int /*<<< orphan*/ RSA_R_INVALID_PADDING_MODE;
int /*<<< orphan*/ RSA_R_INVALID_X931_DIGEST;
int RSA_X931_PADDING;
int RSA_X931_hash_id(int /*<<< orphan*/);
int /*<<< orphan*/ RSAerr(int /*<<< orphan*/, int /*<<< orphan*/);
int check_padding_md(const EVP_MD *md, int padding) {
  if (!md)
    return 1;
  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(EVP_MD_type(md)) == -1) {
      RSAerr(RSA_F_CHECK_PADDING_MD, RSA_R_INVALID_X931_DIGEST);
      return 0;
    }
    return 1;
  }
  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    11ec <check_padding_md+0xbc>
mov    -0x14(%rbp),%eax
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%eax
jne    118b <check_padding_md+0x5b>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ec <check_padding_md+0xbc>
mov    -0x14(%rbp),%eax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%eax
jne    11e5 <check_padding_md+0xb5>
mov    -0x10(%rbp),%rdi
call   1040 <EVP_MD_type@plt>
mov    %eax,%edi
call   1030 <RSA_X931_hash_id@plt>
cmp    $0xffffffff,%eax
jne    11d9 <check_padding_md+0xa9>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
call   1050 <RSAerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ec <check_padding_md+0xbc>
movl   $0x1,-0x4(%rbp)
jmp    11ec <check_padding_md+0xbc>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_padding_md>:
push   %rbx
mov    $0x1,%ebx
test   %rdi,%rdi
je     117d <check_padding_md+0x4d>
mov    0x2e9e(%rip),%rax
cmp    %esi,(%rax)
jne    1161 <check_padding_md+0x31>
mov    0x2e7b(%rip),%rax
mov    0x2e84(%rip),%rcx
mov    (%rcx),%edi
mov    (%rax),%esi
call   1050 <RSAerr@plt>
xor    %ebx,%ebx
jmp    117d <check_padding_md+0x4d>
mov    0x2e80(%rip),%rax
cmp    %esi,(%rax)
jne    117d <check_padding_md+0x4d>
call   1040 <EVP_MD_type@plt>
mov    %eax,%edi
call   1030 <RSA_X931_hash_id@plt>
cmp    $0xffffffff,%eax
je     1181 <check_padding_md+0x51>
mov    %ebx,%eax
pop    %rbx
ret
mov    0x2e38(%rip),%rax
jmp    114d <check_padding_md+0x1d>

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
define i32 @check_padding_md(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%6 = load i32*, i32** %4
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %2
store i32 1, i32* %3
br label %32
9: ; preds = %2
%10 = load i32, i32* %5
%11 = load i32, i32* @RSA_NO_PADDING
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @RSA_F_CHECK_PADDING_MD
%15 = load i32, i32* @RSA_R_INVALID_PADDING_MODE
%16 = call i32 @RSAerr(i32 %14, i32 %15)
store i32 0, i32* %3
br label %32
17: ; preds = %9
%18 = load i32, i32* %5
%19 = load i32, i32* @RSA_X931_PADDING
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32*, i32** %4
%23 = call i32 @EVP_MD_type(i32* %22)
%24 = call i32 @RSA_X931_hash_id(i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @RSA_F_CHECK_PADDING_MD
%28 = load i32, i32* @RSA_R_INVALID_X931_DIGEST
%29 = call i32 @RSAerr(i32 %27, i32 %28)
store i32 0, i32* %3
br label %32
30: ; preds = %21
store i32 1, i32* %3
br label %32
31: ; preds = %17
store i32 1, i32* %3
br label %32
32: ; preds = %31, %30, %26, %13, %8
%33 = load i32, i32* %3
ret i32 %33
}

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
define i32 @check_padding_md(i32* %0, i32 %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = load i32, i32* @RSA_NO_PADDING
%6 = icmp eq i32 %5, %1
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = load i32, i32* @RSA_X931_PADDING
%9 = icmp eq i32 %8, %1
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = tail call i32 @EVP_MD_type(i32* %0)
%12 = tail call i32 @RSA_X931_hash_id(i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %19
14: ; preds = %10, %4
%15 = phi i32* [ @RSA_R_INVALID_PADDING_MODE, %4 ], [ @RSA_R_INVALID_X931_DIGEST, %10 ]
%16 = load i32, i32* @RSA_F_CHECK_PADDING_MD
%17 = load i32, i32* %15
%18 = tail call i32 @RSAerr(i32 %16, i32 %17)
br label %19
19: ; preds = %14, %7, %10, %2
%20 = phi i32 [ 1, %2 ], [ 1, %10 ], [ 1, %7 ], [ 0, %14 ]
ret i32 %20
}