#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*/ SSL;
typedef int /*<<< orphan*/ EVP_MD;

/* Variables and functions */
int /*<<< orphan*/ *EVP_gostr341194();
int /*<<< orphan*/ *EVP_md5_sha1();
int /*<<< orphan*/ *EVP_sha256();
int /*<<< orphan*/ *EVP_sha384();
int /*<<< orphan*/ *EVP_streebog256();
int ssl_get_algorithm2(int /*<<< orphan*/ *);
int ssl_get_handshake_evp_md(SSL *s, const EVP_MD **md) {
  *md = NULL;
  switch (ssl_get_algorithm2(s) & 0xff0) {
  case (0x010 | 0x020):
    *md = EVP_md5_sha1();
    return 1;
  case 0x040:
    *md = EVP_gostr341194();
    return 1;
  case 0x080:
    *md = EVP_sha256();
    return 1;
  case 0x100:
    *md = EVP_sha384();
    return 1;
  case 0x200:
    *md = EVP_streebog256();
    return 1;
  default:
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ssl_get_handshake_evp_md>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <ssl_get_algorithm2@plt>
and    $0xff0,%eax
mov    %eax,-0x1c(%rbp)
sub    $0x30,%eax
je     11e4 <ssl_get_handshake_evp_md+0x84>
jmp    119a <ssl_get_handshake_evp_md+0x3a>
mov    -0x1c(%rbp),%eax
sub    $0x40,%eax
je     1201 <ssl_get_handshake_evp_md+0xa1>
jmp    11ab <ssl_get_handshake_evp_md+0x4b>
mov    -0x1c(%rbp),%eax
sub    $0x80,%eax
je     121e <ssl_get_handshake_evp_md+0xbe>
jmp    11be <ssl_get_handshake_evp_md+0x5e>
mov    -0x1c(%rbp),%eax
sub    $0x100,%eax
je     123b <ssl_get_handshake_evp_md+0xdb>
jmp    11d1 <ssl_get_handshake_evp_md+0x71>
mov    -0x1c(%rbp),%eax
sub    $0x200,%eax
je     1258 <ssl_get_handshake_evp_md+0xf8>
jmp    1275 <ssl_get_handshake_evp_md+0x115>
mov    $0x0,%al
call   1030 <EVP_md5_sha1@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1281 <ssl_get_handshake_evp_md+0x121>
mov    $0x0,%al
call   1050 <EVP_gostr341194@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1281 <ssl_get_handshake_evp_md+0x121>
mov    $0x0,%al
call   1080 <EVP_sha256@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1281 <ssl_get_handshake_evp_md+0x121>
mov    $0x0,%al
call   1060 <EVP_sha384@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1281 <ssl_get_handshake_evp_md+0x121>
mov    $0x0,%al
call   1070 <EVP_streebog256@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1281 <ssl_get_handshake_evp_md+0x121>
jmp    127a <ssl_get_handshake_evp_md+0x11a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_get_handshake_evp_md>:
push   %rbx
mov    %rsi,%rbx
movq   $0x0,(%rsi)
call   1040 <ssl_get_algorithm2@plt>
mov    %eax,%ecx
and    $0xff0,%ecx
xor    %eax,%eax
cmp    $0x7f,%ecx
jle    11a0 <ssl_get_handshake_evp_md+0x40>
cmp    $0x80,%ecx
je     11b3 <ssl_get_handshake_evp_md+0x53>
cmp    $0x100,%ecx
je     11bc <ssl_get_handshake_evp_md+0x5c>
cmp    $0x200,%ecx
jne    11d4 <ssl_get_handshake_evp_md+0x74>
xor    %eax,%eax
call   1070 <EVP_streebog256@plt>
jmp    11cc <ssl_get_handshake_evp_md+0x6c>
cmp    $0x30,%ecx
je     11c5 <ssl_get_handshake_evp_md+0x65>
cmp    $0x40,%ecx
jne    11d4 <ssl_get_handshake_evp_md+0x74>
xor    %eax,%eax
call   1050 <EVP_gostr341194@plt>
jmp    11cc <ssl_get_handshake_evp_md+0x6c>
xor    %eax,%eax
call   1080 <EVP_sha256@plt>
jmp    11cc <ssl_get_handshake_evp_md+0x6c>
xor    %eax,%eax
call   1060 <EVP_sha384@plt>
jmp    11cc <ssl_get_handshake_evp_md+0x6c>
xor    %eax,%eax
call   1030 <EVP_md5_sha1@plt>
mov    %rax,(%rbx)
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @ssl_get_handshake_evp_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*** %5
store i32* null, i32** %6
%7 = load i32*, i32** %4
%8 = call i32 @ssl_get_algorithm2(i32* %7)
%9 = and i32 %8, 4080
switch i32 %9, label %25 [
i32 48, label %10
i32 64, label %13
i32 128, label %16
i32 256, label %19
i32 512, label %22
]
10: ; preds = %2
%11 = call i32* (...) @EVP_md5_sha1()
%12 = load i32**, i32*** %5
store i32* %11, i32** %12
store i32 1, i32* %3
br label %27
13: ; preds = %2
%14 = call i32* (...) @EVP_gostr341194()
%15 = load i32**, i32*** %5
store i32* %14, i32** %15
store i32 1, i32* %3
br label %27
16: ; preds = %2
%17 = call i32* (...) @EVP_sha256()
%18 = load i32**, i32*** %5
store i32* %17, i32** %18
store i32 1, i32* %3
br label %27
19: ; preds = %2
%20 = call i32* (...) @EVP_sha384()
%21 = load i32**, i32*** %5
store i32* %20, i32** %21
store i32 1, i32* %3
br label %27
22: ; preds = %2
%23 = call i32* (...) @EVP_streebog256()
%24 = load i32**, i32*** %5
store i32* %23, i32** %24
store i32 1, i32* %3
br label %27
25: ; preds = %2
br label %26
26: ; preds = %25
store i32 0, i32* %3
br label %27
27: ; preds = %26, %22, %19, %16, %13, %10
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @ssl_get_handshake_evp_md(i32* %0, i32** nocapture writeonly %1) {
store i32* null, i32** %1
%3 = tail call i32 @ssl_get_algorithm2(i32* %0)
%4 = and i32 %3, 4080
switch i32 %4, label %17 [
i32 48, label %5
i32 64, label %7
i32 128, label %9
i32 256, label %11
i32 512, label %13
]
5: ; preds = %2
%6 = tail call i32* (...) @EVP_md5_sha1()
br label %15
7: ; preds = %2
%8 = tail call i32* (...) @EVP_gostr341194()
br label %15
9: ; preds = %2
%10 = tail call i32* (...) @EVP_sha256()
br label %15
11: ; preds = %2
%12 = tail call i32* (...) @EVP_sha384()
br label %15
13: ; preds = %2
%14 = tail call i32* (...) @EVP_streebog256()
br label %15
15: ; preds = %5, %7, %9, %11, %13
%16 = phi i32* [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ]
store i32* %16, i32** %1
br label %17
17: ; preds = %15, %2
%18 = phi i32 [ 0, %2 ], [ 1, %15 ]
ret i32 %18
}