#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 timeval {
  int tv_usec;
};
struct stat {
  scalar_t__ st_dev;
  scalar_t__ st_ino;
  scalar_t__ st_size;
  scalar_t__ st_mtime;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int ENOENT;
int EOPNOTSUPP;
int EPERM;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int link(char *, char *);
char *malloc(int);
scalar_t__ memcmp(char *, char *, int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int rename(char *, char *);
int snprintf(char *, int, char *, char *, unsigned int);
int stat(char *, struct stat *);
int strlen(char *);
int /*<<< orphan*/ unlink(char *);
int maybe_relink(char *src, char *dst, int careful) {
  int len, rc, saved_errno;
  char *tempname;
  struct stat srcstat, dststat, tempstat;
  struct timeval now;
  rc = stat(src, &srcstat);
  if (rc < 0) {
    if (errno == ENOENT)
      return -2;
    else
      return -1;
  }
  rc = stat(dst, &dststat);
  if (rc < 0)
    return -1;
  if (!S_ISREG(srcstat.st_mode) || !S_ISREG(dststat.st_mode)) {
    return -4;
  }
  if (srcstat.st_dev != dststat.st_dev) {
    return -2;
  }
  if (srcstat.st_ino == dststat.st_ino)
    return 0;
  if (srcstat.st_size != dststat.st_size)
    return -2;
  gettimeofday(&now, NULL);
  rc = strlen(dst) + 6;
  tempname = malloc(rc);
  if (tempname == NULL)
    return -1;
  len = snprintf(tempname, rc, "%s-%04x", dst,
                 ((unsigned)(now.tv_usec ^ (now.tv_usec >> 16))) & 0xFFFF);
  if (len < 0 || len >= rc) {
    free(tempname);
    return -4;
  }
  rc = link(src, tempname);
  if (rc < 0) {
    goto fail;
  }
  rc = stat(tempname, &tempstat);
  if (rc < 0)
    goto fail;
  if (tempstat.st_ino != srcstat.st_ino ||
      tempstat.st_size != srcstat.st_size ||
      tempstat.st_mtime != srcstat.st_mtime) {
    unlink(tempname);
    free(tempname);
    return -3;
  }
  if (careful) {
    int fd1, fd2, i, rc1, rc2;
    char buf1[8192], buf2[8192];
    fd1 = open(tempname, O_RDONLY);
    if (fd1 < 0)
      goto fail;
    fd2 = open(dst, O_RDONLY);
    if (fd2 < 0) {
      close(fd1);
      goto fail;
    }
    i = 0;
    while (i < tempstat.st_size) {
      rc1 = read(fd1, buf1, 8192);
      if (rc1 < 0) {
        close(fd1);
        close(fd2);
        goto fail;
      }
      rc2 = read(fd2, buf2, 8192);
      if (rc2 < 0) {
        close(fd1);
        close(fd2);
        goto fail;
      }
      if (rc1 == 0 || rc1 != rc2 || memcmp(buf1, buf2, rc1) != 0) {
        close(fd1);
        close(fd2);
        unlink(tempname);
        free(tempname);
        return -2;
      }
      i += rc1;
    }
    close(fd1);
    close(fd2);
  }
  rc = rename(tempname, dst);
  if (rc < 0)
    goto fail;
  free(tempname);
  return 1;
fail:
  saved_errno = errno;
  unlink(tempname);
  free(tempname);
  errno = saved_errno;
  if (errno == EPERM || errno == EOPNOTSUPP)
    return -2;
  return -1;
}


x86 assembly (clang, -O0):
<maybe_relink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40d0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   10b0 <stat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1240 <maybe_relink+0x60>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%eax
jne    1234 <maybe_relink+0x54>
movl   $0xfffffffe,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
movl   $0xffffffff,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   10b0 <stat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1266 <maybe_relink+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
mov    -0x38(%rbp),%edi
call   10c0 <S_ISREG@plt>
cmp    $0x0,%eax
je     1288 <maybe_relink+0xa8>
mov    -0x60(%rbp),%edi
call   10c0 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1294 <maybe_relink+0xb4>
movl   $0xfffffffc,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
mov    -0x58(%rbp),%rax
cmp    -0x80(%rbp),%rax
je     12ae <maybe_relink+0xce>
movl   $0xfffffffe,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
mov    -0x50(%rbp),%rax
cmp    -0x78(%rbp),%rax
jne    12c8 <maybe_relink+0xe8>
movl   $0x0,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
mov    -0x48(%rbp),%rax
cmp    -0x70(%rbp),%rax
je     12e2 <maybe_relink+0x102>
movl   $0xfffffffe,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
lea    -0xb0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x6,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   10d0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1324 <maybe_relink+0x144>
movl   $0xffffffff,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0xb0(%rbp),%r8d
mov    -0xb0(%rbp),%eax
sar    $0x10,%eax
xor    %eax,%r8d
and    $0xffff,%r8d
lea    0xcb0(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     136e <maybe_relink+0x18e>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     1383 <maybe_relink+0x1a3>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1100 <link@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    13a2 <maybe_relink+0x1c2>
jmp    15fd <maybe_relink+0x41d>
mov    -0x30(%rbp),%rdi
lea    -0xa8(%rbp),%rsi
call   10b0 <stat@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    13c4 <maybe_relink+0x1e4>
jmp    15fd <maybe_relink+0x41d>
mov    -0xa0(%rbp),%rax
cmp    -0x50(%rbp),%rax
jne    13f7 <maybe_relink+0x217>
mov    -0x98(%rbp),%rax
cmp    -0x48(%rbp),%rax
jne    13f7 <maybe_relink+0x217>
mov    -0x90(%rbp),%rax
cmp    -0x40(%rbp),%rax
je     1415 <maybe_relink+0x235>
mov    -0x30(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
cmpl   $0x0,-0x1c(%rbp)
je     15c9 <maybe_relink+0x3e9>
mov    -0x30(%rbp),%rdi
mov    0x2bbe(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0x0,-0xb4(%rbp)
jge    1449 <maybe_relink+0x269>
jmp    15fd <maybe_relink+0x41d>
mov    -0x18(%rbp),%rdi
mov    0x2b94(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0xb8(%rbp)
cmpl   $0x0,-0xb8(%rbp)
jge    147e <maybe_relink+0x29e>
mov    -0xb4(%rbp),%edi
call   1080 <close@plt>
jmp    15fd <maybe_relink+0x41d>
movl   $0x0,-0xbc(%rbp)
movslq -0xbc(%rbp),%rax
cmp    -0x98(%rbp),%rax
jge    15b3 <maybe_relink+0x3d3>
mov    -0xb4(%rbp),%edi
lea    -0x20d0(%rbp),%rsi
mov    $0x2000,%edx
call   1090 <read@plt>
mov    %eax,-0xc0(%rbp)
cmpl   $0x0,-0xc0(%rbp)
jge    14e1 <maybe_relink+0x301>
mov    -0xb4(%rbp),%edi
call   1080 <close@plt>
mov    -0xb8(%rbp),%edi
call   1080 <close@plt>
jmp    15fd <maybe_relink+0x41d>
mov    -0xb8(%rbp),%edi
lea    -0x40d0(%rbp),%rsi
mov    $0x2000,%edx
call   1090 <read@plt>
mov    %eax,-0xc4(%rbp)
cmpl   $0x0,-0xc4(%rbp)
jge    1526 <maybe_relink+0x346>
mov    -0xb4(%rbp),%edi
call   1080 <close@plt>
mov    -0xb8(%rbp),%edi
call   1080 <close@plt>
jmp    15fd <maybe_relink+0x41d>
cmpl   $0x0,-0xc0(%rbp)
je     1568 <maybe_relink+0x388>
mov    -0xc0(%rbp),%eax
cmp    -0xc4(%rbp),%eax
jne    1568 <maybe_relink+0x388>
lea    -0x20d0(%rbp),%rdi
lea    -0x40d0(%rbp),%rsi
mov    -0xc0(%rbp),%edx
call   10a0 <memcmp@plt>
cmp    $0x0,%rax
je     159c <maybe_relink+0x3bc>
mov    -0xb4(%rbp),%edi
call   1080 <close@plt>
mov    -0xb8(%rbp),%edi
call   1080 <close@plt>
mov    -0x30(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
mov    -0xc0(%rbp),%eax
add    -0xbc(%rbp),%eax
mov    %eax,-0xbc(%rbp)
jmp    1488 <maybe_relink+0x2a8>
mov    -0xb4(%rbp),%edi
call   1080 <close@plt>
mov    -0xb8(%rbp),%edi
call   1080 <close@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10f0 <rename@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    15e8 <maybe_relink+0x408>
jmp    15fd <maybe_relink+0x41d>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
mov    0x29cc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%ecx
mov    0x29ab(%rip),%rax
mov    %ecx,(%rax)
mov    0x29a2(%rip),%rax
mov    (%rax),%eax
mov    0x2981(%rip),%rcx
cmp    (%rcx),%eax
je     1657 <maybe_relink+0x477>
mov    0x298a(%rip),%rax
mov    (%rax),%eax
mov    0x2989(%rip),%rcx
cmp    (%rcx),%eax
jne    1663 <maybe_relink+0x483>
movl   $0xfffffffe,-0x4(%rbp)
jmp    166a <maybe_relink+0x48a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maybe_relink>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4098,%rsp
mov    %edx,%r15d
mov    %rsi,%r12
mov    %rdi,%rbp
lea    0x18(%rsp),%rsi
call   10b0 <stat@plt>
test   %eax,%eax
js     143b <maybe_relink+0x25b>
lea    0x40(%rsp),%rsi
mov    %r12,%rdi
call   10b0 <stat@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     145b <maybe_relink+0x27b>
mov    0x38(%rsp),%edi
call   10c0 <S_ISREG@plt>
mov    $0xfffffffc,%ebx
test   %eax,%eax
je     145b <maybe_relink+0x27b>
mov    0x60(%rsp),%edi
call   10c0 <S_ISREG@plt>
test   %eax,%eax
je     145b <maybe_relink+0x27b>
mov    0x18(%rsp),%rax
cmp    0x40(%rsp),%rax
jne    1456 <maybe_relink+0x276>
mov    0x20(%rsp),%r14
xor    %ebx,%ebx
cmp    0x48(%rsp),%r14
je     145b <maybe_relink+0x27b>
mov    0x28(%rsp),%rax
cmp    0x50(%rsp),%rax
jne    1456 <maybe_relink+0x276>
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%r13d
add    $0x6,%r13d
mov    %r13d,%edi
call   10d0 <malloc@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     145b <maybe_relink+0x27b>
mov    %rax,%rcx
mov    0x8(%rsp),%eax
movzwl %ax,%r8d
shr    $0x10,%eax
xor    %eax,%r8d
lea    0xd33(%rip),%rdx
mov    %rcx,%rbx
mov    %rcx,%rdi
mov    %r13d,%esi
mov    %r12,%rcx
call   1060 <snprintf@plt>
test   %eax,%eax
js     146f <maybe_relink+0x28f>
cmp    %r13d,%eax
jge    146f <maybe_relink+0x28f>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1100 <link@plt>
test   %eax,%eax
js     14ae <maybe_relink+0x2ce>
lea    0x68(%rsp),%rsi
mov    %rbx,%rdi
call   10b0 <stat@plt>
test   %eax,%eax
js     14ae <maybe_relink+0x2ce>
cmp    %r14,0x70(%rsp)
mov    0x10(%rsp),%rbp
jne    147e <maybe_relink+0x29e>
cmp    %rbp,0x78(%rsp)
jne    147e <maybe_relink+0x29e>
mov    0x80(%rsp),%rax
cmp    0x30(%rsp),%rax
jne    147e <maybe_relink+0x29e>
test   %r15d,%r15d
je     1419 <maybe_relink+0x239>
mov    %rbx,%rdi
mov    0x2c90(%rip),%rbx
mov    (%rbx),%esi
mov    %rdi,(%rsp)
call   10e0 <open@plt>
test   %eax,%eax
js     14aa <maybe_relink+0x2ca>
mov    %eax,%r14d
mov    (%rbx),%esi
mov    %r12,%rdi
call   10e0 <open@plt>
test   %eax,%eax
js     1495 <maybe_relink+0x2b5>
mov    %eax,%r15d
test   %rbp,%rbp
jle    1405 <maybe_relink+0x225>
xor    %ebx,%ebx
lea    0x2090(%rsp),%rbp
mov    %r14d,%edi
lea    0x90(%rsp),%rsi
mov    $0x2000,%edx
call   1090 <read@plt>
test   %eax,%eax
js     149a <maybe_relink+0x2ba>
mov    %eax,%r13d
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x2000,%edx
call   1090 <read@plt>
test   %eax,%eax
js     149a <maybe_relink+0x2ba>
test   %r13d,%r13d
je     14ed <maybe_relink+0x30d>
cmp    %eax,%r13d
jne    14ed <maybe_relink+0x30d>
lea    0x90(%rsp),%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
call   10a0 <memcmp@plt>
test   %rax,%rax
jne    14ed <maybe_relink+0x30d>
add    %r13d,%ebx
movslq %ebx,%rax
cmp    %rax,0x10(%rsp)
jg     1392 <maybe_relink+0x1b2>
mov    %r14d,%edi
call   1080 <close@plt>
mov    %r15d,%edi
call   1080 <close@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   10f0 <rename@plt>
test   %eax,%eax
js     14ae <maybe_relink+0x2ce>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%ebx
jmp    145b <maybe_relink+0x27b>
mov    0x2b8e(%rip),%rax
mov    (%rax),%eax
mov    0x2b75(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%eax
sete   %bl
not    %ebx
jmp    145b <maybe_relink+0x27b>
mov    $0xfffffffe,%ebx
mov    %ebx,%eax
add    $0x4098,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xfffffffc,%ebx
jmp    145b <maybe_relink+0x27b>
mov    %rbx,%rdi
call   1040 <unlink@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xfffffffd,%ebx
jmp    145b <maybe_relink+0x27b>
mov    %r14d,%edi
jmp    14a5 <maybe_relink+0x2c5>
mov    %r14d,%edi
call   1080 <close@plt>
mov    %r15d,%edi
call   1080 <close@plt>
mov    (%rsp),%rbx
mov    0x2b1b(%rip),%r14
mov    (%r14),%ebp
mov    %rbx,%rdi
call   1040 <unlink@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,(%r14)
mov    0x2ae6(%rip),%rax
cmp    (%rax),%ebp
sete   %al
mov    0x2afa(%rip),%rcx
cmp    (%rcx),%ebp
sete   %cl
or     %al,%cl
movzbl %cl,%ebx
jmp    1452 <maybe_relink+0x272>
mov    %r14d,%edi
call   1080 <close@plt>
mov    %r15d,%edi
call   1080 <close@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1040 <unlink@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xfffffffe,%ebx
jmp    145b <maybe_relink+0x27b>

LLVM IR (-O0):
%struct.stat = type { i64, i64, i64, i64, i32 }
%struct.timeval = type { i32 }
@errno = global i32 0
@ENOENT = global i32 0
@.str = [8 x i8] c"%s-%04x\00"
@O_RDONLY = global i32 0
@EPERM = global i32 0
@EOPNOTSUPP = global i32 0
define i32 @maybe_relink(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca %struct.stat
%13 = alloca %struct.stat
%14 = alloca %struct.stat
%15 = alloca %struct.timeval
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca [8192 x i8]
%22 = alloca [8192 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%23 = load i8*, i8** %5
%24 = call i32 @stat(i8* %23, %struct.stat* %12)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %3
%28 = load i32, i32* @errno
%29 = load i32, i32* @ENOENT
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 -2, i32* %4
br label %243
32: ; preds = %27
store i32 -1, i32* %4
br label %243
33: ; preds = %3
%34 = load i8*, i8** %6
%35 = call i32 @stat(i8* %34, %struct.stat* %13)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 -1, i32* %4
br label %243
39: ; preds = %33
%40 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 4
%41 = load i32, i32* %40
%42 = call i32 @S_ISREG(i32 %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 4
%46 = load i32, i32* %45
%47 = call i32 @S_ISREG(i32 %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %44, %39
store i32 -4, i32* %4
br label %243
50: ; preds = %44
%51 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%52 = load i64, i64* %51
%53 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%54 = load i64, i64* %53
%55 = icmp ne i64 %52, %54
br i1 %55, label %56, label %57
56: ; preds = %50
store i32 -2, i32* %4
br label %243
57: ; preds = %50
%58 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 1
%59 = load i64, i64* %58
%60 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%61 = load i64, i64* %60
%62 = icmp eq i64 %59, %61
br i1 %62, label %63, label %64
63: ; preds = %57
store i32 0, i32* %4
br label %243
64: ; preds = %57
%65 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 2
%66 = load i64, i64* %65
%67 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 2
%68 = load i64, i64* %67
%69 = icmp ne i64 %66, %68
br i1 %69, label %70, label %71
70: ; preds = %64
store i32 -2, i32* %4
br label %243
71: ; preds = %64
%72 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
%73 = load i8*, i8** %6
%74 = call i32 @strlen(i8* %73)
%75 = add nsw i32 %74, 6
store i32 %75, i32* %9
%76 = load i32, i32* %9
%77 = call i8* @malloc(i32 %76)
store i8* %77, i8** %11
%78 = load i8*, i8** %11
%79 = icmp eq i8* %78, null
br i1 %79, label %80, label %81
80: ; preds = %71
store i32 -1, i32* %4
br label %243
81: ; preds = %71
%82 = load i8*, i8** %11
%83 = load i32, i32* %9
%84 = load i8*, i8** %6
%85 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%86 = load i32, i32* %85
%87 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%88 = load i32, i32* %87
%89 = ashr i32 %88, 16
%90 = xor i32 %86, %89
%91 = and i32 %90, 65535
%92 = call i32 @snprintf(i8* %82, i32 %83, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %84, i32 %91)
store i32 %92, i32* %8
%93 = load i32, i32* %8
%94 = icmp slt i32 %93, 0
br i1 %94, label %99, label %95
95: ; preds = %81
%96 = load i32, i32* %8
%97 = load i32, i32* %9
%98 = icmp sge i32 %96, %97
br i1 %98, label %99, label %102
99: ; preds = %95, %81
%100 = load i8*, i8** %11
%101 = call i32 @free(i8* %100)
store i32 -4, i32* %4
br label %243
102: ; preds = %95
%103 = load i8*, i8** %5
%104 = load i8*, i8** %11
%105 = call i32 @link(i8* %103, i8* %104)
store i32 %105, i32* %9
%106 = load i32, i32* %9
%107 = icmp slt i32 %106, 0
br i1 %107, label %108, label %109
108: ; preds = %102
br label %227
109: ; preds = %102
%110 = load i8*, i8** %11
%111 = call i32 @stat(i8* %110, %struct.stat* %14)
store i32 %111, i32* %9
%112 = load i32, i32* %9
%113 = icmp slt i32 %112, 0
br i1 %113, label %114, label %115
114: ; preds = %109
br label %227
115: ; preds = %109
%116 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 1
%117 = load i64, i64* %116
%118 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 1
%119 = load i64, i64* %118
%120 = icmp ne i64 %117, %119
br i1 %120, label %133, label %121
121: ; preds = %115
%122 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 2
%123 = load i64, i64* %122
%124 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 2
%125 = load i64, i64* %124
%126 = icmp ne i64 %123, %125
br i1 %126, label %133, label %127
127: ; preds = %121
%128 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 3
%129 = load i64, i64* %128
%130 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 3
%131 = load i64, i64* %130
%132 = icmp ne i64 %129, %131
br i1 %132, label %133, label %138
133: ; preds = %127, %121, %115
%134 = load i8*, i8** %11
%135 = call i32 @unlink(i8* %134)
%136 = load i8*, i8** %11
%137 = call i32 @free(i8* %136)
store i32 -3, i32* %4
br label %243
138: ; preds = %127
%139 = load i32, i32* %7
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %217
141: ; preds = %138
%142 = load i8*, i8** %11
%143 = load i32, i32* @O_RDONLY
%144 = call i32 @open(i8* %142, i32 %143)
store i32 %144, i32* %16
%145 = load i32, i32* %16
%146 = icmp slt i32 %145, 0
br i1 %146, label %147, label %148
147: ; preds = %141
br label %227
148: ; preds = %141
%149 = load i8*, i8** %6
%150 = load i32, i32* @O_RDONLY
%151 = call i32 @open(i8* %149, i32 %150)
store i32 %151, i32* %17
%152 = load i32, i32* %17
%153 = icmp slt i32 %152, 0
br i1 %153, label %154, label %157
154: ; preds = %148
%155 = load i32, i32* %16
%156 = call i32 @close(i32 %155)
br label %227
157: ; preds = %148
store i32 0, i32* %18
br label %158
158: ; preds = %208, %157
%159 = load i32, i32* %18
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 2
%162 = load i64, i64* %161
%163 = icmp slt i64 %160, %162
br i1 %163, label %164, label %212
164: ; preds = %158
%165 = load i32, i32* %16
%166 = getelementptr inbounds [8192 x i8], [8192 x i8]* %21, i64 0, i64 0
%167 = call i32 @read(i32 %165, i8* %166, i32 8192)
store i32 %167, i32* %19
%168 = load i32, i32* %19
%169 = icmp slt i32 %168, 0
br i1 %169, label %170, label %175
170: ; preds = %164
%171 = load i32, i32* %16
%172 = call i32 @close(i32 %171)
%173 = load i32, i32* %17
%174 = call i32 @close(i32 %173)
br label %227
175: ; preds = %164
%176 = load i32, i32* %17
%177 = getelementptr inbounds [8192 x i8], [8192 x i8]* %22, i64 0, i64 0
%178 = call i32 @read(i32 %176, i8* %177, i32 8192)
store i32 %178, i32* %20
%179 = load i32, i32* %20
%180 = icmp slt i32 %179, 0
br i1 %180, label %181, label %186
181: ; preds = %175
%182 = load i32, i32* %16
%183 = call i32 @close(i32 %182)
%184 = load i32, i32* %17
%185 = call i32 @close(i32 %184)
br label %227
186: ; preds = %175
%187 = load i32, i32* %19
%188 = icmp eq i32 %187, 0
br i1 %188, label %199, label %189
189: ; preds = %186
%190 = load i32, i32* %19
%191 = load i32, i32* %20
%192 = icmp ne i32 %190, %191
br i1 %192, label %199, label %193
193: ; preds = %189
%194 = getelementptr inbounds [8192 x i8], [8192 x i8]* %21, i64 0, i64 0
%195 = getelementptr inbounds [8192 x i8], [8192 x i8]* %22, i64 0, i64 0
%196 = load i32, i32* %19
%197 = call i64 @memcmp(i8* %194, i8* %195, i32 %196)
%198 = icmp ne i64 %197, 0
br i1 %198, label %199, label %208
199: ; preds = %193, %189, %186
%200 = load i32, i32* %16
%201 = call i32 @close(i32 %200)
%202 = load i32, i32* %17
%203 = call i32 @close(i32 %202)
%204 = load i8*, i8** %11
%205 = call i32 @unlink(i8* %204)
%206 = load i8*, i8** %11
%207 = call i32 @free(i8* %206)
store i32 -2, i32* %4
br label %243
208: ; preds = %193
%209 = load i32, i32* %19
%210 = load i32, i32* %18
%211 = add nsw i32 %210, %209
store i32 %211, i32* %18
br label %158
212: ; preds = %158
%213 = load i32, i32* %16
%214 = call i32 @close(i32 %213)
%215 = load i32, i32* %17
%216 = call i32 @close(i32 %215)
br label %217
217: ; preds = %212, %138
%218 = load i8*, i8** %11
%219 = load i8*, i8** %6
%220 = call i32 @rename(i8* %218, i8* %219)
store i32 %220, i32* %9
%221 = load i32, i32* %9
%222 = icmp slt i32 %221, 0
br i1 %222, label %223, label %224
223: ; preds = %217
br label %227
224: ; preds = %217
%225 = load i8*, i8** %11
%226 = call i32 @free(i8* %225)
store i32 1, i32* %4
br label %243
227: ; preds = %223, %181, %170, %154, %147, %114, %108
%228 = load i32, i32* @errno
store i32 %228, i32* %10
%229 = load i8*, i8** %11
%230 = call i32 @unlink(i8* %229)
%231 = load i8*, i8** %11
%232 = call i32 @free(i8* %231)
%233 = load i32, i32* %10
store i32 %233, i32* @errno
%234 = load i32, i32* @errno
%235 = load i32, i32* @EPERM
%236 = icmp eq i32 %234, %235
br i1 %236, label %241, label %237
237: ; preds = %227
%238 = load i32, i32* @errno
%239 = load i32, i32* @EOPNOTSUPP
%240 = icmp eq i32 %238, %239
br i1 %240, label %241, label %242
241: ; preds = %237, %227
store i32 -2, i32* %4
br label %243
242: ; preds = %237
store i32 -1, i32* %4
br label %243
243: ; preds = %242, %241, %224, %199, %133, %99, %80, %70, %63, %56, %49, %38, %32, %31
%244 = load i32, i32* %4
ret i32 %244
}

LLVM IR (-O2):
%struct.stat = type { i64, i64, i64, i64, i32 }
%struct.timeval = type { i32 }
@errno = global i32 0
@ENOENT = global i32 0
@.str = [8 x i8] c"%s-%04x\00"
@O_RDONLY = global i32 0
@EPERM = global i32 0
@EOPNOTSUPP = global i32 0
define i32 @maybe_relink(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.stat
%5 = alloca %struct.stat
%6 = alloca %struct.stat
%7 = alloca %struct.timeval
%8 = alloca [8192 x i8]
%9 = alloca [8192 x i8]
%10 = bitcast %struct.stat* %4 to i8*
%11 = bitcast %struct.stat* %5 to i8*
%12 = bitcast %struct.stat* %6 to i8*
%13 = bitcast %struct.timeval* %7 to i8*
%14 = call i32 @stat(i8* %0, %struct.stat* %4)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %3
%17 = load i32, i32* @errno
%18 = load i32, i32* @ENOENT
%19 = icmp eq i32 %17, %18
%20 = select i1 %19, i32 -2, i32 -1
br label %157
21: ; preds = %3
%22 = call i32 @stat(i8* %1, %struct.stat* %5)
%23 = icmp slt i32 %22, 0
br i1 %23, label %157, label %24
24: ; preds = %21
%25 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 4
%26 = load i32, i32* %25
%27 = tail call i32 @S_ISREG(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %157, label %29
29: ; preds = %24
%30 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 4
%31 = load i32, i32* %30
%32 = tail call i32 @S_ISREG(i32 %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %157, label %34
34: ; preds = %29
%35 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%36 = load i64, i64* %35
%37 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%38 = load i64, i64* %37
%39 = icmp eq i64 %36, %38
br i1 %39, label %40, label %157
40: ; preds = %34
%41 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%42 = load i64, i64* %41
%43 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 1
%44 = load i64, i64* %43
%45 = icmp eq i64 %42, %44
br i1 %45, label %157, label %46
46: ; preds = %40
%47 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 2
%48 = load i64, i64* %47
%49 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 2
%50 = load i64, i64* %49
%51 = icmp eq i64 %48, %50
br i1 %51, label %52, label %157
52: ; preds = %46
%53 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%54 = tail call i32 @strlen(i8* %1)
%55 = add nsw i32 %54, 6
%56 = tail call i8* @malloc(i32 %55)
%57 = icmp eq i8* %56, null
br i1 %57, label %157, label %58
58: ; preds = %52
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%60 = load i32, i32* %59
%61 = lshr i32 %60, 16
%62 = and i32 %60, 65535
%63 = xor i32 %62, %61
%64 = tail call i32 @snprintf(i8* %56, i32 %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %63)
%65 = icmp sgt i32 %64, -1
%66 = icmp slt i32 %64, %55
%67 = and i1 %65, %66
br i1 %67, label %70, label %68
68: ; preds = %58
%69 = tail call i32 @free(i8* %56)
br label %157
70: ; preds = %58
%71 = tail call i32 @link(i8* %0, i8* %56)
%72 = icmp slt i32 %71, 0
br i1 %72, label %147, label %73
73: ; preds = %70
%74 = call i32 @stat(i8* %56, %struct.stat* %6)
%75 = icmp slt i32 %74, 0
br i1 %75, label %147, label %76
76: ; preds = %73
%77 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 1
%78 = load i64, i64* %77
%79 = icmp eq i64 %78, %42
%80 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 2
%81 = load i64, i64* %80
%82 = icmp eq i64 %81, %48
%83 = select i1 %79, i1 %82, i1 false
br i1 %83, label %84, label %90
84: ; preds = %76
%85 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 3
%86 = load i64, i64* %85
%87 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 3
%88 = load i64, i64* %87
%89 = icmp eq i64 %86, %88
br i1 %89, label %93, label %90
90: ; preds = %84, %76
%91 = tail call i32 @unlink(i8* %56)
%92 = tail call i32 @free(i8* %56)
br label %157
93: ; preds = %84
%94 = icmp eq i32 %2, 0
br i1 %94, label %142, label %95
95: ; preds = %93
%96 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%97 = getelementptr inbounds [8192 x i8], [8192 x i8]* %9, i64 0, i64 0
%98 = load i32, i32* @O_RDONLY
%99 = tail call i32 @open(i8* %56, i32 %98)
%100 = icmp slt i32 %99, 0
br i1 %100, label %138, label %101
101: ; preds = %95
%102 = load i32, i32* @O_RDONLY
%103 = tail call i32 @open(i8* %1, i32 %102)
%104 = icmp slt i32 %103, 0
br i1 %104, label %107, label %105
105: ; preds = %101
%106 = icmp sgt i64 %48, 0
br i1 %106, label %112, label %139
107: ; preds = %101
%108 = tail call i32 @close(i32 %99)
br label %138
109: ; preds = %129
%110 = sext i32 %132 to i64
%111 = icmp sgt i64 %48, %110
br i1 %111, label %112, label %139
112: ; preds = %105, %109
%113 = phi i32 [ %132, %109 ], [ 0, %105 ]
%114 = call i32 @read(i32 %99, i8* %96, i32 8192)
%115 = icmp slt i32 %114, 0
br i1 %115, label %116, label %119
116: ; preds = %112
%117 = call i32 @close(i32 %99)
%118 = call i32 @close(i32 %103)
br label %138
119: ; preds = %112
%120 = call i32 @read(i32 %103, i8* %97, i32 8192)
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %125
122: ; preds = %119
%123 = call i32 @close(i32 %99)
%124 = call i32 @close(i32 %103)
br label %138
125: ; preds = %119
%126 = icmp ne i32 %114, 0
%127 = icmp eq i32 %114, %120
%128 = and i1 %126, %127
br i1 %128, label %129, label %133
129: ; preds = %125
%130 = call i64 @memcmp(i8* %96, i8* %97, i32 %114)
%131 = icmp eq i64 %130, 0
%132 = add nsw i32 %114, %113
br i1 %131, label %109, label %133
133: ; preds = %125, %129
%134 = call i32 @close(i32 %99)
%135 = call i32 @close(i32 %103)
%136 = call i32 @unlink(i8* %56)
%137 = call i32 @free(i8* %56)
br label %157
138: ; preds = %107, %116, %122, %95
br label %147
139: ; preds = %109, %105
%140 = call i32 @close(i32 %99)
%141 = call i32 @close(i32 %103)
br label %142
142: ; preds = %139, %93
%143 = call i32 @rename(i8* %56, i8* %1)
%144 = icmp slt i32 %143, 0
br i1 %144, label %147, label %145
145: ; preds = %142
%146 = call i32 @free(i8* %56)
br label %157
147: ; preds = %138, %142, %73, %70
%148 = load i32, i32* @errno
%149 = call i32 @unlink(i8* %56)
%150 = call i32 @free(i8* %56)
store i32 %148, i32* @errno
%151 = load i32, i32* @EPERM
%152 = icmp eq i32 %148, %151
%153 = load i32, i32* @EOPNOTSUPP
%154 = icmp eq i32 %148, %153
%155 = select i1 %152, i1 true, i1 %154
%156 = select i1 %155, i32 -2, i32 -1
br label %157
157: ; preds = %133, %147, %52, %46, %40, %34, %24, %29, %21, %16, %145, %90, %68
%158 = phi i32 [ -4, %68 ], [ -3, %90 ], [ 1, %145 ], [ %20, %16 ], [ -1, %21 ], [ -4, %29 ], [ -4, %24 ], [ -2, %34 ], [ 0, %40 ], [ -2, %46 ], [ -1, %52 ], [ %156, %147 ], [ -2, %133 ]
ret i32 %158
}