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

/* Variables and functions */
int /*<<< orphan*/ EVP_DigestFinal_ex(int /*<<< orphan*/ *, unsigned char *,
                                      int *);
int /*<<< orphan*/ EVP_DigestInit_ex(int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ const *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_DigestUpdate(int /*<<< orphan*/ *, char *, int);
int EVP_MAX_MD_SIZE;
int /*<<< orphan*/ *EVP_MD_CTX_create();
int /*<<< orphan*/ EVP_MD_CTX_destroy(int /*<<< orphan*/ *);
int /*<<< orphan*/ *EVP_sha256();
int /*<<< orphan*/ OpenSSL_add_all_digests();
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
main(int argc, char *argv[]) {
  EVP_MD_CTX *mdctx;
  const EVP_MD *md = EVP_sha256();
  char mess[256 + 1];
  unsigned char md_value[EVP_MAX_MD_SIZE];
  int md_len, i, nowLength;
  FILE *theFile;
  if (argc < 2) {
    printf("无文件名！\n");
    return 1;
  } else {
    if ((theFile = fopen(argv[1], "r")) == NULL) {
      printf("打开文件错误！\n");
      return 1;
    } else {
      OpenSSL_add_all_digests();
      mdctx = EVP_MD_CTX_create();
      EVP_DigestInit_ex(mdctx, md, NULL);
      while (!feof(theFile)) {
        nowLength = fread(mess, sizeof(char), 256, theFile);
        mess[nowLength] = 0;
        EVP_DigestUpdate(mdctx, mess, nowLength);
      }
      EVP_DigestFinal_ex(mdctx, md_value, &md_len);
      EVP_MD_CTX_destroy(mdctx);
      for (i = 0; i < md_len; i++)
        printf("%02x", md_value[i]);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
call   10c0 <EVP_sha256@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x138(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x168(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x140(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1237 <main+0x87>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x15c(%rbp)
jmp    139c <main+0x1ec>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdcb(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x158(%rbp)
cmp    $0x0,%rax
jne    1280 <main+0xd0>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x15c(%rbp)
jmp    139c <main+0x1ec>
mov    $0x0,%al
call   1070 <OpenSSL_add_all_digests@plt>
mov    $0x0,%al
call   10d0 <EVP_MD_CTX_create@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <EVP_DigestInit_ex@plt>
mov    -0x158(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12c4 <main+0x114>
jmp    1311 <main+0x161>
lea    -0x130(%rbp),%rdi
mov    -0x158(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   1030 <fread@plt>
mov    %eax,-0x14c(%rbp)
movslq -0x14c(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
mov    -0x18(%rbp),%rdi
lea    -0x130(%rbp),%rsi
mov    -0x14c(%rbp),%edx
call   1090 <EVP_DigestUpdate@plt>
jmp    12a3 <main+0xf3>
mov    -0x168(%rbp),%rsi
mov    -0x18(%rbp),%rdi
lea    -0x144(%rbp),%rdx
call   1040 <EVP_DigestFinal_ex@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <EVP_MD_CTX_destroy@plt>
movl   $0x0,-0x148(%rbp)
mov    -0x148(%rbp),%eax
cmp    -0x144(%rbp),%eax
jge    1381 <main+0x1d1>
mov    -0x168(%rbp),%rax
movslq -0x148(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xcc4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x148(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x148(%rbp)
jmp    133b <main+0x18b>
jmp    1386 <main+0x1d6>
jmp    138b <main+0x1db>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x15c(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
xor    %eax,%eax
call   10d0 <EVP_sha256@plt>
mov    %rax,%r13
mov    %rsp,%r12
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
cmp    $0x2,%ebx
jge    1211 <main+0x51>
lea    0xe11(%rip),%rdi
jmp    1309 <main+0x149>
mov    0x8(%r14),%rdi
lea    0xde4(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1302 <main+0x142>
mov    %rax,%rbx
mov    %r12,-0x38(%rbp)
xor    %r14d,%r14d
xor    %eax,%eax
call   1080 <OpenSSL_add_all_digests@plt>
xor    %eax,%eax
call   10e0 <EVP_MD_CTX_create@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r13,%rsi
xor    %edx,%edx
call   1070 <EVP_DigestInit_ex@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    12a7 <main+0xe7>
lea    -0x140(%rbp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
movslq %eax,%rdx
movb   $0x0,-0x140(%rbp,%rdx,1)
mov    %r12,%rdi
mov    %r13,%rsi
call   10a0 <EVP_DigestUpdate@plt>
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1270 <main+0xb0>
lea    -0x2c(%rbp),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <EVP_DigestFinal_ex@plt>
mov    %r12,%rdi
call   10b0 <EVP_MD_CTX_destroy@plt>
cmpl   $0x0,-0x2c(%rbp)
mov    -0x38(%rbp),%r12
jle    1314 <main+0x154>
xor    %r14d,%r14d
lea    0xd30(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r15,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     12e0 <main+0x120>
mov    -0x38(%rbp),%r12
jmp    1314 <main+0x154>
lea    0xcfe(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r14d
mov    %r12,%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EVP_MAX_MD_SIZE = global i32 0
@.str = [17 x i8] c"\E6\97\A0\E6\96\87\E4\BB\B6\E5\90\8D\EF\BC\81\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"\E6\89\93\E5\BC\80\E6\96\87\E4\BB\B6\E9\94\99\E8\AF\AF\EF\BC\81\0A\00"
@.str.3 = [5 x i8] c"%02x\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [257 x i8]
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = call i32* (...) @EVP_sha256()
store i32* %16, i32** %7
%17 = load i32, i32* @EVP_MAX_MD_SIZE
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %9
%20 = alloca i8, i64 %18
store i64 %18, i64* %10
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 2
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %15
br label %77
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %14
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %15
br label %77
33: ; preds = %25
%34 = call i32 (...) @OpenSSL_add_all_digests()
%35 = call i32* (...) @EVP_MD_CTX_create()
store i32* %35, i32** %6
%36 = load i32*, i32** %6
%37 = load i32*, i32** %7
%38 = call i32 @EVP_DigestInit_ex(i32* %36, i32* %37, i32* null)
br label %39
39: ; preds = %44, %33
%40 = load i32*, i32** %14
%41 = call i32 @feof(i32* %40)
%42 = icmp ne i32 %41, 0
%43 = xor i1 %42, true
br i1 %43, label %44, label %55
44: ; preds = %39
%45 = getelementptr inbounds [257 x i8], [257 x i8]* %8, i64 0, i64 0
%46 = load i32*, i32** %14
%47 = call i32 @fread(i8* %45, i32 1, i32 256, i32* %46)
store i32 %47, i32* %13
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [257 x i8], [257 x i8]* %8, i64 0, i64 %49
store i8 0, i8* %50
%51 = load i32*, i32** %6
%52 = getelementptr inbounds [257 x i8], [257 x i8]* %8, i64 0, i64 0
%53 = load i32, i32* %13
%54 = call i32 @EVP_DigestUpdate(i32* %51, i8* %52, i32 %53)
br label %39
55: ; preds = %39
%56 = load i32*, i32** %6
%57 = call i32 @EVP_DigestFinal_ex(i32* %56, i8* %20, i32* %11)
%58 = load i32*, i32** %6
%59 = call i32 @EVP_MD_CTX_destroy(i32* %58)
store i32 0, i32* %12
br label %60
60: ; preds = %71, %55
%61 = load i32, i32* %12
%62 = load i32, i32* %11
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %74
64: ; preds = %60
%65 = load i32, i32* %12
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %20, i64 %66
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %64
%72 = load i32, i32* %12
%73 = add nsw i32 %72, 1
store i32 %73, i32* %12
br label %60
74: ; preds = %60
br label %75
75: ; preds = %74
br label %76
76: ; preds = %75
store i32 0, i32* %3
store i32 1, i32* %15
br label %77
77: ; preds = %76, %31, %23
%78 = load i8*, i8** %9
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@EVP_MAX_MD_SIZE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [5 x i8] c"%02x\00"
@str = [22 x i8] c"\E6\89\93\E5\BC\80\E6\96\87\E4\BB\B6\E9\94\99\E8\AF\AF\EF\BC\81\00"
@str.4 = [16 x i8] c"\E6\97\A0\E6\96\87\E4\BB\B6\E5\90\8D\EF\BC\81\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [257 x i8]
%4 = alloca i32
%5 = tail call i32* (...) @EVP_sha256()
%6 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @EVP_MAX_MD_SIZE
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = bitcast i32* %4 to i8*
%12 = icmp slt i32 %0, 2
br i1 %12, label %46, label %13
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %46, label %18
18: ; preds = %13
%19 = tail call i32 (...) @OpenSSL_add_all_digests()
%20 = tail call i32* (...) @EVP_MD_CTX_create()
%21 = tail call i32 @EVP_DigestInit_ex(i32* %20, i32* %5, i32* null)
%22 = call i32 @feof(i32* %16)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %18, %24
%25 = call i32 @fread(i8* %6, i32 1, i32 256, i32* %16)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 @EVP_DigestUpdate(i32* %20, i8* %6, i32 %25)
%29 = call i32 @feof(i32* %16)
%30 = icmp eq i32 %29, 0
br i1 %30, label %24, label %31
31: ; preds = %24, %18
%32 = call i32 @EVP_DigestFinal_ex(i32* %20, i8* %10, i32* %4)
%33 = call i32 @EVP_MD_CTX_destroy(i32* %20)
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %49
36: ; preds = %31, %36
%37 = phi i64 [ %42, %36 ], [ 0, %31 ]
%38 = getelementptr inbounds i8, i8* %10, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = add nuw nsw i64 %37, 1
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = icmp slt i64 %42, %44
br i1 %45, label %36, label %49
46: ; preds = %13, %2
%47 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0), %2 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0), %13 ]
%48 = tail call i32 @puts(i8* dereferenceable(1) %47)
br label %49
49: ; preds = %36, %46, %31
%50 = phi i32 [ 0, %31 ], [ 1, %46 ], [ 0, %36 ]
ret i32 %50
}