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

/* Variables and functions */
int /*<<< orphan*/ calc_sha_256(int /*<<< orphan*/ *, char const *,
                                int /*<<< orphan*/);
int /*<<< orphan*/ hash_to_string(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ strlen(char const *);
int string_test(const char input[], const char output[]) {
  uint8_t hash[32];
  char hash_string[65];
  calc_sha_256(hash, input, strlen(input));
  hash_to_string(hash_string, hash);
  printf("input: %s\n", input);
  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):
<string_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x100(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x100(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
mov    %eax,%edx
call   1040 <calc_sha_256@plt>
lea    -0xf0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1060 <hash_to_string@plt>
mov    -0x10(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xf0(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1208 <string_test+0xb8>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    121d <string_test+0xcd>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_test>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x50(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <calc_sha_256@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <hash_to_string@plt>
lea    0xe60(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
lea    0xe41(%rip),%rax
lea    0xe44(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"input: %s\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 @string_test(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [32 x i32]
%7 = alloca [65 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [32 x i32], [32 x i32]* %6, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @calc_sha_256(i32* %8, i8* %9, i32 %11)
%13 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [32 x i32], [32 x i32]* %6, i64 0, i64 0
%15 = call i32 @hash_to_string(i8* %13, i32* %14)
%16 = load i8*, i8** %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %5
%21 = getelementptr inbounds [65 x i8], [65 x i8]* %7, i64 0, i64 0
%22 = call i64 @strcmp(i8* %20, i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %28
26: ; preds = %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %28
28: ; preds = %26, %24
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [11 x i8] c"input: %s\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 @string_test(i8* %0, i8* %1) {
%3 = alloca [32 x i32]
%4 = alloca [65 x i8]
%5 = bitcast [32 x i32]* %3 to i8*
%6 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%8 = tail call i32 @strlen(i8* %0)
%9 = call i32 @calc_sha_256(i32* %7, i8* %0, i32 %8)
%10 = call i32 @hash_to_string(i8* %6, i32* %7)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%13 = call i64 @strcmp(i8* %1, i8* %6)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, 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)
%16 = xor i1 %14, true
%17 = zext i1 %16 to i32
%18 = call i32 @puts(i8* dereferenceable(1) %15)
ret i32 %17
}