#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*/ SHA_CTX;
typedef int /*<<< orphan*/ MD5_CTX;

/* Variables and functions */
int /*<<< orphan*/ MD5_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Update(int /*<<< orphan*/ *, char const *, int);
int /*<<< orphan*/ SHA1_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Update(int /*<<< orphan*/ *, char const *, int);
int /*<<< orphan*/ logfile(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
void file_hash(const char *file, int opt) {
  unsigned char digest[512];
  char sum[(512 * 2) + 1];
  if (opt == 'M') {
    MD5_CTX c;
    logfile("\nMD5 Hash Sum");
    logfile("================");
    MD5_Init(&c);
    MD5_Update(&c, file, 512);
    MD5_Final(digest, &c);
  } else {
    SHA_CTX c;
    logfile("\nSHA1 Hash Sum");
    logfile("=================");
    SHA1_Init(&c);
    SHA1_Update(&c, file, 512);
    SHA1_Final(digest, &c);
  }
  for (int n = 0; n <= 16; ++n)
    snprintf(&(sum[n * 2]), 16 * 3, "%02x", (unsigned int)digest[n]);
  logfile(sum);
}


x86 assembly (clang, -O0):
<file_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x630,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x4d,-0xc(%rbp)
jne    11ed <file_hash+0x6d>
lea    0xe5d(%rip),%rdi
call   1030 <logfile@plt>
lea    0xe6f(%rip),%rdi
call   1030 <logfile@plt>
lea    -0x624(%rbp),%rdi
call   1080 <MD5_Init@plt>
mov    -0x8(%rbp),%rsi
lea    -0x624(%rbp),%rdi
mov    $0x200,%edx
call   1090 <MD5_Update@plt>
lea    -0x210(%rbp),%rdi
lea    -0x624(%rbp),%rsi
call   1040 <MD5_Final@plt>
jmp    1239 <file_hash+0xb9>
lea    0xe1a(%rip),%rdi
call   1030 <logfile@plt>
lea    0xe1d(%rip),%rdi
call   1030 <logfile@plt>
lea    -0x628(%rbp),%rdi
call   1070 <SHA1_Init@plt>
mov    -0x8(%rbp),%rsi
lea    -0x628(%rbp),%rdi
mov    $0x200,%edx
call   1060 <SHA1_Update@plt>
lea    -0x210(%rbp),%rdi
lea    -0x628(%rbp),%rsi
call   10a0 <SHA1_Final@plt>
movl   $0x0,-0x62c(%rbp)
cmpl   $0x10,-0x62c(%rbp)
jg     1299 <file_hash+0x119>
mov    -0x62c(%rbp),%eax
shl    $0x1,%eax
cltq
lea    -0x620(%rbp),%rdi
add    %rax,%rdi
movslq -0x62c(%rbp),%rax
movzbl -0x210(%rbp,%rax,1),%ecx
ff
mov    $0x30,%esi
lea    0xdaf(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x62c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x62c(%rbp)
jmp    1243 <file_hash+0xc3>
lea    -0x620(%rbp),%rdi
call   1030 <logfile@plt>
add    $0x630,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_hash>:
push   %r14
push   %rbx
sub    $0x608,%rsp
mov    %rdi,%rbx
cmp    $0x4d,%esi
jne    11d7 <file_hash+0x57>
lea    0xe67(%rip),%rdi
call   1030 <logfile@plt>
lea    0xe79(%rip),%rdi
call   1030 <logfile@plt>
lea    0x200(%rsp),%r14
mov    %r14,%rdi
call   1080 <MD5_Init@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1090 <MD5_Update@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1040 <MD5_Final@plt>
jmp    121a <file_hash+0x9a>
lea    0xe30(%rip),%rdi
call   1030 <logfile@plt>
lea    0xe33(%rip),%rdi
call   1030 <logfile@plt>
lea    0x200(%rsp),%r14
mov    %r14,%rdi
call   1070 <SHA1_Init@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1060 <SHA1_Update@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
call   10a0 <SHA1_Final@plt>
movzbl (%rsp),%ecx
lea    0xe0a(%rip),%rbx
lea    0x200(%rsp),%r14
mov    %r14,%rdi
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x202(%rsp),%rdi
movzbl 0x1(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x204(%rsp),%rdi
movzbl 0x2(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x206(%rsp),%rdi
movzbl 0x3(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x208(%rsp),%rdi
movzbl 0x4(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x20a(%rsp),%rdi
movzbl 0x5(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x20c(%rsp),%rdi
movzbl 0x6(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x20e(%rsp),%rdi
movzbl 0x7(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x210(%rsp),%rdi
movzbl 0x8(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x212(%rsp),%rdi
movzbl 0x9(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x214(%rsp),%rdi
movzbl 0xa(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x216(%rsp),%rdi
movzbl 0xb(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x218(%rsp),%rdi
movzbl 0xc(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x21a(%rsp),%rdi
movzbl 0xd(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x21c(%rsp),%rdi
movzbl 0xe(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x21e(%rsp),%rdi
movzbl 0xf(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
lea    0x220(%rsp),%rdi
movzbl 0x10(%rsp),%ecx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1030 <logfile@plt>
add    $0x608,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"\0AMD5 Hash Sum\00"
@.str.1 = [17 x i8] c"================\00"
@.str.2 = [15 x i8] c"\0ASHA1 Hash Sum\00"
@.str.3 = [18 x i8] c"=================\00"
@.str.4 = [5 x i8] c"%02x\00"
define void @file_hash(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca [1025 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 77
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = call i32 @logfile(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @logfile(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @MD5_Init(i32* %7)
%16 = load i8*, i8** %3
%17 = call i32 @MD5_Update(i32* %7, i8* %16, i32 512)
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%19 = call i32 @MD5_Final(i8* %18, i32* %7)
br label %28
20: ; preds = %2
%21 = call i32 @logfile(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @logfile(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @SHA1_Init(i32* %8)
%24 = load i8*, i8** %3
%25 = call i32 @SHA1_Update(i32* %8, i8* %24, i32 512)
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%27 = call i32 @SHA1_Final(i8* %26, i32* %8)
br label %28
28: ; preds = %20, %12
store i32 0, i32* %9
br label %29
29: ; preds = %43, %28
%30 = load i32, i32* %9
%31 = icmp sle i32 %30, 16
br i1 %31, label %32, label %46
32: ; preds = %29
%33 = load i32, i32* %9
%34 = mul nsw i32 %33, 2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 %35
%37 = load i32, i32* %9
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = call i32 @snprintf(i8* %36, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %32
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %29
46: ; preds = %29
%47 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%48 = call i32 @logfile(i8* %47)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"\0AMD5 Hash Sum\00"
@.str.1 = [17 x i8] c"================\00"
@.str.2 = [15 x i8] c"\0ASHA1 Hash Sum\00"
@.str.3 = [18 x i8] c"=================\00"
@.str.4 = [5 x i8] c"%02x\00"
define void @file_hash(i8* %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = alloca [1025 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 0
%9 = icmp eq i32 %1, 77
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = bitcast i32* %5 to i8*
%12 = tail call i32 @logfile(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @logfile(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @MD5_Init(i32* %5)
%15 = call i32 @MD5_Update(i32* %5, i8* %0, i32 512)
%16 = call i32 @MD5_Final(i8* %7, i32* %5)
br label %24
17: ; preds = %2
%18 = bitcast i32* %6 to i8*
%19 = tail call i32 @logfile(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @logfile(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @SHA1_Init(i32* %6)
%22 = call i32 @SHA1_Update(i32* %6, i8* %0, i32 512)
%23 = call i32 @SHA1_Final(i8* %7, i32* %6)
br label %24
24: ; preds = %17, %10
%25 = load i8, i8* %7
%26 = zext i8 %25 to i32
%27 = call i32 @snprintf(i8* %8, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 2
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 1
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 @snprintf(i8* %28, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 4
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 2
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = call i32 @snprintf(i8* %33, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 6
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 3
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = call i32 @snprintf(i8* %38, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 8
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 4
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = call i32 @snprintf(i8* %43, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 10
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 5
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = call i32 @snprintf(i8* %48, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 12
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 6
%55 = load i8, i8* %54
%56 = zext i8 %55 to i32
%57 = call i32 @snprintf(i8* %53, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 14
%59 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 7
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = call i32 @snprintf(i8* %58, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%63 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 16
%64 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 8
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = call i32 @snprintf(i8* %63, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %66)
%68 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 18
%69 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 9
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = call i32 @snprintf(i8* %68, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %71)
%73 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 20
%74 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 10
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = call i32 @snprintf(i8* %73, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %76)
%78 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 22
%79 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 11
%80 = load i8, i8* %79
%81 = zext i8 %80 to i32
%82 = call i32 @snprintf(i8* %78, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %81)
%83 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 24
%84 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 12
%85 = load i8, i8* %84
%86 = zext i8 %85 to i32
%87 = call i32 @snprintf(i8* %83, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %86)
%88 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 26
%89 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 13
%90 = load i8, i8* %89
%91 = zext i8 %90 to i32
%92 = call i32 @snprintf(i8* %88, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %91)
%93 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 28
%94 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 14
%95 = load i8, i8* %94
%96 = zext i8 %95 to i32
%97 = call i32 @snprintf(i8* %93, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %96)
%98 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 30
%99 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 15
%100 = load i8, i8* %99
%101 = zext i8 %100 to i32
%102 = call i32 @snprintf(i8* %98, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %101)
%103 = getelementptr inbounds [1025 x i8], [1025 x i8]* %4, i64 0, i64 32
%104 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 16
%105 = load i8, i8* %104
%106 = zext i8 %105 to i32
%107 = call i32 @snprintf(i8* %103, i32 48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %106)
%108 = call i32 @logfile(i8* %8)
ret void
}