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

/* Variables and functions */
int /*<<< orphan*/ EVP_DigestFinal_ex(int /*<<< orphan*/ *, unsigned char *,
                                      int *);
int /*<<< orphan*/ EVP_DigestInit_ex(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ const *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_DigestUpdate(int /*<<< orphan*/ *, char *,
                                    int /*<<< orphan*/);
int EVP_MAX_MD_SIZE;
int /*<<< orphan*/ *EVP_MD_CTX_create();
int /*<<< orphan*/ EVP_MD_CTX_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_cleanup();
int /*<<< orphan*/ *EVP_sha256();
int /*<<< orphan*/ d2i_ECDSA_SIG(int /*<<< orphan*/ *, unsigned char const **,
                                 int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  EVP_MD_CTX *mdctx;
  const EVP_MD *md;
  char mess1[] = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9."
                 "eyJpZCI6MSwiaXNzIjoiYXJ1bi5jb20iLCJ0aW1lX3N0ciI6Ijg6MThwbSAyN"
                 "CBOb3YgMjAxNyIsIndoZXJlIjoiYWlycG9ydCJ9";
  unsigned char md_value[EVP_MAX_MD_SIZE];
  int md_len, i;
  if (!argv[1]) {
    printf("Usage: mdtest digestname\n");
    exit(1);
  }
  md = EVP_sha256();
  if (!md) {
    printf("Unknown message digest %s\n", argv[1]);
    exit(1);
  }
  mdctx = EVP_MD_CTX_create();
  EVP_DigestInit_ex(mdctx, md, NULL);
  EVP_DigestUpdate(mdctx, mess1, strlen(mess1));
  EVP_DigestFinal_ex(mdctx, md_value, &md_len);
  EVP_MD_CTX_destroy(mdctx);
  printf("Dig: %s\n", md_value);
  printf("Dig: %d\n", md_len);
  printf("Digest is: ");
  for (i = 0; i < md_len; i++)
    printf("%02x", md_value[i]);
  printf("\n");
  d2i_ECDSA_SIG(NULL, (const unsigned char **)&md_value[0], md_len);
  EVP_cleanup();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe20(%rip),%rsi
lea    -0xb0(%rbp),%rdi
mov    $0x8a,%edx
call   1080 <memcpy@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0xb8(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xd0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xc0(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    124d <main+0x8d>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10c0 <EVP_sha256@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1283 <main+0xc3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10e0 <EVP_MD_CTX_create@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <EVP_DigestInit_ex@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0xb0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xe0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
mov    %eax,%edx
call   1090 <EVP_DigestUpdate@plt>
mov    -0xd0(%rbp),%rsi
mov    -0x18(%rbp),%rdi
lea    -0xc4(%rbp),%rdx
call   1030 <EVP_DigestFinal_ex@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <EVP_MD_CTX_destroy@plt>
mov    -0xd0(%rbp),%rsi
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc4(%rbp),%esi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xc8(%rbp)
mov    -0xc8(%rbp),%eax
cmp    -0xc4(%rbp),%eax
jge    1380 <main+0x1c0>
mov    -0xd0(%rbp),%rax
movslq -0xc8(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc8(%rbp)
jmp    133a <main+0x17a>
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xd0(%rbp),%rsi
mov    -0xc4(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <d2i_ECDSA_SIG@plt>
mov    $0x0,%al
call   1070 <EVP_cleanup@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%r14
lea    0xe06(%rip),%rsi
lea    -0xb0(%rbp),%rdi
mov    $0x8a,%edx
call   10a0 <memcpy@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
cmpq   $0x0,0x8(%r14)
jne    1242 <main+0x62>
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
call   10e0 <EVP_sha256@plt>
test   %rax,%rax
jne    126a <main+0x8a>
mov    0x8(%r14),%rsi
lea    0xe31(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1100 <EVP_MD_CTX_create@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <EVP_DigestInit_ex@plt>
lea    -0xb0(%rbp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10b0 <EVP_DigestUpdate@plt>
lea    -0x1c(%rbp),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <EVP_DigestFinal_ex@plt>
mov    %r14,%rdi
call   10c0 <EVP_MD_CTX_destroy@plt>
lea    0xde7(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdd7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    131c <main+0x13c>
lea    0xdcf(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
movslq -0x1c(%rbp),%rax
cmp    %rax,%rbx
jl     1300 <main+0x120>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x1c(%rbp),%edx
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <d2i_ECDSA_SIG@plt>
xor    %eax,%eax
call   1090 <EVP_cleanup@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@__const.main.mess1 = [138 x i8] c"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaXNzIjoiYXJ1bi5jb20iLCJ0aW1lX3N0ciI6Ijg6MThwbSAyNCBOb3YgMjAxNyIsIndoZXJlIjoiYWlycG9ydCJ9\00"
@EVP_MAX_MD_SIZE = global i32 0
@.str = [26 x i8] c"Usage: mdtest digestname\0A\00"
@.str.1 = [27 x i8] c"Unknown message digest %s\0A\00"
@.str.2 = [9 x i8] c"Dig: %s\0A\00"
@.str.3 = [9 x i8] c"Dig: %d\0A\00"
@.str.4 = [12 x i8] c"Digest is: \00"
@.str.5 = [5 x i8] c"%02x\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [138 x i8]
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [138 x i8]* %8 to i8*
%14 = load i32, i32* @EVP_MAX_MD_SIZE
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %9
%17 = alloca i8, i64 %15
store i64 %15, i64* %10
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = call i32* (...) @EVP_sha256()
store i32* %26, i32** %7
%27 = load i32*, i32** %7
%28 = icmp ne i32* %27, null
br i1 %28, label %35, label %29
29: ; preds = %25
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %25
%36 = call i32* (...) @EVP_MD_CTX_create()
store i32* %36, i32** %6
%37 = load i32*, i32** %6
%38 = load i32*, i32** %7
%39 = call i32 @EVP_DigestInit_ex(i32* %37, i32* %38, i32* null)
%40 = load i32*, i32** %6
%41 = getelementptr inbounds [138 x i8], [138 x i8]* %8, i64 0, i64 0
%42 = getelementptr inbounds [138 x i8], [138 x i8]* %8, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = call i32 @EVP_DigestUpdate(i32* %40, i8* %41, i32 %43)
%45 = load i32*, i32** %6
%46 = call i32 @EVP_DigestFinal_ex(i32* %45, i8* %17, i32* %11)
%47 = load i32*, i32** %6
%48 = call i32 @EVP_MD_CTX_destroy(i32* %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%50 = load i32, i32* %11
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %12
br label %53
53: ; preds = %64, %35
%54 = load i32, i32* %12
%55 = load i32, i32* %11
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %67
57: ; preds = %53
%58 = load i32, i32* %12
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %17, i64 %59
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %62)
br label %64
64: ; preds = %57
%65 = load i32, i32* %12
%66 = add nsw i32 %65, 1
store i32 %66, i32* %12
br label %53
67: ; preds = %53
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%69 = getelementptr inbounds i8, i8* %17, i64 0
%70 = bitcast i8* %69 to i8**
%71 = load i32, i32* %11
%72 = call i32 @d2i_ECDSA_SIG(i32* null, i8** %70, i32 %71)
%73 = call i32 (...) @EVP_cleanup()
%74 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.mess1 = [138 x i8] c"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiaXNzIjoiYXJ1bi5jb20iLCJ0aW1lX3N0ciI6Ijg6MThwbSAyNCBOb3YgMjAxNyIsIndoZXJlIjoiYWlycG9ydCJ9\00"
@EVP_MAX_MD_SIZE = global i32 0
@.str.1 = [27 x i8] c"Unknown message digest %s\0A\00"
@.str.2 = [9 x i8] c"Dig: %s\0A\00"
@.str.3 = [9 x i8] c"Dig: %d\0A\00"
@.str.4 = [12 x i8] c"Digest is: \00"
@.str.5 = [5 x i8] c"%02x\00"
@str = [25 x i8] c"Usage: mdtest digestname\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [138 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [138 x i8], [138 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @EVP_MAX_MD_SIZE
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = bitcast i32* %4 to i8*
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = tail call i32* (...) @EVP_sha256()
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i8*, i8** %10
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %16
%24 = tail call i32* (...) @EVP_MD_CTX_create()
%25 = tail call i32 @EVP_DigestInit_ex(i32* %24, i32* %17, i32* null)
%26 = call i32 @strlen(i8* %5)
%27 = call i32 @EVP_DigestUpdate(i32* %24, i8* %5, i32 %26)
%28 = call i32 @EVP_DigestFinal_ex(i32* %24, i8* %8, i32* %4)
%29 = call i32 @EVP_MD_CTX_destroy(i32* %24)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %23, %36
%37 = phi i64 [ %42, %36 ], [ 0, %23 ]
%38 = getelementptr inbounds i8, i8* %8, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = add nuw nsw i64 %37, 1
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %42, %44
br i1 %45, label %36, label %46
46: ; preds = %36, %23
%47 = call i32 @putchar(i32 10)
%48 = bitcast i8* %8 to i8**
%49 = load i32, i32* %4
%50 = call i32 @d2i_ECDSA_SIG(i32* null, i8** %48, i32 %49)
%51 = call i32 (...) @EVP_cleanup()
%52 = call i32 @exit(i32 0)
unreachable
}