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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ EVP_DigestFinal(int /*<<< orphan*/ *, unsigned char *,
                                   unsigned int *);
int /*<<< orphan*/ EVP_DigestInit(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ EVP_DigestUpdate(int /*<<< orphan*/ *, unsigned char *,
                                    size_t);
int /*<<< orphan*/ EVP_MD_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_MD_CTX_init(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_MD_CTX_new();
int /*<<< orphan*/ EVP_MD_size(int /*<<< orphan*/);
int /*<<< orphan*/ EVP_sha1();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
char *oauth_body_hash_encode(size_t, unsigned char *);
scalar_t__ xcalloc(int /*<<< orphan*/, int);
char *oauth_body_hash_file(char *filename) {
  unsigned char fb[BUFSIZ];
  EVP_MD_CTX *ctx;
  size_t len = 0;
  unsigned char *md;
  FILE *F = fopen(filename, "r");
  if (!F)
    return NULL;
  ctx = EVP_MD_CTX_new();
  EVP_MD_CTX_init(ctx);
  EVP_DigestInit(ctx, EVP_sha1());
  while (!feof(F) && (len = fread(fb, sizeof(char), BUFSIZ, F)) > 0) {
    EVP_DigestUpdate(ctx, fb, len);
  }
  fclose(F);
  len = 0;
  md = (unsigned char *)xcalloc(EVP_MD_size(EVP_sha1()), sizeof(unsigned char));
  EVP_DigestFinal(ctx, md, (unsigned int *)&len);
  EVP_MD_CTX_free(ctx);
  return oauth_body_hash_encode(len, md);
}


x86 assembly (clang, -O0):
<oauth_body_hash_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ded(%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,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1253 <oauth_body_hash_file+0x73>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    134a <oauth_body_hash_file+0x16a>
mov    $0x0,%al
call   10d0 <EVP_MD_CTX_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10c0 <EVP_MD_CTX_init@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1070 <EVP_sha1@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
call   1080 <EVP_DigestInit@plt>
mov    -0x40(%rbp),%rdi
call   10a0 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x59(%rbp)
jne    12c3 <oauth_body_hash_file+0xe3>
mov    -0x50(%rbp),%rdi
mov    0x2d3b(%rip),%rax
mov    (%rax),%edx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
seta   %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    12d3 <oauth_body_hash_file+0xf3>
jmp    12e9 <oauth_body_hash_file+0x109>
mov    -0x50(%rbp),%rsi
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
call   10b0 <EVP_DigestUpdate@plt>
jmp    1281 <oauth_body_hash_file+0xa1>
mov    -0x40(%rbp),%rdi
call   1060 <fclose@plt>
movq   $0x0,-0x30(%rbp)
mov    $0x0,%al
call   1070 <EVP_sha1@plt>
mov    %eax,%edi
call   1030 <EVP_MD_size@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1100 <xcalloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   10e0 <EVP_DigestFinal@plt>
mov    -0x28(%rbp),%rdi
call   1040 <EVP_MD_CTX_free@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <oauth_body_hash_encode@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oauth_body_hash_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2dea(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xdee(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     12d7 <oauth_body_hash_file+0xf7>
mov    %rax,%rbx
xor    %eax,%eax
call   10d0 <EVP_MD_CTX_new@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   10c0 <EVP_MD_CTX_init@plt>
xor    %eax,%eax
call   1070 <EVP_sha1@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1080 <EVP_DigestInit@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1285 <oauth_body_hash_file+0xa5>
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     1285 <oauth_body_hash_file+0xa5>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   10b0 <EVP_DigestUpdate@plt>
jmp    1250 <oauth_body_hash_file+0x70>
mov    %rbx,%rdi
call   1060 <fclose@plt>
movq   $0x0,-0x28(%rbp)
xor    %eax,%eax
call   1070 <EVP_sha1@plt>
mov    %eax,%edi
call   1030 <EVP_MD_size@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1100 <xcalloc@plt>
mov    %rax,%rbx
lea    -0x28(%rbp),%rdx
mov    %r14,%rdi
mov    %rax,%rsi
call   10e0 <EVP_DigestFinal@plt>
mov    %r14,%rdi
call   1040 <EVP_MD_CTX_free@plt>
mov    -0x28(%rbp),%rdi
mov    %rbx,%rsi
call   1090 <oauth_body_hash_encode@plt>
jmp    12d9 <oauth_body_hash_file+0xf9>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
define i8* @oauth_body_hash_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i8* %0, i8** %3
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
store i64 0, i64* %7
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %9
%17 = load i32*, i32** %9
%18 = icmp ne i32* %17, null
br i1 %18, label %20, label %19
19: ; preds = %1
store i8* null, i8** %2
store i32 1, i32* %10
br label %58
20: ; preds = %1
%21 = call i32* (...) @EVP_MD_CTX_new()
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = call i32 @EVP_MD_CTX_init(i32* %22)
%24 = load i32*, i32** %6
%25 = call i32 (...) @EVP_sha1()
%26 = call i32 @EVP_DigestInit(i32* %24, i32 %25)
br label %27
27: ; preds = %38, %20
%28 = load i32*, i32** %9
%29 = call i32 @feof(i32* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %27
%32 = load i32, i32* @BUFSIZ
%33 = load i32*, i32** %9
%34 = call i64 @fread(i8* %14, i32 1, i32 %32, i32* %33)
store i64 %34, i64* %7
%35 = icmp ugt i64 %34, 0
br label %36
36: ; preds = %31, %27
%37 = phi i1 [ false, %27 ], [ %35, %31 ]
br i1 %37, label %38, label %42
38: ; preds = %36
%39 = load i32*, i32** %6
%40 = load i64, i64* %7
%41 = call i32 @EVP_DigestUpdate(i32* %39, i8* %14, i64 %40)
br label %27
42: ; preds = %36
%43 = load i32*, i32** %9
%44 = call i32 @fclose(i32* %43)
store i64 0, i64* %7
%45 = call i32 (...) @EVP_sha1()
%46 = call i32 @EVP_MD_size(i32 %45)
%47 = call i64 @xcalloc(i32 %46, i32 1)
%48 = inttoptr i64 %47 to i8*
store i8* %48, i8** %8
%49 = load i32*, i32** %6
%50 = load i8*, i8** %8
%51 = bitcast i64* %7 to i32*
%52 = call i32 @EVP_DigestFinal(i32* %49, i8* %50, i32* %51)
%53 = load i32*, i32** %6
%54 = call i32 @EVP_MD_CTX_free(i32* %53)
%55 = load i64, i64* %7
%56 = load i8*, i8** %8
%57 = call i8* @oauth_body_hash_encode(i64 %55, i8* %56)
store i8* %57, i8** %2
store i32 1, i32* %10
br label %58
58: ; preds = %42, %19
%59 = load i8*, i8** %4
%60 = load i8*, i8** %2
ret i8* %60
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
define i8* @oauth_body_hash_file(i8* nocapture %0) {
%2 = alloca i64
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast i64* %2 to i8*
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %35, label %9
9: ; preds = %1
%10 = tail call i32* (...) @EVP_MD_CTX_new()
%11 = tail call i32 @EVP_MD_CTX_init(i32* %10)
%12 = tail call i32 (...) @EVP_sha1()
%13 = tail call i32 @EVP_DigestInit(i32* %10, i32 %12)
%14 = call i32 @feof(i32* %7)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %9, %20
%17 = load i32, i32* @BUFSIZ
%18 = call i64 @fread(i8* %5, i32 1, i32 %17, i32* %7)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = call i32 @EVP_DigestUpdate(i32* %10, i8* %5, i64 %18)
%22 = call i32 @feof(i32* %7)
%23 = icmp eq i32 %22, 0
br i1 %23, label %16, label %24
24: ; preds = %16, %20, %9
%25 = call i32 @fclose(i32* %7)
store i64 0, i64* %2
%26 = call i32 (...) @EVP_sha1()
%27 = call i32 @EVP_MD_size(i32 %26)
%28 = call i64 @xcalloc(i32 %27, i32 1)
%29 = inttoptr i64 %28 to i8*
%30 = bitcast i64* %2 to i32*
%31 = call i32 @EVP_DigestFinal(i32* %10, i8* %29, i32* %30)
%32 = call i32 @EVP_MD_CTX_free(i32* %10)
%33 = load i64, i64* %2
%34 = call i8* @oauth_body_hash_encode(i64 %33, i8* %29)
br label %35
35: ; preds = %1, %24
%36 = phi i8* [ %34, %24 ], [ null, %1 ]
ret i8* %36
}