#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*/ uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ digest(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
size_t newsize(size_t const);
int /*<<< orphan*/ *preprocess(int /*<<< orphan*/ const *, size_t const,
                               size_t);
int /*<<< orphan*/ statetobuf(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int sha256(const uint8_t *in, const size_t insize, uint8_t *out) {
  uint8_t *prep;
  size_t size = newsize(insize);
  uint32_t H[8];
  if ((prep = preprocess(in, insize, size)) == NULL)
    return 0;
  digest(prep, size, H);
  free(prep);
  statetobuf(H, out);
  return 1;
}


x86 assembly (clang, -O0):
<sha256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <newsize@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <preprocess@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    119c <sha256+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    11ca <sha256+0x7a>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1050 <digest@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <statetobuf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha256>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
call   1070 <newsize@plt>
mov    %rax,%r15
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1060 <preprocess@plt>
test   %rax,%rax
je     11b0 <sha256+0x60>
mov    %rax,%rbx
mov    %rsp,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <digest@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <statetobuf@plt>
mov    $0x1,%eax
jmp    11b2 <sha256+0x62>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @sha256(i32* %0, i64 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca [8 x i32]
store i32* %0, i32** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
%11 = load i64, i64* %6
%12 = call i64 @newsize(i64 %11)
store i64 %12, i64* %9
%13 = load i32*, i32** %5
%14 = load i64, i64* %6
%15 = load i64, i64* %9
%16 = call i32* @preprocess(i32* %13, i64 %14, i64 %15)
store i32* %16, i32** %8
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %3
store i32 0, i32* %4
br label %29
19: ; preds = %3
%20 = load i32*, i32** %8
%21 = load i64, i64* %9
%22 = getelementptr inbounds [8 x i32], [8 x i32]* %10, i64 0, i64 0
%23 = call i32 @digest(i32* %20, i64 %21, i32* %22)
%24 = load i32*, i32** %8
%25 = call i32 @free(i32* %24)
%26 = getelementptr inbounds [8 x i32], [8 x i32]* %10, i64 0, i64 0
%27 = load i32*, i32** %7
%28 = call i32 @statetobuf(i32* %26, i32* %27)
store i32 1, i32* %4
br label %29
29: ; preds = %19, %18
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @sha256(i32* %0, i64 %1, i32* %2) {
%4 = alloca [8 x i32]
%5 = tail call i64 @newsize(i64 %1)
%6 = bitcast [8 x i32]* %4 to i8*
%7 = tail call i32* @preprocess(i32* %0, i64 %1, i64 %5)
%8 = icmp eq i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %3
%10 = getelementptr inbounds [8 x i32], [8 x i32]* %4, i64 0, i64 0
%11 = call i32 @digest(i32* %7, i64 %5, i32* %10)
%12 = call i32 @free(i32* %7)
%13 = call i32 @statetobuf(i32* %10, i32* %2)
br label %14
14: ; preds = %3, %9
%15 = phi i32 [ 1, %9 ], [ 0, %3 ]
ret i32 %15
}