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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ libevil_md5sum_fd(int, int /*<<< orphan*/ *);
int openat(int, char const *, int /*<<< orphan*/, int /*<<< orphan*/);
int libevil_md5sum_file(int dirfd, const char *path, uint8_t *out) {
  int fd = -1;
  fd = openat(dirfd, path, O_RDONLY, 0);
  if (fd < 0)
    return -errno;
  libevil_md5sum_fd(fd, out);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<libevil_md5sum_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1030 <openat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1181 <libevil_md5sum_file+0x51>
xor    %eax,%eax
mov    0x2e61(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <libevil_md5sum_file+0x6c>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <libevil_md5sum_fd@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<libevil_md5sum_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    0x2eaa(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
xor    %ecx,%ecx
call   1030 <openat@plt>
test   %eax,%eax
js     1162 <libevil_md5sum_file+0x32>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <libevil_md5sum_fd@plt>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    116d <libevil_md5sum_file+0x3d>
mov    0x2e6f(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @libevil_md5sum_file(i32 %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32* %2, i32** %7
store i32 -1, i32* %8
%9 = load i32, i32* %5
%10 = load i8*, i8** %6
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @openat(i32 %9, i8* %10, i32 %11, i32 0)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* @errno
%17 = sub nsw i32 0, %16
store i32 %17, i32* %4
br label %24
18: ; preds = %3
%19 = load i32, i32* %8
%20 = load i32*, i32** %7
%21 = call i32 @libevil_md5sum_fd(i32 %19, i32* %20)
%22 = load i32, i32* %8
%23 = call i32 @close(i32 %22)
store i32 0, i32* %4
br label %24
24: ; preds = %18, %15
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@errno = global i32 0
define i32 @libevil_md5sum_file(i32 %0, i8* %1, i32* %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @openat(i32 %0, i8* %1, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
br label %13
10: ; preds = %3
%11 = tail call i32 @libevil_md5sum_fd(i32 %5, i32* %2)
%12 = tail call i32 @close(i32 %5)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ %9, %7 ], [ 0, %10 ]
ret i32 %14
}