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

/* Variables and functions */
int O_NOCTTY;
int O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int);
int sha1_fd(int, unsigned char *);
int dttools_sha1_file(const char *path, unsigned char digest[20]) {
  int fd = open(path, O_RDONLY | O_NOCTTY);
  if (fd == -1)
    return 0;
  int rc = sha1_fd(fd, digest);
  close(fd);
  return rc;
}


x86 assembly (clang, -O0):
<dttools_sha1_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    0x2e84(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1174 <dttools_sha1_file+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1191 <dttools_sha1_file+0x61>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <sha1_fd@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dttools_sha1_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2eab(%rip),%rax
mov    0x2e94(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     116b <dttools_sha1_file+0x3b>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <sha1_fd@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
jmp    116d <dttools_sha1_file+0x3d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_NOCTTY = global i32 0
define i32 @dttools_sha1_file(i8* nocapture %0, i8* %1) {
%3 = load i32, i32* @O_RDONLY
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @sha1_fd(i32 %6, i8* %1)
%10 = tail call i32 @close(i32 %6)
br label %11
11: ; preds = %2, %8
%12 = phi i32 [ %9, %8 ], [ 0, %2 ]
ret i32 %12
}