#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*/ FILE;

/* Variables and functions */
int calc_md5sum(void *, unsigned char *, unsigned int);
int /*<<< orphan*/ close_file(void *);
int /*<<< orphan*/ digest_to_string(unsigned char *, char *);
int errno;
int /*<<< orphan*/ errx(int, char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void *open_file(char const *, unsigned int);
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strerror(int);
int strlen(char const *);
int md5sum_file(const char *pszFilename, unsigned fText, unsigned fQuiet,
                unsigned fProgress, FILE *pOutput) {
  int rc;
  void *pvFile;
  pvFile = open_file(pszFilename, fText);
  if (pvFile) {
    unsigned char Digest[16];
    if (fProgress && pOutput)
      fprintf(stdout, "%s: ", pszFilename);
    rc = calc_md5sum(pvFile, Digest, fProgress);
    close_file(pvFile);
    if (fProgress && pOutput) {
      size_t cch = strlen(pszFilename) + 2;
      while (cch-- > 0)
        fputc('\b', stdout);
    }
    if (!rc) {
      char szDigest[36];
      digest_to_string(Digest, szDigest);
      if (pOutput) {
        fprintf(pOutput, "%s %s%s\n", szDigest, fText ? "" : "*", pszFilename);
        fflush(pOutput);
      }
      fprintf(stdout, "%s %s%s\n", szDigest, fText ? "" : "*", pszFilename);
      fflush(stdout);
    } else {
      if (!fQuiet)
        errx(1, "Failed to open '%s': %s", pszFilename, strerror(rc));
      rc = 1;
    }
  } else {
    if (!fQuiet)
      errx(1, "Failed to open '%s': %s", pszFilename, strerror(errno));
    rc = 1;
  }
  return rc;
}


x86 assembly (clang, -O0):
<md5sum_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <open_file@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1368 <md5sum_file+0x1c8>
cmpl   $0x0,-0x14(%rbp)
je     1208 <md5sum_file+0x68>
cmpq   $0x0,-0x20(%rbp)
je     1208 <md5sum_file+0x68>
mov    0x2de5(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   10a0 <calc_md5sum@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <close_file@plt>
cmpl   $0x0,-0x14(%rbp)
je     1282 <md5sum_file+0xe2>
cmpq   $0x0,-0x20(%rbp)
je     1282 <md5sum_file+0xe2>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
cltq
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x48(%rbp)
cmp    $0x0,%rax
jbe    127d <md5sum_file+0xdd>
mov    0x2d6d(%rip),%rax
mov    (%rax),%rsi
mov    $0x8,%edi
call   1070 <fputc@plt>
jmp    124b <md5sum_file+0xab>
jmp    1282 <md5sum_file+0xe2>
cmpl   $0x0,-0x24(%rbp)
jne    132b <md5sum_file+0x18b>
lea    -0x40(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   10c0 <digest_to_string@plt>
cmpq   $0x0,-0x20(%rbp)
je     12df <md5sum_file+0x13f>
mov    -0x20(%rbp),%rdi
lea    -0x70(%rbp),%rdx
mov    -0xc(%rbp),%esi
lea    0xd58(%rip),%rcx
lea    0xd50(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
mov    -0x8(%rbp),%r8
lea    0xd36(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <fflush@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%rdi
lea    -0x70(%rbp),%rdx
mov    -0xc(%rbp),%esi
lea    0xd17(%rip),%rcx
lea    0xd0f(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
mov    -0x8(%rbp),%r8
lea    0xcf5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cba(%rip),%rax
mov    (%rax),%rdi
call   1090 <fflush@plt>
jmp    1363 <md5sum_file+0x1c3>
cmpl   $0x0,-0x10(%rbp)
jne    135c <md5sum_file+0x1bc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x24(%rbp),%edi
call   10b0 <strerror@plt>
mov    -0x78(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%edi
lea    0xcb9(%rip),%rsi
call   1060 <errx@plt>
movl   $0x1,-0x24(%rbp)
jmp    13a6 <md5sum_file+0x206>
cmpl   $0x0,-0x10(%rbp)
jne    139f <md5sum_file+0x1ff>
mov    -0x8(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x80(%rbp),%rdx
mov    %eax,%ecx
mov    $0x1,%edi
lea    0xc76(%rip),%rsi
call   1060 <errx@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md5sum_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,%rbx
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %esi,%r13d
mov    %rdi,%r12
call   1050 <open_file@plt>
test   %rax,%rax
je     126e <md5sum_file+0xce>
mov    %rax,%rbp
mov    %r14d,0x4(%rsp)
test   %r15d,%r15d
setne  %al
mov    %rbx,0x8(%rsp)
test   %rbx,%rbx
setne  %r14b
and    %al,%r14b
cmp    $0x1,%r14b
jne    1209 <md5sum_file+0x69>
mov    0x2de3(%rip),%rax
mov    (%rax),%rdi
lea    0xe01(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rsi
mov    %rbp,%rdi
mov    %r15d,%edx
call   10a0 <calc_md5sum@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1030 <close_file@plt>
test   %r14b,%r14b
je     1253 <md5sum_file+0xb3>
mov    %r12,%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
je     1253 <md5sum_file+0xb3>
movslq %eax,%rbp
mov    0x2d98(%rip),%rbx
mov    (%rbx),%rsi
mov    $0x8,%edi
call   1070 <fputc@plt>
add    $0xffffffffffffffff,%rbp
jne    1240 <md5sum_file+0xa0>
test   %r15d,%r15d
mov    0x4(%rsp),%eax
je     12aa <md5sum_file+0x10a>
mov    $0x1,%ebp
test   %eax,%eax
jne    1338 <md5sum_file+0x198>
mov    %r15d,%edi
jmp    1285 <md5sum_file+0xe5>
mov    $0x1,%ebp
test   %r14d,%r14d
jne    1338 <md5sum_file+0x198>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd7f(%rip),%rsi
mov    $0x1,%ebp
mov    $0x1,%edi
mov    %r12,%rdx
mov    %eax,%ecx
call   1060 <errx@plt>
jmp    1338 <md5sum_file+0x198>
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   10c0 <digest_to_string@plt>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     12f9 <md5sum_file+0x159>
test   %r13d,%r13d
lea    0xd41(%rip),%rax
lea    0xd39(%rip),%rcx
cmove  %rax,%rcx
lea    0xd26(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %rbx,%rdi
mov    %r12,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1090 <fflush@plt>
mov    0x2cd8(%rip),%rbx
mov    (%rbx),%rdi
test   %r13d,%r13d
lea    0xd01(%rip),%rax
lea    0xcf9(%rip),%rcx
cmove  %rax,%rcx
lea    0xce6(%rip),%rsi
xor    %ebp,%ebp
lea    0x20(%rsp),%rdx
mov    %r12,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%rbx),%rdi
call   1090 <fflush@plt>
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32* null
@.str = [5 x i8] c"%s: \00"
@.str.1 = [9 x i8] c"%s %s%s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c"*\00"
@.str.4 = [24 x i8] c"Failed to open '%s': %s\00"
@errno = global i32 0
define i32 @md5sum_file(i8* %0, i32 %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca [16 x i8]
%14 = alloca i64
%15 = alloca [36 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32* %4, i32** %10
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = call i8* @open_file(i8* %16, i32 %17)
store i8* %18, i8** %12
%19 = load i8*, i8** %12
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %97
21: ; preds = %5
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load i32*, i32** %10
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32*, i32** @stdout
%29 = load i8*, i8** %6
%30 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %27, %24, %21
%32 = load i8*, i8** %12
%33 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%34 = load i32, i32* %9
%35 = call i32 @calc_md5sum(i8* %32, i8* %33, i32 %34)
store i32 %35, i32* %11
%36 = load i8*, i8** %12
%37 = call i32 @close_file(i8* %36)
%38 = load i32, i32* %9
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %56
40: ; preds = %31
%41 = load i32*, i32** %10
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %56
43: ; preds = %40
%44 = load i8*, i8** %6
%45 = call i32 @strlen(i8* %44)
%46 = add nsw i32 %45, 2
%47 = sext i32 %46 to i64
store i64 %47, i64* %14
br label %48
48: ; preds = %52, %43
%49 = load i64, i64* %14
%50 = add i64 %49, -1
store i64 %50, i64* %14
%51 = icmp ugt i64 %49, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32*, i32** @stdout
%54 = call i32 @fputc(i8 signext 8, i32* %53)
br label %48
55: ; preds = %48
br label %56
56: ; preds = %55, %40, %31
%57 = load i32, i32* %11
%58 = icmp ne i32 %57, 0
br i1 %58, label %87, label %59
59: ; preds = %56
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%61 = getelementptr inbounds [36 x i8], [36 x i8]* %15, i64 0, i64 0
%62 = call i32 @digest_to_string(i8* %60, i8* %61)
%63 = load i32*, i32** %10
%64 = icmp ne i32* %63, null
br i1 %64, label %65, label %76
65: ; preds = %59
%66 = load i32*, i32** %10
%67 = getelementptr inbounds [36 x i8], [36 x i8]* %15, i64 0, i64 0
%68 = load i32, i32* %7
%69 = icmp ne i32 %68, 0
%70 = zext i1 %69 to i64
%71 = select i1 %69, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%72 = load i8*, i8** %6
%73 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %67, i8* %71, i8* %72)
%74 = load i32*, i32** %10
%75 = call i32 @fflush(i32* %74)
br label %76
76: ; preds = %65, %59
%77 = load i32*, i32** @stdout
%78 = getelementptr inbounds [36 x i8], [36 x i8]* %15, i64 0, i64 0
%79 = load i32, i32* %7
%80 = icmp ne i32 %79, 0
%81 = zext i1 %80 to i64
%82 = select i1 %80, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
%83 = load i8*, i8** %6
%84 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %77, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %78, i8* %82, i8* %83)
%85 = load i32*, i32** @stdout
%86 = call i32 @fflush(i32* %85)
br label %96
87: ; preds = %56
%88 = load i32, i32* %8
%89 = icmp ne i32 %88, 0
br i1 %89, label %95, label %90
90: ; preds = %87
%91 = load i8*, i8** %6
%92 = load i32, i32* %11
%93 = call i32 @strerror(i32 %92)
%94 = call i32 @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %91, i32 %93)
br label %95
95: ; preds = %90, %87
store i32 1, i32* %11
br label %96
96: ; preds = %95, %76
br label %106
97: ; preds = %5
%98 = load i32, i32* %8
%99 = icmp ne i32 %98, 0
br i1 %99, label %105, label %100
100: ; preds = %97
%101 = load i8*, i8** %6
%102 = load i32, i32* @errno
%103 = call i32 @strerror(i32 %102)
%104 = call i32 @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %101, i32 %103)
br label %105
105: ; preds = %100, %97
store i32 1, i32* %11
br label %106
106: ; preds = %105, %96
%107 = load i32, i32* %11
ret i32 %107
}

LLVM IR (-O2):
@stdout = global i32* null
@.str = [5 x i8] c"%s: \00"
@.str.1 = [9 x i8] c"%s %s%s\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c"*\00"
@.str.4 = [24 x i8] c"Failed to open '%s': %s\00"
@errno = global i32 0
define i32 @md5sum_file(i8* %0, i32 %1, i32 %2, i32 %3, i32* %4) {
%6 = alloca [16 x i8]
%7 = alloca [36 x i8]
%8 = tail call i8* @open_file(i8* %0, i32 %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %57, label %10
10: ; preds = %5
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%12 = icmp ne i32 %3, 0
%13 = icmp ne i32* %4, null
%14 = and i1 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32*, i32** @stdout
%17 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %15, %10
%19 = call i32 @calc_md5sum(i8* %8, i8* %11, i32 %3)
%20 = call i32 @close_file(i8* %8)
br i1 %14, label %21, label %33
21: ; preds = %18
%22 = call i32 @strlen(i8* %0)
%23 = add nsw i32 %22, 2
%24 = icmp eq i32 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = sext i32 %23 to i64
br label %27
27: ; preds = %25, %27
%28 = phi i64 [ %29, %27 ], [ %26, %25 ]
%29 = add i64 %28, -1
%30 = load i32*, i32** @stdout
%31 = call i32 @fputc(i8 signext 8, i32* %30)
%32 = icmp eq i64 %29, 0
br i1 %32, label %33, label %27
33: ; preds = %27, %21, %18
%34 = icmp eq i32 %19, 0
br i1 %34, label %35, label %50
35: ; preds = %33
%36 = getelementptr inbounds [36 x i8], [36 x i8]* %7, i64 0, i64 0
%37 = call i32 @digest_to_string(i8* %11, i8* %36)
br i1 %13, label %38, label %43
38: ; preds = %35
%39 = icmp eq i32 %1, 0
%40 = select i1 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%41 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %40, i8* %0)
%42 = call i32 @fflush(i32* %4)
br label %43
43: ; preds = %35, %38
%44 = load i32*, i32** @stdout
%45 = icmp eq i32 %1, 0
%46 = select i1 %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%47 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %46, i8* %0)
%48 = load i32*, i32** @stdout
%49 = call i32 @fflush(i32* %48)
br label %55
50: ; preds = %33
%51 = icmp eq i32 %2, 0
br i1 %51, label %52, label %55
52: ; preds = %50
%53 = call i32 @strerror(i32 %19)
%54 = call i32 @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %53)
br label %55
55: ; preds = %50, %52, %43
%56 = phi i32 [ 0, %43 ], [ 1, %52 ], [ 1, %50 ]
br label %63
57: ; preds = %5
%58 = icmp eq i32 %2, 0
br i1 %58, label %59, label %63
59: ; preds = %57
%60 = load i32, i32* @errno
%61 = tail call i32 @strerror(i32 %60)
%62 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %61)
br label %63
63: ; preds = %57, %59, %55
%64 = phi i32 [ %56, %55 ], [ 1, %59 ], [ 1, %57 ]
ret i32 %64
}