#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*/ 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*/ bzero(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
char *GetMd5FromFile(char *fileName) {
  unsigned char c[MD5_DIGEST_LENGTH];
  int i;
  FILE *inFile = fopen(fileName, "rb");
  MD5_CTX mdContext;
  int bytes;
  unsigned char data[1024];
  char *md5 = malloc(33);
  bzero(md5, 33);
  if (inFile == NULL) {
    printf("%s can't be opened.\n", fileName);
    return NULL;
  }
  MD5_Init(&mdContext);
  while ((bytes = fread(data, 1, 1024, inFile)) != 0)
    MD5_Update(&mdContext, data, bytes);
  MD5_Final(c, &mdContext);
  for (i = 0; i < MD5_DIGEST_LENGTH; i++) {
    sprintf(md5 + i * 2, "%02x", c[i]);
  }
  md5[33] = 0;
  fclose(inFile);
  return md5;
}


x86 assembly (clang, -O0):
<GetMd5FromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e2a(%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,-0x458(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    $0x21,%edi
call   1070 <malloc@plt>
mov    %rax,-0x448(%rbp)
mov    -0x448(%rbp),%rdi
mov    $0x21,%esi
call   1090 <bzero@plt>
cmpq   $0x0,-0x30(%rbp)
jne    1246 <GetMd5FromFile+0xa6>
mov    -0x10(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1060 <printf@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x44c(%rbp)
jmp    131b <GetMd5FromFile+0x17b>
lea    -0x34(%rbp),%rdi
call   10a0 <MD5_Init@plt>
lea    -0x440(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
je     128d <GetMd5FromFile+0xed>
lea    -0x440(%rbp),%rsi
mov    -0x38(%rbp),%edx
lea    -0x34(%rbp),%rdi
call   10c0 <MD5_Update@plt>
jmp    124f <GetMd5FromFile+0xaf>
mov    -0x458(%rbp),%rdi
lea    -0x34(%rbp),%rsi
call   1030 <MD5_Final@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d32(%rip),%rcx
cmp    (%rcx),%eax
jge    12f2 <GetMd5FromFile+0x152>
mov    -0x458(%rbp),%rax
mov    -0x448(%rbp),%rdi
mov    -0x24(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rdi
movslq -0x24(%rbp),%rcx
lea    0xd3d(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   10b0 <sprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12a4 <GetMd5FromFile+0x104>
mov    -0x448(%rbp),%rax
movb   $0x0,0x21(%rax)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x448(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x44c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetMd5FromFile>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%r12
mov    0x2e22(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xe27(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    $0x21,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x21,%esi
call   1090 <bzero@plt>
test   %r15,%r15
je     12c4 <GetMd5FromFile+0x124>
mov    %rbx,-0x38(%rbp)
lea    -0x2c(%rbp),%rdi
call   10a0 <MD5_Init@plt>
lea    -0x440(%rbp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     1266 <GetMd5FromFile+0xc6>
lea    -0x2c(%rbp),%r12
lea    -0x440(%rbp),%rbx
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10c0 <MD5_Update@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jne    1240 <GetMd5FromFile+0xa0>
mov    %r15,-0x40(%rbp)
lea    -0x2c(%rbp),%rsi
mov    %r13,%rdi
call   1030 <MD5_Final@plt>
cmpl   $0x0,(%r14)
jle    12b1 <GetMd5FromFile+0x111>
mov    %r14,%r15
xor    %r14d,%r14d
lea    0xd8f(%rip),%r12
mov    -0x38(%rbp),%rbx
nopl   (%rax)
movzbl 0x0(%r13,%r14,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   10b0 <sprintf@plt>
add    $0x1,%r14
movslq (%r15),%rax
add    $0x2,%rbx
cmp    %rax,%r14
jl     1290 <GetMd5FromFile+0xf0>
mov    -0x38(%rbp),%rbx
movb   $0x0,0x21(%rbx)
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
jmp    12d5 <GetMd5FromFile+0x135>
lea    0xd38(%rip),%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
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 = [21 x i8] c"%s can't be opened.\0A\00"
@.str.2 = [5 x i8] c"%02x\00"
define i8* @GetMd5FromFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %3
%13 = load i32, i32* @MD5_DIGEST_LENGTH
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %4
%16 = alloca i8, i64 %14
store i64 %14, i64* %5
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %7
%19 = call i8* @malloc(i32 33)
store i8* %19, i8** %11
%20 = load i8*, i8** %11
%21 = call i32 @bzero(i8* %20, i32 33)
%22 = load i32*, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %1
%25 = load i8*, i8** %3
%26 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i8* null, i8** %2
store i32 1, i32* %12
br label %64
27: ; preds = %1
%28 = call i32 @MD5_Init(i32* %8)
br label %29
29: ; preds = %34, %27
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%31 = load i32*, i32** %7
%32 = call i32 @fread(i8* %30, i32 1, i32 1024, i32* %31)
store i32 %32, i32* %9
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%36 = load i32, i32* %9
%37 = call i32 @MD5_Update(i32* %8, i8* %35, i32 %36)
br label %29
38: ; preds = %29
%39 = call i32 @MD5_Final(i8* %16, i32* %8)
store i32 0, i32* %6
br label %40
40: ; preds = %55, %38
%41 = load i32, i32* %6
%42 = load i32, i32* @MD5_DIGEST_LENGTH
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %58
44: ; preds = %40
%45 = load i8*, i8** %11
%46 = load i32, i32* %6
%47 = mul nsw i32 %46, 2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %16, i64 %51
%53 = load i8, i8* %52
%54 = call i32 @sprintf(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %53)
br label %55
55: ; preds = %44
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %40
58: ; preds = %40
%59 = load i8*, i8** %11
%60 = getelementptr inbounds i8, i8* %59, i64 33
store i8 0, i8* %60
%61 = load i32*, i32** %7
%62 = call i32 @fclose(i32* %61)
%63 = load i8*, i8** %11
store i8* %63, i8** %2
store i32 1, i32* %12
br label %64
64: ; preds = %58, %24
%65 = load i8*, i8** %4
%66 = load i8*, i8** %2
ret i8* %66
}

LLVM IR (-O2):
@MD5_DIGEST_LENGTH = global i32 0
@.str = [3 x i8] c"rb\00"
@.str.1 = [21 x i8] c"%s can't be opened.\0A\00"
@.str.2 = [5 x i8] c"%02x\00"
define noalias i8* @GetMd5FromFile(i8* %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = load i32, i32* @MD5_DIGEST_LENGTH
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = bitcast i32* %2 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = tail call dereferenceable_or_null(33) i8* @malloc(i32 33)
%11 = tail call i32 @bzero(i8* %10, i32 33)
%12 = icmp eq i32* %7, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %42
15: ; preds = %1
%16 = call i32 @MD5_Init(i32* %2)
%17 = call i32 @fread(i8* %9, i32 1, i32 1024, i32* %7)
%18 = icmp eq i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %15, %19
%20 = phi i32 [ %22, %19 ], [ %17, %15 ]
%21 = call i32 @MD5_Update(i32* %2, i8* %9, i32 %20)
%22 = call i32 @fread(i8* %9, i32 1, i32 1024, i32* %7)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %19
24: ; preds = %19, %15
%25 = call i32 @MD5_Final(i8* %6, i32* %2)
%26 = load i32, i32* @MD5_DIGEST_LENGTH
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %24, %28
%29 = phi i64 [ %35, %28 ], [ 0, %24 ]
%30 = shl nuw nsw i64 %29, 1
%31 = getelementptr inbounds i8, i8* %10, i64 %30
%32 = getelementptr inbounds i8, i8* %6, i64 %29
%33 = load i8, i8* %32
%34 = call i32 @sprintf(i8* dereferenceable(1) %31, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %33)
%35 = add nuw nsw i64 %29, 1
%36 = load i32, i32* @MD5_DIGEST_LENGTH
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %28, label %39
39: ; preds = %28, %24
%40 = getelementptr inbounds i8, i8* %10, i64 33
store i8 0, i8* %40
%41 = call i32 @fclose(i32* %7)
br label %42
42: ; preds = %39, %13
%43 = phi i8* [ null, %13 ], [ %10, %39 ]
ret i8* %43
}