#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stderr,
            "Uso: ./md5_generator <caminho/para/arquivo>. Abortando!\n");
    exit(EXIT_FAILURE);
  }
  FILE *f;
  if ((f = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "Arquivo %s não pode ser aberto! ", argv[1]);
    perror("motivo");
    exit(EXIT_FAILURE);
  }
  MD5_CTX mContext;
  MD5_Init(&mContext);
  int bytes;
  unsigned char buf[1024];
  unsigned char digest[MD5_DIGEST_LENGTH];
  char converted[MD5_DIGEST_LENGTH];
  while ((bytes = fread(buf, 1, 1024, f)) != 0)
    MD5_Update(&mContext, buf, bytes);
  fclose(f);
  MD5_Final(digest, &mContext);
  int i;
  for (i = 0; i < MD5_DIGEST_LENGTH; i++)
    sprintf(&converted[i * 2], "%02x", digest[i]);
  printf("%s  %s\n", converted, argv[1]);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11f8 <main+0x48>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1253 <main+0xa3>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0xe1d(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x1c(%rbp),%rdi
call   10a0 <MD5_Init@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x428(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x450(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x430(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x448(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x438(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     12f3 <main+0x143>
lea    -0x420(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    -0x1c(%rbp),%rdi
call   10d0 <MD5_Update@plt>
jmp    12b5 <main+0x105>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x450(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1030 <MD5_Final@plt>
movl   $0x0,-0x43c(%rbp)
mov    -0x43c(%rbp),%eax
mov    0x2cb5(%rip),%rcx
cmp    (%rcx),%eax
jge    1373 <main+0x1c3>
mov    -0x450(%rbp),%rax
mov    -0x448(%rbp),%rdi
mov    -0x43c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rdi
movslq -0x43c(%rbp),%rcx
lea    0xd0e(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   10b0 <sprintf@plt>
mov    -0x43c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x43c(%rbp)
jmp    1316 <main+0x166>
mov    -0x448(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xce0(%rip),%rdi
call   1060 <printf@plt>
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
cmp    $0x1,%edi
jg     11e2 <main+0x32>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1221 <main+0x71>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe49(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
jne    122f <main+0x7f>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe2d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xe41(%rip),%rdi
call   1090 <perror@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    %rax,%rbx
mov    %r14,-0x40(%rbp)
lea    -0x2c(%rbp),%rdi
call   10a0 <MD5_Init@plt>
mov    0x2d92(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
lea    -0x440(%rbp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     12b6 <main+0x106>
lea    -0x2c(%rbp),%r13
lea    -0x440(%rbp),%r15
nop
mov    %r13,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   10d0 <MD5_Update@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jne    1290 <main+0xe0>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    -0x2c(%rbp),%rsi
mov    %r12,%rdi
call   1030 <MD5_Final@plt>
cmpl   $0x0,(%r14)
jle    1300 <main+0x150>
xor    %ebx,%ebx
lea    0xd8b(%rip),%r15
mov    -0x38(%rbp),%r13
nopl   (%rax)
movzbl (%r12,%rbx,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   10b0 <sprintf@plt>
add    $0x1,%rbx
movslq (%r14),%rax
add    $0x2,%r13
cmp    %rax,%rbx
jl     12e0 <main+0x130>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd5a(%rip),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <printf@plt>
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"Uso: ./md5_generator <caminho/para/arquivo>. Abortando!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"Arquivo %s n\C3\A3o pode ser aberto! \00"
@.str.3 = [7 x i8] c"motivo\00"
@MD5_DIGEST_LENGTH = global i32 0
@.str.4 = [5 x i8] c"%02x\00"
@.str.5 = [8 x i8] c"%s %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %36
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %21
%37 = call i32 @MD5_Init(i32* %7)
%38 = load i32, i32* @MD5_DIGEST_LENGTH
%39 = zext i32 %38 to i64
%40 = call i8* @llvm.stacksave()
store i8* %40, i8** %10
%41 = alloca i8, i64 %39
store i64 %39, i64* %11
%42 = load i32, i32* @MD5_DIGEST_LENGTH
%43 = zext i32 %42 to i64
%44 = alloca i8, i64 %43
store i64 %43, i64* %12
br label %45
45: ; preds = %50, %36
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%47 = load i32*, i32** %6
%48 = call i32 @fread(i8* %46, i32 1, i32 1024, i32* %47)
store i32 %48, i32* %8
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%52 = load i32, i32* %8
%53 = call i32 @MD5_Update(i32* %7, i8* %51, i32 %52)
br label %45
54: ; preds = %45
%55 = load i32*, i32** %6
%56 = call i32 @fclose(i32* %55)
%57 = call i32 @MD5_Final(i8* %41, i32* %7)
store i32 0, i32* %13
br label %58
58: ; preds = %72, %54
%59 = load i32, i32* %13
%60 = load i32, i32* @MD5_DIGEST_LENGTH
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %75
62: ; preds = %58
%63 = load i32, i32* %13
%64 = mul nsw i32 %63, 2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %44, i64 %65
%67 = load i32, i32* %13
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %41, i64 %68
%70 = load i8, i8* %69
%71 = call i32 @sprintf(i8* %66, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %70)
br label %72
72: ; preds = %62
%73 = load i32, i32* %13
%74 = add nsw i32 %73, 1
store i32 %74, i32* %13
br label %58
75: ; preds = %58
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 1
%78 = load i8*, i8** %77
%79 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %44, i8* %78)
%80 = load i32, i32* @EXIT_SUCCESS
%81 = call i32 @exit(i32 %80)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"Uso: ./md5_generator <caminho/para/arquivo>. Abortando!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"Arquivo %s n\C3\A3o pode ser aberto! \00"
@.str.3 = [7 x i8] c"motivo\00"
@MD5_DIGEST_LENGTH = global i32 0
@.str.4 = [5 x i8] c"%02x\00"
@.str.5 = [8 x i8] c"%s %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %11
%24 = bitcast i32* %3 to i8*
%25 = call i32 @MD5_Init(i32* %3)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%27 = load i32, i32* @MD5_DIGEST_LENGTH
%28 = zext i32 %27 to i64
%29 = alloca i8, i64 %28
%30 = alloca i8, i64 %28
%31 = call i32 @fread(i8* %26, i32 1, i32 1024, i32* %14)
%32 = icmp eq i32 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %23, %33
%34 = phi i32 [ %36, %33 ], [ %31, %23 ]
%35 = call i32 @MD5_Update(i32* %3, i8* %26, i32 %34)
%36 = call i32 @fread(i8* %26, i32 1, i32 1024, i32* %14)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %33
38: ; preds = %33, %23
%39 = call i32 @fclose(i32* %14)
%40 = call i32 @MD5_Final(i8* %29, i32* %3)
%41 = load i32, i32* @MD5_DIGEST_LENGTH
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %54
43: ; preds = %38, %43
%44 = phi i64 [ %50, %43 ], [ 0, %38 ]
%45 = shl nuw nsw i64 %44, 1
%46 = getelementptr inbounds i8, i8* %30, i64 %45
%47 = getelementptr inbounds i8, i8* %29, i64 %44
%48 = load i8, i8* %47
%49 = call i32 @sprintf(i8* %46, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %48)
%50 = add nuw nsw i64 %44, 1
%51 = load i32, i32* @MD5_DIGEST_LENGTH
%52 = sext i32 %51 to i64
%53 = icmp slt i64 %50, %52
br i1 %53, label %43, label %54
54: ; preds = %43, %38
%55 = load i8*, i8** %12
%56 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %30, i8* %55)
%57 = load i32, i32* @EXIT_SUCCESS
%58 = call i32 @exit(i32 %57)
unreachable
}