#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*/ *, char *,
                                 int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strlen(char *);
void sha256(char *string, char outputBuffer[65]) {
  unsigned char hash[SHA256_DIGEST_LENGTH];
  SHA256_CTX sha256;
  SHA256_Init(&sha256);
  SHA256_Update(&sha256, string, strlen(string));
  SHA256_Final(hash, &sha256);
  int i = 0;
  for (i = 0; i < SHA256_DIGEST_LENGTH; i++) {
    sprintf(outputBuffer + (i * 2), "%02x", hash[i]);
  }
  outputBuffer[64] = 0;
}


x86 assembly (clang, -O0):
<sha256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e79(%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,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    -0x24(%rbp),%rdi
call   1040 <SHA256_Init@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    -0x24(%rbp),%rdi
call   1060 <SHA256_Update@plt>
mov    -0x30(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1050 <SHA256_Final@plt>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2e06(%rip),%rcx
cmp    (%rcx),%eax
jge    1218 <sha256+0xc8>
mov    -0x30(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rdi
movslq -0x28(%rbp),%rcx
lea    0xdff(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11d0 <sha256+0x80>
mov    -0x10(%rbp),%rax
movb   $0x0,0x40(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha256>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,-0x30(%rbp)
mov    %rdi,%rbx
mov    0x2e71(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x34(%rbp),%r15
mov    %r15,%rdi
call   1040 <SHA256_Init@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <SHA256_Update@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <SHA256_Final@plt>
cmpl   $0x0,0x0(%r13)
jle    11f1 <sha256+0xa1>
xor    %r14d,%r14d
lea    0xe3f(%rip),%r15
mov    -0x30(%rbp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r12,%r14,1),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <sprintf@plt>
add    $0x1,%r14
movslq 0x0(%r13),%rax
add    $0x2,%rbx
cmp    %rax,%r14
jl     11d0 <sha256+0x80>
mov    -0x30(%rbp),%rax
movb   $0x0,0x40(%rax)
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
@.str = [5 x i8] c"%02x\00"
define void @sha256(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i32, i32* @SHA256_DIGEST_LENGTH
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = call i32 @SHA256_Init(i32* %7)
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @SHA256_Update(i32* %7, i8* %14, i32 %16)
%18 = call i32 @SHA256_Final(i8* %12, i32* %7)
store i32 0, i32* %8
store i32 0, i32* %8
br label %19
19: ; preds = %34, %2
%20 = load i32, i32* %8
%21 = load i32, i32* @SHA256_DIGEST_LENGTH
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %37
23: ; preds = %19
%24 = load i8*, i8** %4
%25 = load i32, i32* %8
%26 = mul nsw i32 %25, 2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %12, i64 %30
%32 = load i8, i8* %31
%33 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %32)
br label %34
34: ; preds = %23
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %19
37: ; preds = %19
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 64
store i8 0, i8* %39
%40 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@SHA256_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c"%02x\00"
define void @sha256(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = load i32, i32* @SHA256_DIGEST_LENGTH
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast i32* %3 to i8*
%8 = call i32 @SHA256_Init(i32* %3)
%9 = call i32 @strlen(i8* %0)
%10 = call i32 @SHA256_Update(i32* %3, i8* %0, i32 %9)
%11 = call i32 @SHA256_Final(i8* %6, i32* %3)
%12 = load i32, i32* @SHA256_DIGEST_LENGTH
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %2, %14
%15 = phi i64 [ %21, %14 ], [ 0, %2 ]
%16 = shl nuw nsw i64 %15, 1
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = getelementptr inbounds i8, i8* %6, i64 %15
%19 = load i8, i8* %18
%20 = call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %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, %2
%26 = getelementptr inbounds i8, i8* %1, i64 64
store i8 0, i8* %26
ret void
}