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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ SHA256_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Update(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fread(char *, int, int, int /*<<< orphan*/ *);
void do_sha256sum(FILE *mfile, unsigned char *rptr) {
  char rdata[BUFSIZ];
  int rsize;
  SHA256_CTX c;
  SHA256_Init(&c);
  while (!feof(mfile)) {
    rsize = fread(rdata, sizeof(char), BUFSIZ, mfile);
    if (rsize > 0) {
      SHA256_Update(&c, rdata, rsize);
    }
  }
  SHA256_Final(rptr, &c);
}


x86 assembly (clang, -O0):
<do_sha256sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    -0x28(%rbp),%rdi
call   1040 <SHA256_Init@plt>
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b3 <do_sha256sum+0x63>
jmp    11f0 <do_sha256sum+0xa0>
mov    -0x30(%rbp),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    11eb <do_sha256sum+0x9b>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    -0x28(%rbp),%rdi
call   1070 <SHA256_Update@plt>
jmp    1195 <do_sha256sum+0x45>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <SHA256_Final@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_sha256sum>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e75(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x2c(%rbp),%rdi
call   1040 <SHA256_Init@plt>
mov    %r15,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     11b0 <do_sha256sum+0x60>
lea    -0x2c(%rbp),%rsi
mov    %r14,%rdi
call   1060 <SHA256_Final@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    -0x2c(%rbp),%r12
jmp    11cc <do_sha256sum+0x7c>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    1195 <do_sha256sum+0x45>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jle    11c0 <do_sha256sum+0x70>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <SHA256_Update@plt>
jmp    11c0 <do_sha256sum+0x70>

LLVM IR (-O0):
@BUFSIZ = global i32 0
define void @do_sha256sum(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%9 = load i32, i32* @BUFSIZ
%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* %8)
br label %14
14: ; preds = %28, %2
%15 = load i32*, i32** %3
%16 = call i32 @feof(i32* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = load i32, i32* @BUFSIZ
%21 = load i32*, i32** %3
%22 = call i32 @fread(i8* %12, i32 1, i32 %20, i32* %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i32, i32* %7
%27 = call i32 @SHA256_Update(i32* %8, i8* %12, i32 %26)
br label %28
28: ; preds = %25, %19
br label %14
29: ; preds = %14
%30 = load i8*, i8** %4
%31 = call i32 @SHA256_Final(i8* %30, i32* %8)
%32 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
define void @do_sha256sum(i32* nocapture %0, i8* %1) {
%3 = alloca i32
%4 = load i32, i32* @BUFSIZ
%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 @feof(i32* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %2, %17
%12 = load i32, i32* @BUFSIZ
%13 = call i32 @fread(i8* %6, i32 1, i32 %12, i32* %0)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @SHA256_Update(i32* %3, i8* %6, i32 %13)
br label %17
17: ; preds = %15, %11
%18 = call i32 @feof(i32* %0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %11, label %20
20: ; preds = %17, %2
%21 = call i32 @SHA256_Final(i8* %1, i32* %3)
ret void
}