#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 timespec {
  int dummy;
};
struct stat {
  struct timespec st_mtim;
  struct timespec st_atim;
  int /*<<< orphan*/ st_mode;
  int /*<<< orphan*/ st_gid;
  int /*<<< orphan*/ st_uid;
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ AT_FDCWD;
scalar_t__ EXDEV;
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int chmod(char *, int /*<<< orphan*/);
int chown(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int copy_file_bytes(int, int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ errno;
int open(char *, int);
int /*<<< orphan*/ print_error(char *, int, scalar_t__, char *);
int rename(char *, char *);
int stat(char *, struct stat *);
int unlink(char *);
int utimensat(int /*<<< orphan*/, char *, struct timespec *,
              int /*<<< orphan*/);
int replace_file(char *newfile, char *origfile, const struct stat origst) {
  struct timespec ts[2];
  if (rename(newfile, origfile) == -1)
    if (errno == EXDEV) {
      struct stat newst;
      int newfd, origfd;
      if (stat(newfile, &newst) == -1) {
        print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/"
                    "refs/heads/master/common.c",
                    30 - 1, errno, "stat");
        return -1;
      }
      if ((newfd = open(newfile, O_RDONLY)) == -1) {
        print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/"
                    "refs/heads/master/common.c",
                    35 - 1, errno, "open");
        return -1;
      }
      if ((origfd = open(origfile, O_WRONLY | O_TRUNC)) == -1) {
        print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/"
                    "refs/heads/master/common.c",
                    40 - 1, errno, "open");
        return -1;
      }
      if (copy_file_bytes(origfd, newfd, 0, newst.st_size) == -1)
        return -1;
      close(origfd);
      close(newfd);
      if (unlink(newfile) == -1)
        print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/"
                    "refs/heads/master/common.c",
                    51 - 1, errno, "unlink");
    } else {
      print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/"
                  "heads/master/common.c",
                  53 - 1, errno, "rename");
      return -1;
    }
  if (chown(origfile, origst.st_uid, origst.st_gid) == -1)
    print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/"
                "heads/master/common.c",
                59 - 1, errno, "chown");
  if (chmod(origfile, origst.st_mode) == -1)
    print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/"
                "heads/master/common.c",
                62 - 1, errno, "chmod");
  ts[0] = origst.st_atim;
  ts[1] = origst.st_mtim;
  if (utimensat(AT_FDCWD, origfile, ts, 0) == -1)
    print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/"
                "heads/master/common.c",
                67 - 1, errno, "utimensat");
  return 0;
}


x86 assembly (clang, -O0):
<replace_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10c0 <rename@plt>
cmp    $0xffffffff,%eax
jne    136e <replace_file+0x1ce>
mov    0x2df3(%rip),%rax
mov    (%rax),%rax
mov    0x2df1(%rip),%rcx
cmp    (%rcx),%rax
jne    133b <replace_file+0x19b>
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    122c <replace_file+0x8c>
mov    0x2dc3(%rip),%rax
mov    (%rax),%rdx
lea    0xdf1(%rip),%rdi
mov    $0x1d,%esi
lea    0xe6f(%rip),%rcx
call   1050 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1440 <replace_file+0x2a0>
mov    -0x10(%rbp),%rdi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    1278 <replace_file+0xd8>
mov    0x2d77(%rip),%rax
mov    (%rax),%rdx
lea    0xda5(%rip),%rdi
mov    $0x22,%esi
lea    0xe28(%rip),%rcx
call   1050 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1440 <replace_file+0x2a0>
mov    -0x18(%rbp),%rdi
mov    0x2d35(%rip),%rax
mov    (%rax),%esi
mov    0x2d6c(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x40(%rbp)
cmp    $0xffffffff,%eax
jne    12cd <replace_file+0x12d>
mov    0x2d22(%rip),%rax
mov    (%rax),%rdx
lea    0xd50(%rip),%rdi
mov    $0x27,%esi
lea    0xdd3(%rip),%rcx
call   1050 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1440 <replace_file+0x2a0>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%esi
mov    -0x24(%rbp),%ecx
xor    %edx,%edx
call   10a0 <copy_file_bytes@plt>
cmp    $0xffffffff,%eax
jne    12f2 <replace_file+0x152>
movl   $0xffffffff,-0x4(%rbp)
jmp    1440 <replace_file+0x2a0>
mov    -0x40(%rbp),%edi
call   1060 <close@plt>
mov    -0x3c(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rdi
call   1040 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1336 <replace_file+0x196>
mov    0x2cad(%rip),%rax
mov    (%rax),%rdx
lea    0xcdb(%rip),%rdi
mov    $0x32,%esi
lea    0xd63(%rip),%rcx
call   1050 <print_error@plt>
jmp    1369 <replace_file+0x1c9>
mov    0x2c86(%rip),%rax
mov    (%rax),%rdx
lea    0xcb4(%rip),%rdi
mov    $0x34,%esi
lea    0xd43(%rip),%rcx
call   1050 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1440 <replace_file+0x2a0>
jmp    136e <replace_file+0x1ce>
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rdi
mov    0x10(%rax),%esi
mov    0xc(%rax),%edx
call   1080 <chown@plt>
cmp    $0xffffffff,%eax
jne    13ac <replace_file+0x20c>
mov    0x2c37(%rip),%rax
mov    (%rax),%rdx
lea    0xc65(%rip),%rdi
mov    $0x3a,%esi
lea    0xcfb(%rip),%rcx
call   1050 <print_error@plt>
mov    -0x48(%rbp),%rax
mov    -0x18(%rbp),%rdi
mov    0x8(%rax),%esi
call   1090 <chmod@plt>
cmp    $0xffffffff,%eax
jne    13e7 <replace_file+0x247>
mov    0x2bfc(%rip),%rax
mov    (%rax),%rdx
lea    0xc2a(%rip),%rdi
mov    $0x3d,%esi
lea    0xcc6(%rip),%rcx
call   1050 <print_error@plt>
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%ecx
mov    %ecx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <utimensat@plt>
cmp    $0xffffffff,%eax
jne    1439 <replace_file+0x299>
mov    0x2baa(%rip),%rax
mov    (%rax),%rdx
lea    0xbd8(%rip),%rdi
mov    $0x42,%esi
lea    0xc7a(%rip),%rcx
call   1050 <print_error@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   10c0 <rename@plt>
cmp    $0xffffffff,%eax
je     1283 <replace_file+0xe3>
lea    0x50(%rsp),%rbx
mov    0xc(%rbx),%edx
mov    0x10(%rbx),%esi
mov    %r14,%rdi
call   1080 <chown@plt>
cmp    $0xffffffff,%eax
jne    11fa <replace_file+0x5a>
mov    0x2de9(%rip),%rax
mov    (%rax),%rdx
lea    0xe17(%rip),%rdi
lea    0xeb2(%rip),%rcx
mov    $0x3a,%esi
call   1050 <print_error@plt>
mov    0x8(%rbx),%esi
mov    %r14,%rdi
call   1090 <chmod@plt>
cmp    $0xffffffff,%eax
jne    122c <replace_file+0x8c>
mov    0x2db7(%rip),%rax
mov    (%rax),%rdx
lea    0xde5(%rip),%rdi
lea    0xe86(%rip),%rcx
mov    $0x3d,%esi
call   1050 <print_error@plt>
mov    0x4(%rbx),%eax
mov    %eax,0x8(%rsp)
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rdx
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %ecx,%ecx
call   1030 <utimensat@plt>
cmp    $0xffffffff,%eax
jne    13b7 <replace_file+0x217>
mov    0x2d65(%rip),%rax
mov    (%rax),%rdx
lea    0xd93(%rip),%rdi
lea    0xe3a(%rip),%rcx
mov    $0x42,%esi
call   1050 <print_error@plt>
jmp    13b7 <replace_file+0x217>
mov    0x2d3e(%rip),%r12
mov    (%r12),%rdx
mov    0x2d3b(%rip),%rax
cmp    (%rax),%rdx
jne    134f <replace_file+0x1af>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
je     1364 <replace_file+0x1c4>
mov    0x2d25(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     137d <replace_file+0x1dd>
mov    %eax,%ebp
mov    0x2ce1(%rip),%rax
mov    0x2d1a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     1396 <replace_file+0x1f6>
mov    %eax,%r15d
mov    0x1c(%rsp),%ecx
mov    %eax,%edi
mov    %ebp,%esi
xor    %edx,%edx
call   10a0 <copy_file_bytes@plt>
cmp    $0xffffffff,%eax
je     13b2 <replace_file+0x212>
mov    %r15d,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
call   1040 <unlink@plt>
cmp    $0xffffffff,%eax
jne    11c0 <replace_file+0x20>
mov    (%r12),%rdx
lea    0xcc7(%rip),%rdi
lea    0xd54(%rip),%rcx
mov    $0x32,%esi
call   1050 <print_error@plt>
jmp    11c0 <replace_file+0x20>
lea    0xcaa(%rip),%rdi
lea    0xd3e(%rip),%rcx
mov    $0x34,%esi
jmp    13ad <replace_file+0x20d>
mov    (%r12),%rdx
lea    0xc91(%rip),%rdi
lea    0xd14(%rip),%rcx
mov    $0x1d,%esi
jmp    13ad <replace_file+0x20d>
mov    (%r12),%rdx
lea    0xc78(%rip),%rdi
lea    0xd00(%rip),%rcx
mov    $0x22,%esi
jmp    13ad <replace_file+0x20d>
mov    (%r12),%rdx
lea    0xc5f(%rip),%rdi
lea    0xce7(%rip),%rcx
mov    $0x27,%esi
call   1050 <print_error@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { %struct.timespec, %struct.timespec, i32, i32, i32, i32 }
%struct.timespec = type { i32 }
@errno = global i64 0
@EXDEV = global i64 0
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/heads/master/common.c\00"
@.str.1 = [5 x i8] c"stat\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [7 x i8] c"unlink\00"
@.str.4 = [7 x i8] c"rename\00"
@.str.5 = [6 x i8] c"chown\00"
@.str.6 = [6 x i8] c"chmod\00"
@AT_FDCWD = global i32 0
@.str.7 = [10 x i8] c"utimensat\00"
define i32 @replace_file(i8* %0, i8* %1, %struct.stat* byval(%struct.stat) align 8 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [2 x %struct.timespec]
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
%11 = load i8*, i8** %5
%12 = load i8*, i8** %6
%13 = call i32 @rename(i8* %11, i8* %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %68
15: ; preds = %3
%16 = load i64, i64* @errno
%17 = load i64, i64* @EXDEV
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %64
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i32 @stat(i8* %20, %struct.stat* %8)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i64, i64* @errno
%25 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 29, i64 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %106
26: ; preds = %19
%27 = load i8*, i8** %5
%28 = load i32, i32* @O_RDONLY
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %9
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i64, i64* @errno
%33 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 34, i64 %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %106
34: ; preds = %26
%35 = load i8*, i8** %6
%36 = load i32, i32* @O_WRONLY
%37 = load i32, i32* @O_TRUNC
%38 = or i32 %36, %37
%39 = call i32 @open(i8* %35, i32 %38)
store i32 %39, i32* %10
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = load i64, i64* @errno
%43 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 39, i64 %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %106
44: ; preds = %34
%45 = load i32, i32* %10
%46 = load i32, i32* %9
%47 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 5
%48 = load i32, i32* %47
%49 = call i32 @copy_file_bytes(i32 %45, i32 %46, i32 0, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %52
51: ; preds = %44
store i32 -1, i32* %4
br label %106
52: ; preds = %44
%53 = load i32, i32* %10
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %9
%56 = call i32 @close(i32 %55)
%57 = load i8*, i8** %5
%58 = call i32 @unlink(i8* %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %63
60: ; preds = %52
%61 = load i64, i64* @errno
%62 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 50, i64 %61, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %63
63: ; preds = %60, %52
br label %67
64: ; preds = %15
%65 = load i64, i64* @errno
%66 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 52, i64 %65, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %4
br label %106
67: ; preds = %63
br label %68
68: ; preds = %67, %3
%69 = load i8*, i8** %6
%70 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 4
%71 = load i32, i32* %70
%72 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 3
%73 = load i32, i32* %72
%74 = call i32 @chown(i8* %69, i32 %71, i32 %73)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %68
%77 = load i64, i64* @errno
%78 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 58, i64 %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %79
79: ; preds = %76, %68
%80 = load i8*, i8** %6
%81 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 2
%82 = load i32, i32* %81
%83 = call i32 @chmod(i8* %80, i32 %82)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %88
85: ; preds = %79
%86 = load i64, i64* @errno
%87 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 61, i64 %86, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %88
88: ; preds = %85, %79
%89 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %7, i64 0, i64 0
%90 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 1
%91 = bitcast %struct.timespec* %89 to i8*
%92 = bitcast %struct.timespec* %90 to i8*
%93 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %7, i64 0, i64 1
%94 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%95 = bitcast %struct.timespec* %93 to i8*
%96 = bitcast %struct.timespec* %94 to i8*
%97 = load i32, i32* @AT_FDCWD
%98 = load i8*, i8** %6
%99 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %7, i64 0, i64 0
%100 = call i32 @utimensat(i32 %97, i8* %98, %struct.timespec* %99, i32 0)
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %105
102: ; preds = %88
%103 = load i64, i64* @errno
%104 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 66, i64 %103, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %105
105: ; preds = %102, %88
store i32 0, i32* %4
br label %106
106: ; preds = %105, %64, %51, %41, %31, %23
%107 = load i32, i32* %4
ret i32 %107
}

LLVM IR (-O2):
%struct.stat = type { %struct.timespec, %struct.timespec, i32, i32, i32, i32 }
%struct.timespec = type { i32 }
@errno = global i64 0
@EXDEV = global i64 0
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/heads/master/common.c\00"
@.str.1 = [5 x i8] c"stat\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [7 x i8] c"unlink\00"
@.str.4 = [7 x i8] c"rename\00"
@.str.5 = [6 x i8] c"chown\00"
@.str.6 = [6 x i8] c"chmod\00"
@AT_FDCWD = global i32 0
@.str.7 = [10 x i8] c"utimensat\00"
define i32 @replace_file(i8* nocapture %0, i8* %1, %struct.stat* nocapture byval(%struct.stat) align 8 %2) {
%4 = alloca [2 x %struct.timespec]
%5 = alloca %struct.stat
%6 = bitcast [2 x %struct.timespec]* %4 to i8*
%7 = tail call i32 @rename(i8* %0, i8* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %52
9: ; preds = %3
%10 = load i64, i64* @errno
%11 = load i64, i64* @EXDEV
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %50
13: ; preds = %9
%14 = bitcast %struct.stat* %5 to i8*
%15 = call i32 @stat(i8* %0, %struct.stat* %5)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i64, i64* @errno
%19 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 29, i64 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %85
20: ; preds = %13
%21 = load i32, i32* @O_RDONLY
%22 = tail call i32 @open(i8* %0, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i64, i64* @errno
%26 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 34, i64 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %85
27: ; preds = %20
%28 = load i32, i32* @O_WRONLY
%29 = load i32, i32* @O_TRUNC
%30 = or i32 %29, %28
%31 = tail call i32 @open(i8* %1, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = load i64, i64* @errno
%35 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 39, i64 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %85
36: ; preds = %27
%37 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 5
%38 = load i32, i32* %37
%39 = tail call i32 @copy_file_bytes(i32 %31, i32 %22, i32 0, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %84, label %41
41: ; preds = %36
%42 = tail call i32 @close(i32 %31)
%43 = tail call i32 @close(i32 %22)
%44 = tail call i32 @unlink(i8* %0)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i64, i64* @errno
%48 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 50, i64 %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %41, %46
br label %52
50: ; preds = %9
%51 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 52, i64 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %85
52: ; preds = %49, %3
%53 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 4
%54 = load i32, i32* %53
%55 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 3
%56 = load i32, i32* %55
%57 = tail call i32 @chown(i8* %1, i32 %54, i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %52
%60 = load i64, i64* @errno
%61 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 58, i64 %60, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %62
62: ; preds = %59, %52
%63 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 2
%64 = load i32, i32* %63
%65 = tail call i32 @chmod(i8* %1, i32 %64)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %70
67: ; preds = %62
%68 = load i64, i64* @errno
%69 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 61, i64 %68, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %70
70: ; preds = %67, %62
%71 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0
%72 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1, i32 0
%73 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 0, i32 0
%74 = load i32, i32* %72
store i32 %74, i32* %73
%75 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0, i32 0
%76 = getelementptr inbounds [2 x %struct.timespec], [2 x %struct.timespec]* %4, i64 0, i64 1, i32 0
%77 = load i32, i32* %75
store i32 %77, i32* %76
%78 = load i32, i32* @AT_FDCWD
%79 = call i32 @utimensat(i32 %78, i8* %1, %struct.timespec* %71, i32 0)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %85
81: ; preds = %70
%82 = load i64, i64* @errno
%83 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 66, i64 %82, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %85
84: ; preds = %36
br label %85
85: ; preds = %70, %81, %84, %17, %24, %33, %50
%86 = phi i32 [ -1, %50 ], [ -1, %33 ], [ -1, %24 ], [ -1, %17 ], [ -1, %84 ], [ 0, %81 ], [ 0, %70 ]
ret i32 %86
}