#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 EVP_MAX_MD_SIZE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ hash_file(char *, unsigned char *, unsigned int *);
int /*<<< orphan*/ print_hash(unsigned char *, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  unsigned char hash_buffer[EVP_MAX_MD_SIZE];
  unsigned int hash_length;
  if (!argv[1]) {
    printf("Usage: mdtest digestname filename\n");
    exit(1);
  }
  if (hash_file(argv[1], hash_buffer, &hash_length) == 0) {
    print_hash(hash_buffer, &hash_length);
  } else {
    printf("There was an error hashing your file (%s)\n", strerror(errno));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11b9 <main+0x69>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x24(%rbp),%rdx
call   1050 <hash_file@plt>
cmp    $0x0,%rax
jne    11ea <main+0x9a>
mov    -0x30(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <print_hash@plt>
jmp    1209 <main+0xb9>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%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   %rbx
push   %rax
mov    0x2e7b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     11d0 <main+0x70>
lea    -0xc(%rbp),%rdx
mov    %rbx,%rsi
call   1060 <hash_file@plt>
test   %rax,%rax
je     11bb <main+0x5b>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe51(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c7 <main+0x67>
lea    -0xc(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <print_hash@plt>
xor    %eax,%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EVP_MAX_MD_SIZE = global i32 0
@.str = [35 x i8] c"Usage: mdtest digestname filename\0A\00"
@.str.1 = [43 x i8] c"There was an error hashing your file (%s)\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @EVP_MAX_MD_SIZE
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @hash_file(i8* %23, i8* %12, i32* %8)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @print_hash(i8* %12, i32* %8)
br label %32
28: ; preds = %20
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %28, %26
store i32 0, i32* %3
%33 = load i8*, i8** %6
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@EVP_MAX_MD_SIZE = global i32 0
@.str.1 = [43 x i8] c"There was an error hashing your file (%s)\0A\00"
@errno = global i32 0
@str = [34 x i8] c"Usage: mdtest digestname filename\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = load i32, i32* @EVP_MAX_MD_SIZE
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i64 @hash_file(i8* %9, i8* %6, i32* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @print_hash(i8* %6, i32* %3)
br label %23
19: ; preds = %14
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19, %17
ret i32 0
}