#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*/ sha1tmp;
typedef int /*<<< orphan*/ padtmp;
typedef int /*<<< orphan*/ SHA_CTX;
typedef int /*<<< orphan*/ EVP_MD_CTX;

/* Variables and functions */
int EVP_CTRL_SSL3_MASTER_SECRET;
int /*<<< orphan*/ *EVP_MD_CTX_md_data(int /*<<< orphan*/ *);
int /*<<< orphan*/ OPENSSL_cleanse(unsigned char *, int);
int /*<<< orphan*/ SHA1_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Init(int /*<<< orphan*/ *);
scalar_t__ SHA1_Update(int /*<<< orphan*/ *, unsigned char *, int);
int SHA_DIGEST_LENGTH;
int /*<<< orphan*/ memset(unsigned char *, int, int);
int ctrl(EVP_MD_CTX *ctx, int cmd, int mslen, void *ms) {
  unsigned char padtmp[40];
  unsigned char sha1tmp[SHA_DIGEST_LENGTH];
  SHA_CTX *sha1 = EVP_MD_CTX_md_data(ctx);
  if (cmd != EVP_CTRL_SSL3_MASTER_SECRET)
    return 0;
  if (mslen != 48)
    return 0;
  if (SHA1_Update(sha1, ms, mslen) <= 0)
    return 0;
  memset(padtmp, 0x36, sizeof(padtmp));
  if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
    return 0;
  if (!SHA1_Final(sha1tmp, sha1))
    return 0;
  if (!SHA1_Init(sha1))
    return 0;
  if (SHA1_Update(sha1, ms, mslen) <= 0)
    return 0;
  memset(padtmp, 0x5c, sizeof(padtmp));
  if (!SHA1_Update(sha1, padtmp, sizeof(padtmp)))
    return 0;
  if (!SHA1_Update(sha1, sha1tmp, sizeof(sha1tmp)))
    return 0;
  OPENSSL_cleanse(sha1tmp, sizeof(sha1tmp));
  return 1;
}


x86 assembly (clang, -O0):
<ctrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x80(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <EVP_MD_CTX_md_data@plt>
mov    %rax,-0x68(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%eax
je     11db <ctrl+0x7b>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1371 <ctrl+0x211>
cmpl   $0x30,-0x18(%rbp)
je     11f8 <ctrl+0x98>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1371 <ctrl+0x211>
mov    -0x68(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <SHA1_Update@plt>
cmp    $0x0,%rax
jg     1225 <ctrl+0xc5>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1371 <ctrl+0x211>
lea    -0x50(%rbp),%rdi
mov    $0x36,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    -0x68(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x28,%edx
call   1060 <SHA1_Update@plt>
cmp    $0x0,%rax
jne    1267 <ctrl+0x107>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1371 <ctrl+0x211>
mov    -0x78(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1080 <SHA1_Final@plt>
cmp    $0x0,%eax
jne    1290 <ctrl+0x130>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1371 <ctrl+0x211>
mov    -0x68(%rbp),%rdi
call   1070 <SHA1_Init@plt>
cmp    $0x0,%eax
jne    12b5 <ctrl+0x155>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1371 <ctrl+0x211>
mov    -0x68(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1060 <SHA1_Update@plt>
cmp    $0x0,%rax
jg     12e2 <ctrl+0x182>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1371 <ctrl+0x211>
lea    -0x50(%rbp),%rdi
mov    $0x5c,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    -0x68(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x28,%edx
call   1060 <SHA1_Update@plt>
cmp    $0x0,%rax
jne    1324 <ctrl+0x1c4>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1371 <ctrl+0x211>
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rax
mov    -0x68(%rbp),%rdi
mov    %eax,%edx
call   1060 <SHA1_Update@plt>
cmp    $0x0,%rax
jne    1354 <ctrl+0x1f4>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1371 <ctrl+0x211>
mov    -0x78(%rbp),%rdi
mov    -0x80(%rbp),%rax
mov    %eax,%esi
call   1050 <OPENSSL_cleanse@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ctrl>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%rbx
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rsp,-0x30(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
mov    %rax,-0x38(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
call   1030 <EVP_MD_CTX_md_data@plt>
mov    %rax,%r12
xor    %eax,%eax
cmp    $0x30,%r15d
jne    1299 <ctrl+0x139>
mov    0x2e21(%rip),%rcx
cmp    %r14d,(%rcx)
jne    1299 <ctrl+0x139>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x30,%edx
call   1060 <SHA1_Update@plt>
test   %rax,%rax
jle    129f <ctrl+0x13f>
lea    -0x60(%rbp),%r14
mov    %r14,%rdi
mov    $0x36,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x28,%edx
call   1060 <SHA1_Update@plt>
test   %rax,%rax
je     129f <ctrl+0x13f>
mov    %r13,%rdi
mov    %r12,%rsi
call   1080 <SHA1_Final@plt>
test   %eax,%eax
je     129f <ctrl+0x13f>
mov    %r12,%rdi
call   1070 <SHA1_Init@plt>
test   %eax,%eax
je     129f <ctrl+0x13f>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x30,%edx
call   1060 <SHA1_Update@plt>
test   %rax,%rax
jle    129f <ctrl+0x13f>
lea    -0x60(%rbp),%r14
mov    %r14,%rdi
mov    $0x5c,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x28,%edx
call   1060 <SHA1_Update@plt>
test   %rax,%rax
je     129f <ctrl+0x13f>
mov    %r12,%rdi
mov    %r13,%rsi
mov    -0x38(%rbp),%r14
mov    %r14d,%edx
call   1060 <SHA1_Update@plt>
test   %rax,%rax
mov    -0x30(%rbp),%rbx
mov    $0x0,%eax
je     12a5 <ctrl+0x145>
mov    %r13,%rdi
mov    %r14d,%esi
call   1050 <OPENSSL_cleanse@plt>
mov    $0x1,%eax
jmp    12a5 <ctrl+0x145>
mov    -0x30(%rbp),%rbx
jmp    12a5 <ctrl+0x145>
mov    -0x30(%rbp),%rbx
xor    %eax,%eax
mov    %rbx,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA_DIGEST_LENGTH = global i32 0
@EVP_CTRL_SSL3_MASTER_SECRET = global i32 0
define i32 @ctrl(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [40 x i8]
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32*
%14 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%15 = load i32, i32* @SHA_DIGEST_LENGTH
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %11
%18 = alloca i8, i64 %16
store i64 %16, i64* %12
%19 = load i32*, i32** %6
%20 = call i32* @EVP_MD_CTX_md_data(i32* %19)
store i32* %20, i32** %13
%21 = load i32, i32* %7
%22 = load i32, i32* @EVP_CTRL_SSL3_MASTER_SECRET
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %4
store i32 0, i32* %5
store i32 1, i32* %14
br label %78
25: ; preds = %4
%26 = load i32, i32* %8
%27 = icmp ne i32 %26, 48
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 0, i32* %5
store i32 1, i32* %14
br label %78
29: ; preds = %25
%30 = load i32*, i32** %13
%31 = load i8*, i8** %9
%32 = load i32, i32* %8
%33 = call i64 @SHA1_Update(i32* %30, i8* %31, i32 %32)
%34 = icmp sle i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 0, i32* %5
store i32 1, i32* %14
br label %78
36: ; preds = %29
%37 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%38 = call i32 @memset(i8* %37, i32 54, i32 40)
%39 = load i32*, i32** %13
%40 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%41 = call i64 @SHA1_Update(i32* %39, i8* %40, i32 40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %36
store i32 0, i32* %5
store i32 1, i32* %14
br label %78
44: ; preds = %36
%45 = load i32*, i32** %13
%46 = call i32 @SHA1_Final(i8* %18, i32* %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %44
store i32 0, i32* %5
store i32 1, i32* %14
br label %78
49: ; preds = %44
%50 = load i32*, i32** %13
%51 = call i32 @SHA1_Init(i32* %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %49
store i32 0, i32* %5
store i32 1, i32* %14
br label %78
54: ; preds = %49
%55 = load i32*, i32** %13
%56 = load i8*, i8** %9
%57 = load i32, i32* %8
%58 = call i64 @SHA1_Update(i32* %55, i8* %56, i32 %57)
%59 = icmp sle i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %54
store i32 0, i32* %5
store i32 1, i32* %14
br label %78
61: ; preds = %54
%62 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%63 = call i32 @memset(i8* %62, i32 92, i32 40)
%64 = load i32*, i32** %13
%65 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%66 = call i64 @SHA1_Update(i32* %64, i8* %65, i32 40)
%67 = icmp ne i64 %66, 0
br i1 %67, label %69, label %68
68: ; preds = %61
store i32 0, i32* %5
store i32 1, i32* %14
br label %78
69: ; preds = %61
%70 = load i32*, i32** %13
%71 = trunc i64 %16 to i32
%72 = call i64 @SHA1_Update(i32* %70, i8* %18, i32 %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %75, label %74
74: ; preds = %69
store i32 0, i32* %5
store i32 1, i32* %14
br label %78
75: ; preds = %69
%76 = trunc i64 %16 to i32
%77 = call i32 @OPENSSL_cleanse(i8* %18, i32 %76)
store i32 1, i32* %5
store i32 1, i32* %14
br label %78
78: ; preds = %75, %74, %68, %60, %53, %48, %43, %35, %28, %24
%79 = load i8*, i8** %11
%80 = load i32, i32* %5
ret i32 %80
}

LLVM IR (-O2):
@SHA_DIGEST_LENGTH = global i32 0
@EVP_CTRL_SSL3_MASTER_SECRET = global i32 0
define i32 @ctrl(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca [40 x i8]
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* @SHA_DIGEST_LENGTH
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = tail call i32* @EVP_MD_CTX_md_data(i32* %0)
%12 = load i32, i32* @EVP_CTRL_SSL3_MASTER_SECRET
%13 = icmp eq i32 %12, %1
%14 = icmp eq i32 %2, 48
%15 = and i1 %14, %13
br i1 %15, label %16, label %41
16: ; preds = %4
%17 = tail call i64 @SHA1_Update(i32* %11, i8* %3, i32 48)
%18 = icmp slt i64 %17, 1
br i1 %18, label %41, label %19
19: ; preds = %16
%20 = call i32 @memset(i8* %6, i32 54, i32 40)
%21 = call i64 @SHA1_Update(i32* %11, i8* %6, i32 40)
%22 = icmp eq i64 %21, 0
br i1 %22, label %41, label %23
23: ; preds = %19
%24 = call i32 @SHA1_Final(i8* %10, i32* %11)
%25 = icmp eq i32 %24, 0
br i1 %25, label %41, label %26
26: ; preds = %23
%27 = call i32 @SHA1_Init(i32* %11)
%28 = icmp eq i32 %27, 0
br i1 %28, label %41, label %29
29: ; preds = %26
%30 = call i64 @SHA1_Update(i32* %11, i8* %3, i32 48)
%31 = icmp slt i64 %30, 1
br i1 %31, label %41, label %32
32: ; preds = %29
%33 = call i32 @memset(i8* %6, i32 92, i32 40)
%34 = call i64 @SHA1_Update(i32* %11, i8* %6, i32 40)
%35 = icmp eq i64 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %32
%37 = call i64 @SHA1_Update(i32* %11, i8* %10, i32 %7)
%38 = icmp eq i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = call i32 @OPENSSL_cleanse(i8* %10, i32 %7)
br label %41
41: ; preds = %36, %32, %29, %26, %23, %19, %16, %4, %39
%42 = phi i32 [ 1, %39 ], [ 0, %4 ], [ 0, %16 ], [ 0, %19 ], [ 0, %23 ], [ 0, %26 ], [ 0, %29 ], [ 0, %32 ], [ 0, %36 ]
ret i32 %42
}