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

/* Variables and functions */
int SHA256_DIGEST_LENGTH;
int /*<<< orphan*/ SHA256_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Update(int /*<<< orphan*/ *, unsigned char *,
                                 int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(unsigned char *);
void sha_256(unsigned char *str) {
  int i;
  SHA256_CTX ctx;
  unsigned char result[SHA256_DIGEST_LENGTH];
  SHA256_Init(&ctx);
  SHA256_Update(&ctx, str, strlen(str));
  SHA256_Final(result, &ctx);
  for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
    fprintf(stderr, "%02x", result[i]);
  fprintf(stderr, "\n");
}


x86 assembly (clang, -O0):
<sha_256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <SHA256_Init@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    -0x10(%rbp),%rdi
call   1070 <SHA256_Update@plt>
mov    -0x28(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <SHA256_Final@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e09(%rip),%rcx
cmp    (%rcx),%eax
jge    1208 <sha_256+0xb8>
mov    -0x28(%rbp),%rax
mov    0x2dfe(%rip),%rcx
mov    (%rcx),%edi
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c5 <sha_256+0x75>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha_256>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    %rsp,-0x30(%rbp)
mov    0x2e69(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x34(%rbp),%r15
mov    %r15,%rdi
call   1040 <SHA256_Init@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1070 <SHA256_Update@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <SHA256_Final@plt>
cmpl   $0x0,0x0(%r13)
jle    11ef <sha_256+0x9f>
mov    0x2e22(%rip),%r15
lea    0xe3b(%rip),%r14
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
movzbl (%rbx,%r12,1),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%r12
movslq 0x0(%r13),%rax
cmp    %rax,%r12
jl     11d0 <sha_256+0x80>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SHA256_DIGEST_LENGTH = global i32 0
@stderr = global i32 0
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @sha_256(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i32, i32* @SHA256_DIGEST_LENGTH
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %5
%10 = alloca i8, i64 %8
store i64 %8, i64* %6
%11 = call i32 @SHA256_Init(i32* %4)
%12 = load i8*, i8** %2
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @SHA256_Update(i32* %4, i8* %12, i32 %14)
%16 = call i32 @SHA256_Final(i8* %10, i32* %4)
store i32 0, i32* %3
br label %17
17: ; preds = %29, %1
%18 = load i32, i32* %3
%19 = load i32, i32* @SHA256_DIGEST_LENGTH
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %10, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %21
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %17
32: ; preds = %17
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%35 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
@stderr = global i32 0
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @sha_256(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @SHA256_DIGEST_LENGTH
%5 = zext i32 %4 to i64
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = call i32 @SHA256_Init(i32* %2)
%9 = call i32 @strlen(i8* %0)
%10 = call i32 @SHA256_Update(i32* %2, i8* %0, i32 %9)
%11 = call i32 @SHA256_Final(i8* %7, i32* %2)
%12 = load i32, i32* @SHA256_DIGEST_LENGTH
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %1, %14
%15 = phi i64 [ %21, %14 ], [ 0, %1 ]
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds i8, i8* %7, i64 %15
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = add nuw nsw i64 %15, 1
%22 = load i32, i32* @SHA256_DIGEST_LENGTH
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %14, label %25
25: ; preds = %14, %1
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}