#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;
};

/* Variables and functions */
scalar_t__ access(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
char *strerror(int /*<<< orphan*/);
int wfc_util_ffile_check(char *pDestFName, int access_mode) {
  struct stat st;
  if (access(pDestFName, access_mode) == 0) {
    if (stat(pDestFName, &st) < 0) {
      printf("Cannot stat the file \"%s\": %s", pDestFName, strerror(errno));
      printf("\n");
      return -1;
    }
    if (st.st_size) {
      return 0;
    }
  } else {
    printf("Cannot access \"%s\": %s", pDestFName, strerror(errno));
    printf("\n");
  }
  return -1;
}


x86 assembly (clang, -O0):
<wfc_util_ffile_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
jne    11dd <wfc_util_ffile_check+0x9d>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    11c1 <wfc_util_ffile_check+0x81>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <wfc_util_ffile_check+0xdd>
cmpq   $0x0,-0x20(%rbp)
je     11d8 <wfc_util_ffile_check+0x98>
movl   $0x0,-0x4(%rbp)
jmp    121d <wfc_util_ffile_check+0xdd>
jmp    1216 <wfc_util_ffile_check+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wfc_util_ffile_check>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1060 <access@plt>
test   %rax,%rax
je     1199 <wfc_util_ffile_check+0x49>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xea7(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     11b7 <wfc_util_ffile_check+0x67>
xor    %eax,%eax
cmpq   $0x0,0x8(%rsp)
jne    1193 <wfc_util_ffile_check+0x43>
jmp    118e <wfc_util_ffile_check+0x3e>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe34(%rip),%rdi
jmp    1177 <wfc_util_ffile_check+0x27>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [30 x i8] c"Cannot stat the file \22%s\22: %s\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [23 x i8] c"Cannot access \22%s\22: %s\00"
define i32 @wfc_util_ffile_check(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.stat
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = call i64 @access(i8* %7, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i64 @stat(i8* %12, %struct.stat* %6)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %34
21: ; preds = %11
%22 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%23 = load i64, i64* %22
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 0, i32* %3
br label %34
26: ; preds = %21
br label %33
27: ; preds = %2
%28 = load i8*, i8** %4
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %28, i8* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %27, %26
store i32 -1, i32* %3
br label %34
34: ; preds = %33, %25, %15
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [30 x i8] c"Cannot stat the file \22%s\22: %s\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"Cannot access \22%s\22: %s\00"
define i32 @wfc_util_ffile_check(i8* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i64 @access(i8* %0, i32 %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %2
%8 = call i64 @stat(i8* %0, %struct.stat* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %12)
%14 = call i32 @putchar(i32 10)
br label %25
15: ; preds = %7
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%17 = load i64, i64* %16
%18 = icmp eq i64 %17, 0
br i1 %18, label %24, label %25
19: ; preds = %2
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %21)
%23 = tail call i32 @putchar(i32 10)
br label %24
24: ; preds = %15, %19
br label %25
25: ; preds = %15, %24, %10
%26 = phi i32 [ -1, %10 ], [ -1, %24 ], [ 0, %15 ]
ret i32 %26
}