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

/* Variables and functions */
int /*<<< orphan*/ calc_sha_256(int *, int const *, size_t);
int /*<<< orphan*/ hash_to_string(char *, int *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char const *, char *);
int test(const uint8_t *input, size_t input_len, const char output[]) {
  uint8_t hash[32];
  char hash_string[65];
  calc_sha_256(hash, input, input_len);
  hash_to_string(hash_string, hash);
  printf("input starts with 0x%02x, length %lu\n", *input,
         (unsigned long)input_len);
  printf("hash : %s\n", hash_string);
  if (strcmp(output, hash_string)) {
    printf("FAILURE!\n\n");
    return 1;
  } else {
    printf("SUCCESS!\n\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <calc_sha_256@plt>
lea    -0xf0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1050 <hash_to_string@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rdx
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xf0(%rbp),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11df <test+0x9f>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <test+0xb4>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd0,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x50(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <calc_sha_256@plt>
mov    %rsp,%r13
mov    %r13,%rdi
mov    %r12,%rsi
call   1060 <hash_to_string@plt>
mov    (%rbx),%esi
lea    0xe6d(%rip),%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe82(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
lea    0xe69(%rip),%rax
lea    0xe6c(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0xd0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"input starts with 0x%02x, length %lu\0A\00"
@.str.1 = [11 x i8] c"hash : %s\0A\00"
@.str.2 = [11 x i8] c"FAILURE!\0A\0A\00"
@.str.3 = [11 x i8] c"SUCCESS!\0A\0A\00"
define i32 @test(i32* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca [32 x i32]
%9 = alloca [65 x i8]
store i32* %0, i32** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%10 = getelementptr inbounds [32 x i32], [32 x i32]* %8, i64 0, i64 0
%11 = load i32*, i32** %5
%12 = load i64, i64* %6
%13 = call i32 @calc_sha_256(i32* %10, i32* %11, i64 %12)
%14 = getelementptr inbounds [65 x i8], [65 x i8]* %9, i64 0, i64 0
%15 = getelementptr inbounds [32 x i32], [32 x i32]* %8, i64 0, i64 0
%16 = call i32 @hash_to_string(i8* %14, i32* %15)
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = load i64, i64* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %18, i64 %19)
%21 = getelementptr inbounds [65 x i8], [65 x i8]* %9, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %7
%24 = getelementptr inbounds [65 x i8], [65 x i8]* %9, i64 0, i64 0
%25 = call i64 @strcmp(i8* %23, i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %4
br label %31
29: ; preds = %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %31
31: ; preds = %29, %27
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@.str = [38 x i8] c"input starts with 0x%02x, length %lu\0A\00"
@.str.1 = [11 x i8] c"hash : %s\0A\00"
@str = [10 x i8] c"SUCCESS!\0A\00"
@str.4 = [10 x i8] c"FAILURE!\0A\00"
define i32 @test(i32* %0, i64 %1, i8* %2) {
%4 = alloca [32 x i32]
%5 = alloca [65 x i8]
%6 = bitcast [32 x i32]* %4 to i8*
%7 = getelementptr inbounds [65 x i8], [65 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [32 x i32], [32 x i32]* %4, i64 0, i64 0
%9 = call i32 @calc_sha_256(i32* %8, i32* %0, i64 %1)
%10 = call i32 @hash_to_string(i8* %7, i32* %8)
%11 = load i32, i32* %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %11, i64 %1)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%14 = call i64 @strcmp(i8* %2, i8* %7)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0)
%17 = xor i1 %15, true
%18 = zext i1 %17 to i32
%19 = call i32 @puts(i8* dereferenceable(1) %16)
ret i32 %18
}