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

/* Variables and functions */
scalar_t__ ENOENT;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int R_OK;
int W_OK;
scalar_t__ access(char *, int);
scalar_t__ chown(char *, int, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int getgid();
int getuid();
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ stat(char *, struct stat *);
char *strerror(scalar_t__);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
int wfc_util_ffile_check_copy(char *pDestFName, char *pSourceFName, mode_t mode,
                              uid_t uID, gid_t gID) {
  char buf[2048] = {0};
  int srcfd, destfd;
  int nread;
  struct stat st;
  if (access(pDestFName, R_OK | W_OK) == 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 if (errno != ENOENT) {
    printf("Cannot access \"%s\": %s", pDestFName, strerror(errno));
    printf("\n");
    return -1;
  }
  srcfd = open(pSourceFName, O_RDONLY);
  if (srcfd < 0) {
    printf("Cannot open \"%s\": %s", pSourceFName, strerror(errno));
    printf("\n");
    return -1;
  }
  destfd = open(pDestFName, O_CREAT | O_WRONLY, mode);
  if (destfd < 0) {
    close(srcfd);
    printf("Cannot create \"%s\": %s", pDestFName, strerror(errno));
    printf("\n");
    return -1;
  }
  while ((nread = read(srcfd, buf, 2048 - 1)) != 0) {
    if (nread < 0) {
      printf("Error reading \"%s\": %s", pSourceFName, strerror(errno));
      printf("\n");
      close(srcfd);
      close(destfd);
      unlink(pDestFName);
      return -1;
    }
    if (nread < 2048)
      buf[nread] = '\0';
    else {
      buf[2048 - 1] = '\0';
      nread = 2048 - 1;
    }
    write(destfd, buf, nread);
  }
  close(destfd);
  close(srcfd);
  {
    uid_t uid = getuid();
    gid_t gid = getgid();
    printf("Error changing group ownership (%d) of %s to %d: %s", gid,
           pDestFName, gID, strerror(errno));
    printf("\n");
    if (0 == uid) {
      if (chown(pDestFName, uID, gID) < 0) {
        printf("Error changing group ownership of %s to %d: %s", pDestFName,
               gID, strerror(errno));
        printf("\n");
        unlink(pDestFName);
        return -1;
      }
    } else {
      printf("wfc_util_ffile_check_copy : we can not excute chown[uid = %d, "
             "gid = %d]",
             uid, getgid());
      printf("\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<wfc_util_ffile_check_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8a0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
mov    0x2dc4(%rip),%rax
or     (%rax),%esi
call   10e0 <access@plt>
cmp    $0x0,%rax
jne    12aa <wfc_util_ffile_check_copy+0xda>
mov    -0x10(%rbp),%rdi
lea    -0x848(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
jge    128b <wfc_util_ffile_check_copy+0xbb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x858(%rbp)
mov    0x2d77(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x858(%rbp),%rsi
mov    %rax,%rdx
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1663 <wfc_util_ffile_check_copy+0x493>
cmpq   $0x0,-0x848(%rbp)
je     12a5 <wfc_util_ffile_check_copy+0xd5>
movl   $0x0,-0x4(%rbp)
jmp    1663 <wfc_util_ffile_check_copy+0x493>
jmp    1315 <wfc_util_ffile_check_copy+0x145>
mov    0x2d17(%rip),%rax
mov    (%rax),%rax
mov    0x2cf5(%rip),%rcx
cmp    (%rcx),%rax
je     1310 <wfc_util_ffile_check_copy+0x140>
mov    -0x10(%rbp),%rax
mov    %rax,-0x860(%rbp)
mov    0x2cf2(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x860(%rbp),%rsi
mov    %rax,%rdx
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1663 <wfc_util_ffile_check_copy+0x493>
jmp    1315 <wfc_util_ffile_check_copy+0x145>
mov    -0x18(%rbp),%rdi
mov    0x2cc0(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x834(%rbp)
cmpl   $0x0,-0x834(%rbp)
jge    1388 <wfc_util_ffile_check_copy+0x1b8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x868(%rbp)
mov    0x2c7a(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x868(%rbp),%rsi
mov    %rax,%rdx
lea    0xcd0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xca9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1663 <wfc_util_ffile_check_copy+0x493>
mov    -0x10(%rbp),%rdi
mov    0x2c65(%rip),%rax
mov    (%rax),%esi
mov    0x2c0c(%rip),%rax
or     (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   10d0 <open@plt>
mov    %eax,-0x838(%rbp)
cmpl   $0x0,-0x838(%rbp)
jge    1412 <wfc_util_ffile_check_copy+0x242>
mov    -0x834(%rbp),%edi
call   1080 <close@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x870(%rbp)
mov    0x2bf0(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x870(%rbp),%rsi
mov    %rax,%rdx
lea    0xc5b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc1f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1663 <wfc_util_ffile_check_copy+0x493>
jmp    1417 <wfc_util_ffile_check_copy+0x247>
mov    -0x834(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    $0x7ff,%edx
call   1090 <read@plt>
mov    %eax,-0x83c(%rbp)
cmp    $0x0,%eax
je     1504 <wfc_util_ffile_check_copy+0x334>
cmpl   $0x0,-0x83c(%rbp)
jge    14b5 <wfc_util_ffile_check_copy+0x2e5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x878(%rbp)
mov    0x2b6c(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x878(%rbp),%rsi
mov    %rax,%rdx
lea    0xbee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xb9b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x834(%rbp),%edi
call   1080 <close@plt>
mov    -0x838(%rbp),%edi
call   1080 <close@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1663 <wfc_util_ffile_check_copy+0x493>
cmpl   $0x800,-0x83c(%rbp)
jge    14d9 <wfc_util_ffile_check_copy+0x309>
movslq -0x83c(%rbp),%rax
movb   $0x0,-0x830(%rbp,%rax,1)
jmp    14e7 <wfc_util_ffile_check_copy+0x317>
movb   $0x0,-0x31(%rbp)
movl   $0x7ff,-0x83c(%rbp)
mov    -0x838(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    -0x83c(%rbp),%edx
call   1040 <write@plt>
jmp    1417 <wfc_util_ffile_check_copy+0x247>
mov    -0x838(%rbp),%edi
call   1080 <close@plt>
mov    -0x834(%rbp),%edi
call   1080 <close@plt>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,-0x84c(%rbp)
mov    $0x0,%al
call   10b0 <getgid@plt>
mov    %eax,-0x850(%rbp)
mov    -0x850(%rbp),%eax
mov    %eax,-0x88c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x888(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x87c(%rbp)
mov    0x2a6d(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x88c(%rbp),%esi
mov    -0x888(%rbp),%rdx
mov    -0x87c(%rbp),%ecx
mov    %rax,%r8
lea    0xafa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xa90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
cmp    -0x84c(%rbp),%eax
jne    1625 <wfc_util_ffile_check_copy+0x455>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   10c0 <chown@plt>
cmp    $0x0,%rax
jge    1620 <wfc_util_ffile_check_copy+0x450>
mov    -0x10(%rbp),%rax
mov    %rax,-0x898(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x890(%rbp)
mov    0x29f1(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strerror@plt>
mov    -0x898(%rbp),%rsi
mov    -0x890(%rbp),%edx
mov    %rax,%rcx
lea    0xab8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xa1a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1663 <wfc_util_ffile_check_copy+0x493>
jmp    165c <wfc_util_ffile_check_copy+0x48c>
mov    -0x84c(%rbp),%eax
mov    %eax,-0x89c(%rbp)
mov    $0x0,%al
call   10b0 <getgid@plt>
mov    -0x89c(%rbp),%esi
mov    %eax,%edx
lea    0xa96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0x9c9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wfc_util_ffile_check_copy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %rsi,%r12
mov    %rdi,%r13
lea    0x20(%rsp),%rdi
mov    $0x800,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    0x2da9(%rip),%rax
mov    0x2dba(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r13,%rdi
call   10f0 <access@plt>
test   %rax,%rax
je     1256 <wfc_util_ffile_check_copy+0x76>
mov    0x2d92(%rip),%rax
mov    (%rax),%rdi
mov    0x2d70(%rip),%rax
cmp    (%rax),%rdi
je     127a <wfc_util_ffile_check_copy+0x9a>
call   1100 <strerror@plt>
lea    0xdcd(%rip),%rdi
jmp    1415 <wfc_util_ffile_check_copy+0x235>
lea    0x18(%rsp),%rsi
mov    %r13,%rdi
call   10b0 <stat@plt>
test   %rax,%rax
js     13e0 <wfc_util_ffile_check_copy+0x200>
xor    %ebp,%ebp
cmpq   $0x0,0x18(%rsp)
jne    1431 <wfc_util_ffile_check_copy+0x251>
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
js     13c5 <wfc_util_ffile_check_copy+0x1e5>
mov    %eax,%ebp
mov    0x2d5a(%rip),%rax
mov    0x2d03(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r13,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
js     13f8 <wfc_util_ffile_check_copy+0x218>
mov    %eax,%ebx
mov    %r12,0x10(%rsp)
mov    %r15d,0x8(%rsp)
mov    %r14d,0xc(%rsp)
lea    0x20(%rsp),%rsi
mov    $0x7ff,%r15d
mov    %ebp,%edi
mov    $0x7ff,%edx
call   10a0 <read@plt>
test   %eax,%eax
je     133e <wfc_util_ffile_check_copy+0x15e>
lea    0x81f(%rsp),%r12
lea    0x20(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
test   %eax,%eax
js     1445 <wfc_util_ffile_check_copy+0x265>
cmp    $0x800,%eax
mov    %eax,%ecx
lea    0x20(%rsp,%rcx,1),%rcx
cmovae %r12,%rcx
cmovae %r15d,%eax
movb   $0x0,(%rcx)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x7ff,%edx
call   10a0 <read@plt>
test   %eax,%eax
jne    1300 <wfc_util_ffile_check_copy+0x120>
mov    %ebx,%edi
call   1090 <close@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <getuid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   10c0 <getgid@plt>
mov    %eax,%ebx
mov    0x2c60(%rip),%r15
mov    (%r15),%rdi
call   1100 <strerror@plt>
lea    0xd01(%rip),%rdi
mov    %ebx,%esi
mov    %r13,%rdx
mov    0xc(%rsp),%ebx
mov    %ebx,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
je     1484 <wfc_util_ffile_check_copy+0x2a4>
xor    %eax,%eax
call   10c0 <getgid@plt>
lea    0xd2e(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1431 <wfc_util_ffile_check_copy+0x251>
mov    0x2bfc(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xc5a(%rip),%rdi
mov    %r12,%rsi
jmp    1418 <wfc_util_ffile_check_copy+0x238>
mov    0x2be1(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xc0a(%rip),%rdi
jmp    1415 <wfc_util_ffile_check_copy+0x235>
mov    %ebp,%edi
call   1090 <close@plt>
mov    0x2bc2(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xc35(%rip),%rdi
mov    %r13,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b7c(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xc06(%rip),%rdi
mov    0x10(%rsp),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %ebx,%edi
call   1090 <close@plt>
jmp    14bf <wfc_util_ffile_check_copy+0x2df>
mov    %r13,%rdi
mov    0x8(%rsp),%esi
mov    %ebx,%edx
call   10d0 <chown@plt>
test   %rax,%rax
jns    1431 <wfc_util_ffile_check_copy+0x251>
mov    (%r15),%rdi
call   1100 <strerror@plt>
lea    0xc06(%rip),%rdi
mov    %r13,%rsi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13,%rdi
call   1040 <unlink@plt>
jmp    142c <wfc_util_ffile_check_copy+0x24c>

LLVM IR (-O0):
%struct.stat = type { i64 }
@R_OK = global i32 0
@W_OK = global i32 0
@.str = [30 x i8] c"Cannot stat the file \22%s\22: %s\00"
@errno = global i64 0
@.str.1 = [2 x i8] c"\0A\00"
@ENOENT = global i64 0
@.str.2 = [23 x i8] c"Cannot access \22%s\22: %s\00"
@O_RDONLY = global i32 0
@.str.3 = [21 x i8] c"Cannot open \22%s\22: %s\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.4 = [23 x i8] c"Cannot create \22%s\22: %s\00"
@.str.5 = [23 x i8] c"Error reading \22%s\22: %s\00"
@.str.6 = [52 x i8] c"Error changing group ownership (%d) of %s to %d: %s\00"
@.str.7 = [47 x i8] c"Error changing group ownership of %s to %d: %s\00"
@.str.8 = [72 x i8] c"wfc_util_ffile_check_copy : we can not excute chown[uid = %d, gid = %d]\00"
define i32 @wfc_util_ffile_check_copy(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [2048 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.stat
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%19 = bitcast [2048 x i8]* %12 to i8*
%20 = load i8*, i8** %7
%21 = load i32, i32* @R_OK
%22 = load i32, i32* @W_OK
%23 = or i32 %21, %22
%24 = call i64 @access(i8* %20, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %42
26: ; preds = %5
%27 = load i8*, i8** %7
%28 = call i64 @stat(i8* %27, %struct.stat* %16)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i8*, i8** %7
%32 = load i64, i64* @errno
%33 = call i8* @strerror(i64 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %33)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %155
36: ; preds = %26
%37 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%38 = load i64, i64* %37
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
store i32 0, i32* %6
br label %155
41: ; preds = %36
br label %53
42: ; preds = %5
%43 = load i64, i64* @errno
%44 = load i64, i64* @ENOENT
%45 = icmp ne i64 %43, %44
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i8*, i8** %7
%48 = load i64, i64* @errno
%49 = call i8* @strerror(i64 %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %47, i8* %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %155
52: ; preds = %42
br label %53
53: ; preds = %52, %41
%54 = load i8*, i8** %8
%55 = load i32, i32* @O_RDONLY
%56 = call i32 (i8*, i32, ...) @open(i8* %54, i32 %55)
store i32 %56, i32* %13
%57 = load i32, i32* %13
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %65
59: ; preds = %53
%60 = load i8*, i8** %8
%61 = load i64, i64* @errno
%62 = call i8* @strerror(i64 %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %60, i8* %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %155
65: ; preds = %53
%66 = load i8*, i8** %7
%67 = load i32, i32* @O_CREAT
%68 = load i32, i32* @O_WRONLY
%69 = or i32 %67, %68
%70 = load i32, i32* %9
%71 = call i32 (i8*, i32, ...) @open(i8* %66, i32 %69, i32 %70)
store i32 %71, i32* %14
%72 = load i32, i32* %14
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %82
74: ; preds = %65
%75 = load i32, i32* %13
%76 = call i32 @close(i32 %75)
%77 = load i8*, i8** %7
%78 = load i64, i64* @errno
%79 = call i8* @strerror(i64 %78)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %77, i8* %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %6
br label %155
82: ; preds = %65
br label %83
83: ; preds = %112, %82
%84 = load i32, i32* %13
%85 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%86 = call i32 @read(i32 %84, i8* %85, i32 2047)
store i32 %86, i32* %15
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %117
88: ; preds = %83
%89 = load i32, i32* %15
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %103
91: ; preds = %88
%92 = load i8*, i8** %8
%93 = load i64, i64* @errno
%94 = call i8* @strerror(i64 %93)
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %92, i8* %94)
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%97 = load i32, i32* %13
%98 = call i32 @close(i32 %97)
%99 = load i32, i32* %14
%100 = call i32 @close(i32 %99)
%101 = load i8*, i8** %7
%102 = call i32 @unlink(i8* %101)
store i32 -1, i32* %6
br label %155
103: ; preds = %88
%104 = load i32, i32* %15
%105 = icmp slt i32 %104, 2048
br i1 %105, label %106, label %110
106: ; preds = %103
%107 = load i32, i32* %15
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 %108
store i8 0, i8* %109
br label %112
110: ; preds = %103
%111 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 2047
store i8 0, i8* %111
store i32 2047, i32* %15
br label %112
112: ; preds = %110, %106
%113 = load i32, i32* %14
%114 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%115 = load i32, i32* %15
%116 = call i32 @write(i32 %113, i8* %114, i32 %115)
br label %83
117: ; preds = %83
%118 = load i32, i32* %14
%119 = call i32 @close(i32 %118)
%120 = load i32, i32* %13
%121 = call i32 @close(i32 %120)
%122 = call i32 (...) @getuid()
store i32 %122, i32* %17
%123 = call i32 (...) @getgid()
store i32 %123, i32* %18
%124 = load i32, i32* %18
%125 = load i8*, i8** %7
%126 = load i32, i32* %11
%127 = load i64, i64* @errno
%128 = call i8* @strerror(i64 %127)
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i32 %124, i8* %125, i32 %126, i8* %128)
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%131 = load i32, i32* %17
%132 = icmp eq i32 0, %131
br i1 %132, label %133, label %149
133: ; preds = %117
%134 = load i8*, i8** %7
%135 = load i32, i32* %10
%136 = load i32, i32* %11
%137 = call i64 @chown(i8* %134, i32 %135, i32 %136)
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %148
139: ; preds = %133
%140 = load i8*, i8** %7
%141 = load i32, i32* %11
%142 = load i64, i64* @errno
%143 = call i8* @strerror(i64 %142)
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i8* %140, i32 %141, i8* %143)
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%146 = load i8*, i8** %7
%147 = call i32 @unlink(i8* %146)
store i32 -1, i32* %6
br label %155
148: ; preds = %133
br label %154
149: ; preds = %117
%150 = load i32, i32* %17
%151 = call i32 (...) @getgid()
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.8, i64 0, i64 0), i32 %150, i32 %151)
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %154
154: ; preds = %149, %148
store i32 0, i32* %6
br label %155
155: ; preds = %154, %139, %91, %74, %59, %46, %40, %30
%156 = load i32, i32* %6
ret i32 %156
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@R_OK = global i32 0
@W_OK = global i32 0
@.str = [30 x i8] c"Cannot stat the file \22%s\22: %s\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [23 x i8] c"Cannot access \22%s\22: %s\00"
@O_RDONLY = global i32 0
@.str.3 = [21 x i8] c"Cannot open \22%s\22: %s\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.4 = [23 x i8] c"Cannot create \22%s\22: %s\00"
@.str.5 = [23 x i8] c"Error reading \22%s\22: %s\00"
@.str.6 = [52 x i8] c"Error changing group ownership (%d) of %s to %d: %s\00"
@.str.7 = [47 x i8] c"Error changing group ownership of %s to %d: %s\00"
@.str.8 = [72 x i8] c"wfc_util_ffile_check_copy : we can not excute chown[uid = %d, gid = %d]\00"
define i32 @wfc_util_ffile_check_copy(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [2048 x i8]
%7 = alloca %struct.stat
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%9 = bitcast %struct.stat* %7 to i8*
%10 = load i32, i32* @R_OK
%11 = load i32, i32* @W_OK
%12 = or i32 %11, %10
%13 = tail call i64 @access(i8* %0, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %5
%16 = call i64 @stat(i8* %0, %struct.stat* %7)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = call i8* @strerror(i64 %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %20)
%22 = call i32 @putchar(i32 10)
br label %104
23: ; preds = %15
%24 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%25 = load i64, i64* %24
%26 = icmp eq i64 %25, 0
br i1 %26, label %35, label %104
27: ; preds = %5
%28 = load i64, i64* @errno
%29 = load i64, i64* @ENOENT
%30 = icmp eq i64 %28, %29
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = tail call i8* @strerror(i64 %28)
%33 = 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* %32)
%34 = tail call i32 @putchar(i32 10)
br label %104
35: ; preds = %27, %23
%36 = load i32, i32* @O_RDONLY
%37 = call i32 (i8*, i32, ...) @open(i8* %1, i32 %36)
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i64, i64* @errno
%41 = call i8* @strerror(i64 %40)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %41)
%43 = call i32 @putchar(i32 10)
br label %104
44: ; preds = %35
%45 = load i32, i32* @O_CREAT
%46 = load i32, i32* @O_WRONLY
%47 = or i32 %46, %45
%48 = call i32 (i8*, i32, ...) @open(i8* %0, i32 %47, i32 %2)
%49 = icmp slt i32 %48, 0
br i1 %49, label %55, label %50
50: ; preds = %44
%51 = call i32 @read(i32 %37, i8* %8, i32 2047)
%52 = icmp eq i32 %51, 0
br i1 %52, label %81, label %53
53: ; preds = %50
%54 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 2047
br label %61
55: ; preds = %44
%56 = call i32 @close(i32 %37)
%57 = load i64, i64* @errno
%58 = call i8* @strerror(i64 %57)
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %58)
%60 = call i32 @putchar(i32 10)
br label %104
61: ; preds = %53, %72
%62 = phi i32 [ %51, %53 ], [ %79, %72 ]
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %72
64: ; preds = %61
%65 = load i64, i64* @errno
%66 = call i8* @strerror(i64 %65)
%67 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %1, i8* %66)
%68 = call i32 @putchar(i32 10)
%69 = call i32 @close(i32 %37)
%70 = call i32 @close(i32 %48)
%71 = call i32 @unlink(i8* %0)
br label %104
72: ; preds = %61
%73 = icmp ult i32 %62, 2048
%74 = zext i32 %62 to i64
%75 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 %74
%76 = select i1 %73, i8* %75, i8* %54
%77 = select i1 %73, i32 %62, i32 2047
store i8 0, i8* %76
%78 = call i32 @write(i32 %48, i8* %8, i32 %77)
%79 = call i32 @read(i32 %37, i8* %8, i32 2047)
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %61
81: ; preds = %72, %50
%82 = call i32 @close(i32 %48)
%83 = call i32 @close(i32 %37)
%84 = call i32 (...) @getuid()
%85 = call i32 (...) @getgid()
%86 = load i64, i64* @errno
%87 = call i8* @strerror(i64 %86)
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i32 %85, i8* %0, i32 %4, i8* %87)
%89 = call i32 @putchar(i32 10)
%90 = icmp eq i32 %84, 0
br i1 %90, label %91, label %94
91: ; preds = %81
%92 = call i64 @chown(i8* %0, i32 %3, i32 %4)
%93 = icmp slt i64 %92, 0
br i1 %93, label %98, label %104
94: ; preds = %81
%95 = call i32 (...) @getgid()
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.8, i64 0, i64 0), i32 %84, i32 %95)
%97 = call i32 @putchar(i32 10)
br label %104
98: ; preds = %91
%99 = load i64, i64* @errno
%100 = call i8* @strerror(i64 %99)
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i8* %0, i32 %4, i8* %100)
%102 = call i32 @putchar(i32 10)
%103 = call i32 @unlink(i8* %0)
br label %104
104: ; preds = %98, %91, %94, %23, %64, %55, %39, %31, %18
%105 = phi i32 [ -1, %18 ], [ -1, %39 ], [ -1, %55 ], [ -1, %64 ], [ -1, %31 ], [ 0, %23 ], [ -1, %98 ], [ 0, %91 ], [ 0, %94 ]
ret i32 %105
}