#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*/ outmd;
typedef int /*<<< orphan*/ out;
typedef int /*<<< orphan*/ filen;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ MD5_CTX;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int MD5_DIGEST_LENGTH;
int /*<<< orphan*/ MD5_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Update(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ *fopen(unsigned char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(unsigned char *, char *, unsigned char);
int /*<<< orphan*/ strcat(unsigned char *, unsigned char *);
int getfilemd5(unsigned char *filename) {
  MD5_CTX ctx;
  unsigned char outmd[MD5_DIGEST_LENGTH];
  unsigned char out[1024];
  unsigned char buffer[1024];
  unsigned char filen[32];
  int len = 0;
  int i;
  FILE *fp = NULL;
  memset(outmd, 0, sizeof(outmd));
  memset(filen, 0, sizeof(filen));
  memset(buffer, 0, sizeof(buffer));
  memset(out, 0, sizeof(out));
  strcat(filen, filename);
  fp = fopen(filen, "rb");
  if (fp == NULL) {
    printf("Can't open file\n");
    getchar();
    return 0;
  }
  MD5_Init(&ctx);
  while ((len = fread(buffer, 1, 1024, fp)) > 0) {
    MD5_Update(&ctx, buffer, len);
    memset(buffer, 0, sizeof(buffer));
  }
  MD5_Final(outmd, &ctx);
  for (i = 0; i < MD5_DIGEST_LENGTH; i < i++) {
    sprintf(buffer, "%02X", outmd[i]);
    strcat(out, buffer);
  }
  printf("%s\n", out);
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<getfilemd5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x870(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x854(%rbp)
movq   $0x0,-0x860(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    -0x850(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x850(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x850(%rbp),%rdi
lea    0xdad(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x860(%rbp)
cmpq   $0x0,-0x860(%rbp)
jne    1298 <getfilemd5+0xf8>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x864(%rbp)
jmp    13a3 <getfilemd5+0x203>
lea    -0x14(%rbp),%rdi
call   10a0 <MD5_Init@plt>
lea    -0x830(%rbp),%rdi
mov    -0x860(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x854(%rbp)
cmp    $0x0,%eax
jle    12fb <getfilemd5+0x15b>
lea    -0x830(%rbp),%rsi
mov    -0x854(%rbp),%edx
lea    -0x14(%rbp),%rdi
call   10c0 <MD5_Update@plt>
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
jmp    12a1 <getfilemd5+0x101>
mov    -0x870(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <MD5_Final@plt>
movl   $0x0,-0x858(%rbp)
mov    -0x858(%rbp),%eax
mov    0x2cbe(%rip),%rcx
cmp    (%rcx),%eax
jge    1376 <getfilemd5+0x1d6>
mov    -0x870(%rbp),%rax
lea    -0x830(%rbp),%rdi
movslq -0x858(%rbp),%rcx
lea    0xcce(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   10b0 <sprintf@plt>
lea    -0x430(%rbp),%rdi
lea    -0x830(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x858(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x858(%rbp)
jmp    1315 <getfilemd5+0x175>
lea    -0x430(%rbp),%rsi
lea    0xc95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x864(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfilemd5>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    %rdi,%r15
mov    %rsp,%r13
mov    0x2e1f(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    -0x60(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
lea    -0x460(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x860(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
lea    0xdd4(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1330 <getfilemd5+0x190>
mov    %rax,%r12
mov    %r13,-0x38(%rbp)
lea    -0x2c(%rbp),%rdi
call   10a0 <MD5_Init@plt>
lea    -0x460(%rbp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jle    12b5 <getfilemd5+0x115>
lea    -0x2c(%rbp),%r15
lea    -0x460(%rbp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10c0 <MD5_Update@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jg     1280 <getfilemd5+0xe0>
lea    -0x2c(%rbp),%rsi
mov    %r14,%rdi
call   1040 <MD5_Final@plt>
mov    0x2d18(%rip),%rax
cmpl   $0x0,(%rax)
jle    131e <getfilemd5+0x17e>
xor    %r13d,%r13d
lea    0xd2c(%rip),%r15
lea    -0x460(%rbp),%rbx
lea    -0x860(%rbp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r14,%r13,1),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <sprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
add    $0x1,%r13
mov    0x2cca(%rip),%rax
movslq (%rax),%rax
cmp    %rax,%r13
jl     12f0 <getfilemd5+0x150>
lea    -0x860(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x38(%rbp),%r13
jmp    133c <getfilemd5+0x19c>
lea    0xcd1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %r13,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MD5_DIGEST_LENGTH = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [17 x i8] c"Can't open file\0A\00"
@.str.2 = [5 x i8] c"%02X\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @getfilemd5(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca [32 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
store i8* %0, i8** %3
%14 = load i32, i32* @MD5_DIGEST_LENGTH
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %5
%17 = alloca i8, i64 %15
store i64 %15, i64* %6
store i32 0, i32* %10
store i32* null, i32** %12
%18 = trunc i64 %15 to i32
%19 = call i32 @memset(i8* %17, i32 0, i32 %18)
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%21 = call i32 @memset(i8* %20, i32 0, i32 32)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 1024)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 1024)
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%27 = load i8*, i8** %3
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %30, i32** %12
%31 = load i32*, i32** %12
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %1
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 (...) @getchar()
store i32 0, i32* %2
store i32 1, i32* %13
br label %75
36: ; preds = %1
%37 = call i32 @MD5_Init(i32* %4)
br label %38
38: ; preds = %43, %36
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%40 = load i32*, i32** %12
%41 = call i32 @fread(i8* %39, i32 1, i32 1024, i32* %40)
store i32 %41, i32* %10
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%45 = load i32, i32* %10
%46 = call i32 @MD5_Update(i32* %4, i8* %44, i32 %45)
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%48 = call i32 @memset(i8* %47, i32 0, i32 1024)
br label %38
49: ; preds = %38
%50 = call i32 @MD5_Final(i8* %17, i32* %4)
store i32 0, i32* %11
br label %51
51: ; preds = %65, %49
%52 = load i32, i32* %11
%53 = load i32, i32* @MD5_DIGEST_LENGTH
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %71
55: ; preds = %51
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %17, i64 %58
%60 = load i8, i8* %59
%61 = call i32 @sprintf(i8* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %60)
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%64 = call i32 @strcat(i8* %62, i8* %63)
br label %65
65: ; preds = %55
%66 = load i32, i32* %11
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
%69 = icmp slt i32 %66, %67
%70 = zext i1 %69 to i32
br label %51
71: ; preds = %51
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %72)
%74 = call i32 (...) @getchar()
store i32 0, i32* %2
store i32 1, i32* %13
br label %75
75: ; preds = %71, %33
%76 = load i8*, i8** %5
%77 = load i32, i32* %2
ret i32 %77
}

LLVM IR (-O2):
@MD5_DIGEST_LENGTH = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.2 = [5 x i8] c"%02X\00"
@str = [16 x i8] c"Can't open file\00"
define i32 @getfilemd5(i8* %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [32 x i8]
%6 = bitcast i32* %2 to i8*
%7 = load i32, i32* @MD5_DIGEST_LENGTH
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%14 = call i32 @memset(i8* %10, i32 0, i32 %7)
%15 = call i32 @memset(i8* %13, i32 0, i32 32)
%16 = call i32 @memset(i8* %12, i32 0, i32 1024)
%17 = call i32 @memset(i8* %11, i32 0, i32 1024)
%18 = call i32 @strcat(i8* %13, i8* %0)
%19 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %49
23: ; preds = %1
%24 = call i32 @MD5_Init(i32* %2)
%25 = call i32 @fread(i8* %12, i32 1, i32 1024, i32* %19)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %23, %27
%28 = phi i32 [ %31, %27 ], [ %25, %23 ]
%29 = call i32 @MD5_Update(i32* %2, i8* %12, i32 %28)
%30 = call i32 @memset(i8* %12, i32 0, i32 1024)
%31 = call i32 @fread(i8* %12, i32 1, i32 1024, i32* %19)
%32 = icmp sgt i32 %31, 0
br i1 %32, label %27, label %33
33: ; preds = %27, %23
%34 = call i32 @MD5_Final(i8* %10, i32* %2)
%35 = load i32, i32* @MD5_DIGEST_LENGTH
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %33, %37
%38 = phi i64 [ %43, %37 ], [ 0, %33 ]
%39 = getelementptr inbounds i8, i8* %10, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %40)
%42 = call i32 @strcat(i8* %11, i8* %12)
%43 = add nuw nsw i64 %38, 1
%44 = load i32, i32* @MD5_DIGEST_LENGTH
%45 = sext i32 %44 to i64
%46 = icmp slt i64 %43, %45
br i1 %46, label %37, label %47
47: ; preds = %37, %33
%48 = call i32 @puts(i8* %11)
br label %49
49: ; preds = %47, %21
%50 = call i32 (...) @getchar()
ret i32 0
}