#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;

/* Variables and functions */
unsigned char *check_sha256_sum(char *, unsigned char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, short);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ memcmp(unsigned char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove(char *);
int main(void) {
  short i;
  unsigned char *ascii = NULL;
  FILE *fp = NULL;
  char *filename = "test_sha256.dat";
  char *assumed =
      "40aff2e9d2d8922e47afd4648e6967497158785fbd1da870e7110266bf944880";
  printf("Running test for SHA256:\n\n");
  fp = fopen(filename, "wb");
  if (!fp) {
    printf("Cannot write test file!\n");
    return 1;
  }
  for (i = 0x00; i <= 0xFF; i++) {
    fprintf(fp, "%c", i);
  }
  fclose(fp);
  printf("Checking file %s ... ", filename);
  ascii = check_sha256_sum(filename, (unsigned char *)assumed);
  if (ascii == NULL) {
    printf("CORRECT!\n\n");
  } else {
    if (memcmp(ascii, assumed, 64) == 0) {
      printf("Memory Error!\n\n");
    } else {
      printf("FALSE!\n");
      printf("%-12s%s\n%-12s%s\n\n", "Calculated:", ascii, "Assumed:", assumed);
      free(ascii);
    }
  }
  remove(filename);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe5a(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe5f(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fc <main+0x7c>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ff <main+0x17f>
movw   $0x0,-0x6(%rbp)
movswl -0x6(%rbp),%eax
cmp    $0xff,%eax
jg     1236 <main+0xb6>
mov    -0x18(%rbp),%rdi
lea    0xe6c(%rip),%rsi
movswl -0x6(%rbp),%edx
call   1090 <fprintf@plt>
mov    -0x6(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x6(%rbp)
jmp    1202 <main+0x82>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <check_sha256_sum@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1280 <main+0x100>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12ef <main+0x16f>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x40,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
jne    12af <main+0x12f>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12ea <main+0x16a>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%r8
lea    0xdf8(%rip),%rdi
lea    0xe03(%rip),%rsi
lea    0xe08(%rip),%rcx
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    12ef <main+0x16f>
mov    -0x20(%rbp),%rdi
call   1040 <remove@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xef7(%rip),%rdi
call   1050 <puts@plt>
lea    0xe5a(%rip),%rdi
lea    0xea4(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1261 <main+0xd1>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <fputc@plt>
add    $0x1,%ebp
cmp    $0x100,%ebp
jne    11c0 <main+0x30>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xe70(%rip),%rdi
lea    0xe15(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe14(%rip),%rsi
mov    %rbx,%rdi
call   1080 <check_sha256_sum@plt>
test   %rax,%rax
je     1274 <main+0xe4>
mov    %rax,%rbx
lea    0xdfd(%rip),%rsi
mov    %rax,%rdi
mov    $0x40,%edx
call   10a0 <memcmp@plt>
test   %rax,%rax
je     127d <main+0xed>
lea    0xe97(%rip),%rdi
call   1050 <puts@plt>
lea    0xe32(%rip),%rdi
lea    0xe3d(%rip),%rsi
lea    0xe42(%rip),%rcx
lea    0xdc3(%rip),%r8
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1289 <main+0xf9>
lea    0xe43(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
jmp    1297 <main+0x107>
lea    0xe5e(%rip),%rdi
jmp    1284 <main+0xf4>
lea    0xe46(%rip),%rdi
call   1050 <puts@plt>
lea    0xd70(%rip),%rdi
call   1040 <remove@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"test_sha256.dat\00"
@.str.1 = [65 x i8] c"40aff2e9d2d8922e47afd4648e6967497158785fbd1da870e7110266bf944880\00"
@.str.2 = [27 x i8] c"Running test for SHA256:\0A\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [25 x i8] c"Cannot write test file!\0A\00"
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [22 x i8] c"Checking file %s ... \00"
@.str.7 = [11 x i8] c"CORRECT!\0A\0A\00"
@.str.8 = [16 x i8] c"Memory Error!\0A\0A\00"
@.str.9 = [8 x i8] c"FALSE!\0A\00"
@.str.10 = [18 x i8] c"%-12s%s\0A%-12s%s\0A\0A\00"
@.str.11 = [12 x i8] c"Calculated:\00"
@.str.12 = [9 x i8] c"Assumed:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
store i32 0, i32* %1
store i8* null, i8** %3
store i32* null, i32** %4
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%8 = load i8*, i8** %5
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %56
14: ; preds = %0
store i16 0, i16* %2
br label %15
15: ; preds = %23, %14
%16 = load i16, i16* %2
%17 = sext i16 %16 to i32
%18 = icmp sle i32 %17, 255
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i32*, i32** %4
%21 = load i16, i16* %2
%22 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i16 signext %21)
br label %23
23: ; preds = %19
%24 = load i16, i16* %2
%25 = add i16 %24, 1
store i16 %25, i16* %2
br label %15
26: ; preds = %15
%27 = load i32*, i32** %4
%28 = call i32 @fclose(i32* %27)
%29 = load i8*, i8** %5
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %29)
%31 = load i8*, i8** %5
%32 = load i8*, i8** %6
%33 = call i8* @check_sha256_sum(i8* %31, i8* %32)
store i8* %33, i8** %3
%34 = load i8*, i8** %3
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %38
36: ; preds = %26
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %53
38: ; preds = %26
%39 = load i8*, i8** %3
%40 = load i8*, i8** %6
%41 = call i64 @memcmp(i8* %39, i8* %40, i32 64)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %52
45: ; preds = %38
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
%47 = load i8*, i8** %3
%48 = load i8*, i8** %6
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %48)
%50 = load i8*, i8** %3
%51 = call i32 @free(i8* %50)
br label %52
52: ; preds = %45, %43
br label %53
53: ; preds = %52, %36
%54 = load i8*, i8** %5
%55 = call i32 @remove(i8* %54)
store i32 0, i32* %1
br label %56
56: ; preds = %53, %12
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [16 x i8] c"test_sha256.dat\00"
@.str.1 = [65 x i8] c"40aff2e9d2d8922e47afd4648e6967497158785fbd1da870e7110266bf944880\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.6 = [22 x i8] c"Checking file %s ... \00"
@.str.10 = [18 x i8] c"%-12s%s\0A%-12s%s\0A\0A\00"
@.str.11 = [12 x i8] c"Calculated:\00"
@.str.12 = [9 x i8] c"Assumed:\00"
@str = [26 x i8] c"Running test for SHA256:\0A\00"
@str.13 = [24 x i8] c"Cannot write test file!\00"
@str.14 = [7 x i8] c"FALSE!\00"
@str.15 = [15 x i8] c"Memory Error!\0A\00"
@str.16 = [10 x i8] c"CORRECT!\0A\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.13, i64 0, i64 0))
br label %29
6: ; preds = %0, %6
%7 = phi i32 [ %9, %6 ], [ 0, %0 ]
%8 = tail call i32 @fputc(i32 %7, i32* %2)
%9 = add nuw nsw i32 %7, 1
%10 = icmp eq i32 %9, 256
br i1 %10, label %11, label %6
11: ; preds = %6
%12 = tail call i32 @fclose(i32* %2)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%14 = tail call i8* @check_sha256_sum(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.16, i64 0, i64 0))
br label %27
18: ; preds = %11
%19 = tail call i64 @memcmp(i8* %14, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i32 64)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.15, i64 0, i64 0))
br label %27
23: ; preds = %18
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.14, i64 0, i64 0))
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 @free(i8* %14)
br label %27
27: ; preds = %21, %23, %16
%28 = tail call i32 @remove(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %4
%30 = phi i32 [ 0, %27 ], [ 1, %4 ]
ret i32 %30
}