#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 */
struct stat {
  scalar_t__ st_size;
};
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int fstat(int, struct stat *);
int /*<<< orphan*/ infq_errno_log(char *, int, char *, char const *);
int /*<<< orphan*/ infq_log(int, char *, int, char *);
int infq_pread(int, unsigned char *, int, scalar_t__);
int open(char const *, int /*<<< orphan*/);
int32_t file_fetch_signature(const char *file_path, unsigned char digest[20]) {
  if (file_path == NULL || digest == NULL) {
    infq_log(2,
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/chosen0ne/infQ/refs/heads/master/src/"
             "file_block.c",
             675, "invalid param");
    return -1;
  }
  int fd;
  struct stat finfo;
  if ((fd = open(file_path, O_RDONLY)) == -1 || fstat(fd, &finfo) == -1) {
    infq_errno_log("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/chosen0ne/infQ/refs/"
                   "heads/master/src/file_block.c",
                   683, "failed to open and stat file, path: %s", file_path);
    return -1;
  }
  if (infq_pread(fd, digest, 20, finfo.st_size - 20) == -1) {
    infq_errno_log("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/chosen0ne/infQ/refs/"
                   "heads/master/src/file_block.c",
                   688, "failed to read file, path: %s", file_path);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<file_fetch_signature>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1176 <file_fetch_signature+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    119f <file_fetch_signature+0x4f>
mov    $0x2,%edi
lea    0xe7e(%rip),%rsi
mov    $0x2a3,%edx
lea    0xefe(%rip),%rcx
call   1030 <infq_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124b <file_fetch_signature+0xfb>
mov    -0x10(%rbp),%rdi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11d2 <file_fetch_signature+0x82>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1070 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11fa <file_fetch_signature+0xaa>
mov    -0x10(%rbp),%rcx
lea    0xe23(%rip),%rdi
mov    $0x2ab,%esi
lea    0xeb1(%rip),%rdx
call   1050 <infq_errno_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124b <file_fetch_signature+0xfb>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rcx
sub    $0x14,%rcx
mov    $0x14,%edx
call   1040 <infq_pread@plt>
cmp    $0xffffffff,%eax
jne    1244 <file_fetch_signature+0xf4>
mov    -0x10(%rbp),%rcx
lea    0xdd9(%rip),%rdi
mov    $0x2b0,%esi
lea    0xe8e(%rip),%rdx
call   1050 <infq_errno_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    124b <file_fetch_signature+0xfb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_fetch_signature>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     11c4 <file_fetch_signature+0x74>
mov    %rsi,%r14
test   %rsi,%rsi
je     11c4 <file_fetch_signature+0x74>
mov    %rdi,%rbx
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11e3 <file_fetch_signature+0x93>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1070 <fstat@plt>
cmp    $0xffffffff,%eax
je     11e3 <file_fetch_signature+0x93>
mov    0x8(%rsp),%rcx
add    $0xffffffffffffffec,%rcx
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x14,%edx
call   1040 <infq_pread@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1203 <file_fetch_signature+0xb3>
lea    0xe4a(%rip),%rdi
lea    0xf04(%rip),%rdx
mov    $0x2b0,%esi
jmp    11f6 <file_fetch_signature+0xa6>
lea    0xe35(%rip),%rsi
lea    0xeba(%rip),%rcx
mov    $0x2,%edi
mov    $0x2a3,%edx
call   1030 <infq_log@plt>
jmp    11fe <file_fetch_signature+0xae>
lea    0xe16(%rip),%rdi
lea    0xea9(%rip),%rdx
mov    $0x2ab,%esi
mov    %rbx,%rcx
call   1050 <infq_errno_log@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/chosen0ne/infQ/refs/heads/master/src/file_block.c\00"
@.str.1 = [14 x i8] c"invalid param\00"
@O_RDONLY = global i32 0
@.str.2 = [39 x i8] c"failed to open and stat file, path: %s\00"
@.str.3 = [30 x i8] c"failed to read file, path: %s\00"
define i32 @file_fetch_signature(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10, %2
%14 = call i32 @infq_log(i32 2, i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 675, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = load i32, i32* %6
%22 = call i32 @fstat(i32 %21, %struct.stat* %7)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %20, %15
%25 = load i8*, i8** %4
%26 = call i32 @infq_errno_log(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 683, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %25)
store i32 -1, i32* %3
br label %39
27: ; preds = %20
%28 = load i32, i32* %6
%29 = load i8*, i8** %5
%30 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%31 = load i64, i64* %30
%32 = sub nsw i64 %31, 20
%33 = call i32 @infq_pread(i32 %28, i8* %29, i32 20, i64 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %27
%36 = load i8*, i8** %4
%37 = call i32 @infq_errno_log(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 688, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %36)
store i32 -1, i32* %3
br label %39
38: ; preds = %27
store i32 0, i32* %3
br label %39
39: ; preds = %38, %35, %24, %13
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/chosen0ne/infQ/refs/heads/master/src/file_block.c\00"
@.str.1 = [14 x i8] c"invalid param\00"
@O_RDONLY = global i32 0
@.str.2 = [39 x i8] c"failed to open and stat file, path: %s\00"
@.str.3 = [30 x i8] c"failed to read file, path: %s\00"
define i32 @file_fetch_signature(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @infq_log(i32 2, i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 675, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %29
9: ; preds = %2
%10 = bitcast %struct.stat* %3 to i8*
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %0, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = call i32 @fstat(i32 %12, %struct.stat* %3)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14, %9
%18 = tail call i32 @infq_errno_log(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 683, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %27
19: ; preds = %14
%20 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%21 = load i64, i64* %20
%22 = add nsw i64 %21, -20
%23 = tail call i32 @infq_pread(i32 %12, i8* %1, i32 20, i64 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = tail call i32 @infq_errno_log(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 688, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %27
27: ; preds = %19, %25, %17
%28 = phi i32 [ -1, %17 ], [ -1, %25 ], [ 0, %19 ]
br label %29
29: ; preds = %27, %7
%30 = phi i32 [ -1, %7 ], [ %28, %27 ]
ret i32 %30
}