#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 */

/* Variables and functions */
int compare_results(unsigned char *, char *, unsigned long long);
int /*<<< orphan*/ printf(char *);
unsigned long long strlen(char *);
int test_known_answer(char *input, char *output,
                      int (*SHA256_fp)(unsigned char *, unsigned char *,
                                       long long unsigned int)) {
  unsigned char result[32];
  SHA256_fp(input, result, strlen(input));
  int match = compare_results(result, output, strlen(output));
  if (match) {
    return 1;
  } else {
    printf("result didn't match");
    return 0;
  }
}


x86 assembly (clang, -O0):
<test_known_answer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %rax,%rdx
mov    -0x60(%rbp),%rax
call   *%rax
lea    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %rax,%rdx
call   1050 <compare_results@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     11b8 <test_known_answer+0x88>
movl   $0x1,-0x4(%rbp)
jmp    11cb <test_known_answer+0x9b>
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_known_answer>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rsp,%r12
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   *%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1050 <compare_results@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    1187 <test_known_answer+0x57>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"result didn't match\00"
define i32 @test_known_answer(i8* %0, i8* %1, i32 (i8*, i8*, i64)* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32 (i8*, i8*, i64)*
%8 = alloca [32 x i8]
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 (i8*, i8*, i64)* %2, i32 (i8*, i8*, i64)** %7
%10 = load i32 (i8*, i8*, i64)*, i32 (i8*, i8*, i64)** %7
%11 = load i8*, i8** %5
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
%15 = call i32 %10(i8* %11, i8* %12, i64 %14)
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = load i8*, i8** %6
%19 = call i64 @strlen(i8* %18)
%20 = call i32 @compare_results(i8* %16, i8* %17, i64 %19)
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %3
store i32 1, i32* %4
br label %26
24: ; preds = %3
%25 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %26
26: ; preds = %24, %23
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@.str = [20 x i8] c"result didn't match\00"
define i32 @test_known_answer(i8* %0, i8* %1, i32 (i8*, i8*, i64)* nocapture %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = call i32 %2(i8* %0, i8* %5, i64 %6)
%8 = call i64 @strlen(i8* dereferenceable(1) %1)
%9 = call i32 @compare_results(i8* %5, i8* %1, i64 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %3, %11
%14 = phi i32 [ 0, %11 ], [ 1, %3 ]
ret i32 %14
}