#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 {
  int /*<<< orphan*/ st_nlink;
  int /*<<< orphan*/ st_ino;
  int /*<<< orphan*/ st_dev;
};
typedef int /*<<< orphan*/ kData;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errx(int, char *, char const *, ...);
scalar_t__ link(char const *, char const *);
int open(char const *, int, ...);
scalar_t__ read(int, char *, int);
scalar_t__ stat(char const *, struct stat *);
scalar_t__ strcmp(char *, char const *);
scalar_t__ unlink(char const *);
scalar_t__ write(int, char const *, int);
int main(int argc, char **argv) {
  const char kOldPath[] = "old.txt";
  int fd = open(kOldPath, O_RDWR | O_CREAT | O_TRUNC, 0600);
  if (fd < 0) {
    errx(1, "open(%s) failed", kOldPath);
  }
  const char kData[] = "some random content";
  if (write(fd, kData, sizeof(kData)) < 0) {
    err(1, "write failed");
  }
  close(fd);
  struct stat old_stat;
  if (stat(kOldPath, &old_stat)) {
    errx(1, "stat(%s) failed", kOldPath);
  }
  const char kNewPath[] = "new.txt";
  if (link(kOldPath, kNewPath)) {
    errx(1, "link(%s, %s) failed", kOldPath, kNewPath);
  }
  struct stat new_stat;
  if (stat(kNewPath, &new_stat)) {
    errx(1, "stat(%s) failed", kNewPath);
  }
  if (old_stat.st_dev != new_stat.st_dev) {
    errx(1, "files st_dev is different, want: %lu, got: %lu", old_stat.st_dev,
         new_stat.st_dev);
  }
  if (old_stat.st_ino != new_stat.st_ino) {
    errx(1, "files st_ino is different, want: %lu, got: %lu", old_stat.st_ino,
         new_stat.st_ino);
  }
  if (new_stat.st_nlink != old_stat.st_nlink + 1) {
    errx(1, "wrong nlink, want: %lu, got: %lu", old_stat.st_nlink + 1,
         new_stat.st_nlink);
  }
  fd = open(kNewPath, O_RDONLY);
  if (fd < 0) {
    errx(1, "open(%s) failed", kNewPath);
  }
  char buf[sizeof(kData)] = {};
  if (read(fd, buf, sizeof(buf)) < 0) {
    err(1, "read failed");
  }
  close(fd);
  if (strcmp(buf, kData) != 0) {
    errx(1, "file content mismatch: %s", buf);
  }
  if (unlink(kNewPath)) {
    errx(1, "unlink(%s) failed", kNewPath);
  }
  if (unlink(kOldPath)) {
    errx(1, "unlink(%s) failed", kOldPath);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe33(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    0x2e13(%rip),%rax
or     (%rax),%esi
mov    0x2e02(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1220 <main+0x70>
lea    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    0xee9(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xee6(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xee4(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    126b <main+0xbb>
mov    $0x1,%edi
lea    0xdb2(%rip),%rsi
call   10b0 <err@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
lea    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
je     12a1 <main+0xf1>
lea    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    0xd8d(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   10d0 <link@plt>
cmp    $0x0,%rax
je     12de <main+0x12e>
lea    -0x18(%rbp),%rdx
lea    -0x48(%rbp),%rcx
mov    $0x1,%edi
lea    0xd66(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
lea    -0x48(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
je     130c <main+0x15c>
lea    -0x48(%rbp),%rdx
mov    $0x1,%edi
lea    0xd20(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x38(%rbp),%eax
cmp    -0x50(%rbp),%eax
je     1332 <main+0x182>
movslq -0x38(%rbp),%rdx
mov    -0x50(%rbp),%ecx
mov    $0x1,%edi
lea    0xd26(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x3c(%rbp),%eax
cmp    -0x54(%rbp),%eax
je     1358 <main+0x1a8>
movslq -0x3c(%rbp),%rdx
mov    -0x54(%rbp),%ecx
mov    $0x1,%edi
lea    0xd2f(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x58(%rbp),%eax
mov    -0x40(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     1388 <main+0x1d8>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rdx
mov    -0x58(%rbp),%ecx
mov    $0x1,%edi
lea    0xd2e(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
lea    -0x48(%rbp),%rdi
mov    0x2c3d(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    13c0 <main+0x210>
lea    -0x48(%rbp),%rdx
mov    $0x1,%edi
lea    0xc4f(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x14,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jge    13fc <main+0x24c>
mov    $0x1,%edi
lea    0xcd9(%rip),%rsi
call   10b0 <err@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
lea    -0x70(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1432 <main+0x282>
lea    -0x70(%rbp),%rdx
mov    $0x1,%edi
lea    0xcb1(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
lea    -0x48(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     145c <main+0x2ac>
lea    -0x48(%rbp),%rdx
mov    $0x1,%edi
lea    0xca1(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
lea    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     1486 <main+0x2d6>
lea    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xc77(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
movabs $0x7478742e646c6f,%r14
mov    0x2e20(%rip),%rax
mov    0x2e39(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,0x8(%rsp)
mov    0x2e21(%rip),%rax
or     (%rax),%esi
lea    0x8(%rsp),%rdi
mov    $0x180,%edx
xor    %eax,%eax
call   10b0 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1200 <main+0x60>
lea    0xe11(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
movaps 0xef9(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movl   $0x746e65,0x60(%rsp)
lea    0x50(%rsp),%rsi
mov    %ebx,%edi
mov    $0x14,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    123b <main+0x9b>
lea    0xddf(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1090 <stat@plt>
test   %rax,%rax
je     126e <main+0xce>
lea    0xdc0(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
add    $0x12f8ff,%r14
mov    %r14,(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   10c0 <link@plt>
test   %rax,%rax
je     12a6 <main+0x106>
lea    0xd9b(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
call   1090 <stat@plt>
test   %rax,%rax
je     12ce <main+0x12e>
lea    0xd5e(%rip),%rsi
mov    %rsp,%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
movslq 0x28(%rsp),%rdx
mov    0x18(%rsp),%ecx
cmp    %ecx,%edx
je     12ee <main+0x14e>
lea    0xd5f(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
movslq 0x24(%rsp),%rdx
mov    0x14(%rsp),%ecx
cmp    %ecx,%edx
je     130e <main+0x16e>
lea    0xd6e(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
mov    0x10(%rsp),%ecx
movslq 0x20(%rsp),%rdx
add    $0x1,%rdx
cmp    %edx,%ecx
je     1332 <main+0x192>
lea    0xd79(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
mov    0x2c97(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
xor    %eax,%eax
call   10b0 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1361 <main+0x1c1>
lea    0xcae(%rip),%rsi
mov    %rsp,%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movl   $0x0,0x40(%rsp)
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
mov    $0x14,%edx
call   1070 <read@plt>
test   %rax,%rax
jns    1398 <main+0x1f8>
lea    0xd32(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0x30(%rsp),%rdi
lea    0x50(%rsp),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     13cb <main+0x22b>
lea    0xd12(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
mov    %rsp,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     13ee <main+0x24e>
lea    0xd07(%rip),%rsi
mov    %rsp,%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
lea    0x8(%rsp),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     1415 <main+0x275>
lea    0xce2(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
@__const.main.kOldPath = [8 x i8] c"old.txt\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [16 x i8] c"open(%s) failed\00"
@__const.main.kData = [20 x i8] c"some random content\00"
@.str.1 = [13 x i8] c"write failed\00"
@.str.2 = [16 x i8] c"stat(%s) failed\00"
@__const.main.kNewPath = [8 x i8] c"new.txt\00"
@.str.3 = [20 x i8] c"link(%s, %s) failed\00"
@.str.4 = [47 x i8] c"files st_dev is different, want: %lu, got: %lu\00"
@.str.5 = [47 x i8] c"files st_ino is different, want: %lu, got: %lu\00"
@.str.6 = [33 x i8] c"wrong nlink, want: %lu, got: %lu\00"
@O_RDONLY = global i32 0
@.str.7 = [12 x i8] c"read failed\00"
@.str.8 = [26 x i8] c"file content mismatch: %s\00"
@.str.9 = [18 x i8] c"unlink(%s) failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i8]
%7 = alloca i32
%8 = alloca [20 x i8]
%9 = alloca %struct.stat
%10 = alloca [8 x i8]
%11 = alloca %struct.stat
%12 = alloca [20 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [8 x i8]* %6 to i8*
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = load i32, i32* @O_TRUNC
%19 = or i32 %17, %18
%20 = call i32 (i8*, i32, ...) @open(i8* %14, i32 %19, i32 384)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%25 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %2
%27 = bitcast [20 x i8]* %8 to i8*
%28 = load i32, i32* %7
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%30 = call i64 @write(i32 %28, i8* %29, i32 20)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %26
%35 = load i32, i32* %7
%36 = call i32 @close(i32 %35)
%37 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%38 = call i64 @stat(i8* %37, %struct.stat* %9)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%42 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %40, %34
%44 = bitcast [8 x i8]* %10 to i8*
%45 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%47 = call i64 @link(i8* %45, i8* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %43
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%51 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%52 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %50, i8* %51)
br label %53
53: ; preds = %49, %43
%54 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%55 = call i64 @stat(i8* %54, %struct.stat* %11)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%59 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %58)
br label %60
60: ; preds = %57, %53
%61 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 2
%62 = load i32, i32* %61
%63 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 2
%64 = load i32, i32* %63
%65 = icmp ne i32 %62, %64
br i1 %65, label %66, label %74
66: ; preds = %60
%67 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 2
%68 = load i32, i32* %67
%69 = sext i32 %68 to i64
%70 = inttoptr i64 %69 to i8*
%71 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 2
%72 = load i32, i32* %71
%73 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %70, i32 %72)
br label %74
74: ; preds = %66, %60
%75 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%76 = load i32, i32* %75
%77 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 1
%78 = load i32, i32* %77
%79 = icmp ne i32 %76, %78
br i1 %79, label %80, label %88
80: ; preds = %74
%81 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 1
%82 = load i32, i32* %81
%83 = sext i32 %82 to i64
%84 = inttoptr i64 %83 to i8*
%85 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 1
%86 = load i32, i32* %85
%87 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8* %84, i32 %86)
br label %88
88: ; preds = %80, %74
%89 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%90 = load i32, i32* %89
%91 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%92 = load i32, i32* %91
%93 = add nsw i32 %92, 1
%94 = icmp ne i32 %90, %93
br i1 %94, label %95, label %104
95: ; preds = %88
%96 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%97 = load i32, i32* %96
%98 = add nsw i32 %97, 1
%99 = sext i32 %98 to i64
%100 = inttoptr i64 %99 to i8*
%101 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%102 = load i32, i32* %101
%103 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %100, i32 %102)
br label %104
104: ; preds = %95, %88
%105 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%106 = load i32, i32* @O_RDONLY
%107 = call i32 (i8*, i32, ...) @open(i8* %105, i32 %106)
store i32 %107, i32* %7
%108 = load i32, i32* %7
%109 = icmp slt i32 %108, 0
br i1 %109, label %110, label %113
110: ; preds = %104
%111 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%112 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %111)
br label %113
113: ; preds = %110, %104
%114 = bitcast [20 x i8]* %12 to i8*
%115 = load i32, i32* %7
%116 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%117 = call i64 @read(i32 %115, i8* %116, i32 20)
%118 = icmp slt i64 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %113
%120 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %121
121: ; preds = %119, %113
%122 = load i32, i32* %7
%123 = call i32 @close(i32 %122)
%124 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%125 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%126 = call i64 @strcmp(i8* %124, i8* %125)
%127 = icmp ne i64 %126, 0
br i1 %127, label %128, label %131
128: ; preds = %121
%129 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%130 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %129)
br label %131
131: ; preds = %128, %121
%132 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%133 = call i64 @unlink(i8* %132)
%134 = icmp ne i64 %133, 0
br i1 %134, label %135, label %138
135: ; preds = %131
%136 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%137 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %136)
br label %138
138: ; preds = %135, %131
%139 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%140 = call i64 @unlink(i8* %139)
%141 = icmp ne i64 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %138
%143 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%144 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %143)
br label %145
145: ; preds = %142, %138
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str = [16 x i8] c"open(%s) failed\00"
@__const.main.kData = [20 x i8] c"some random content\00"
@.str.1 = [13 x i8] c"write failed\00"
@.str.2 = [16 x i8] c"stat(%s) failed\00"
@.str.3 = [20 x i8] c"link(%s, %s) failed\00"
@.str.4 = [47 x i8] c"files st_dev is different, want: %lu, got: %lu\00"
@.str.5 = [47 x i8] c"files st_ino is different, want: %lu, got: %lu\00"
@.str.6 = [33 x i8] c"wrong nlink, want: %lu, got: %lu\00"
@O_RDONLY = global i32 0
@.str.7 = [12 x i8] c"read failed\00"
@.str.8 = [26 x i8] c"file content mismatch: %s\00"
@.str.9 = [18 x i8] c"unlink(%s) failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca [20 x i8]
%5 = alloca %struct.stat
%6 = alloca i64
%7 = alloca %struct.stat
%8 = alloca [20 x i8]
%9 = bitcast i64* %3 to i8*
store i64 32783537688308847, i64* %3
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CREAT
%12 = or i32 %11, %10
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %12, %13
%15 = call i32 (i8*, i32, ...) @open(i8* %9, i32 %14, i32 384)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %19
19: ; preds = %17, %2
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%21 = call i64 @write(i32 %15, i8* %20, i32 20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = call i32 @close(i32 %15)
%27 = bitcast %struct.stat* %5 to i8*
%28 = call i64 @stat(i8* %9, %struct.stat* %5)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %32
32: ; preds = %30, %25
%33 = bitcast i64* %6 to i8*
store i64 32783537689552238, i64* %6
%34 = call i64 @link(i8* %9, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %32
%37 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %9, i64* %6)
br label %38
38: ; preds = %36, %32
%39 = bitcast %struct.stat* %7 to i8*
%40 = call i64 @stat(i8* %33, %struct.stat* %7)
%41 = icmp eq i64 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %44
44: ; preds = %42, %38
%45 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 2
%46 = load i32, i32* %45
%47 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 2
%48 = load i32, i32* %47
%49 = icmp eq i32 %46, %48
br i1 %49, label %54, label %50
50: ; preds = %44
%51 = sext i32 %46 to i64
%52 = inttoptr i64 %51 to i8*
%53 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i8* %52, i32 %48)
br label %54
54: ; preds = %50, %44
%55 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 1
%56 = load i32, i32* %55
%57 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 1
%58 = load i32, i32* %57
%59 = icmp eq i32 %56, %58
br i1 %59, label %64, label %60
60: ; preds = %54
%61 = sext i32 %56 to i64
%62 = inttoptr i64 %61 to i8*
%63 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8* %62, i32 %58)
br label %64
64: ; preds = %60, %54
%65 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%66 = load i32, i32* %65
%67 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%68 = load i32, i32* %67
%69 = add nsw i32 %68, 1
%70 = icmp eq i32 %66, %69
br i1 %70, label %75, label %71
71: ; preds = %64
%72 = sext i32 %69 to i64
%73 = inttoptr i64 %72 to i8*
%74 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %73, i32 %66)
br label %75
75: ; preds = %71, %64
%76 = load i32, i32* @O_RDONLY
%77 = call i32 (i8*, i32, ...) @open(i8* %33, i32 %76)
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %75
%80 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %81
81: ; preds = %79, %75
%82 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%83 = call i64 @read(i32 %77, i8* %82, i32 20)
%84 = icmp slt i64 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %87
87: ; preds = %85, %81
%88 = call i32 @close(i32 %77)
%89 = call i64 @strcmp(i8* %82, i8* %20)
%90 = icmp eq i64 %89, 0
br i1 %90, label %93, label %91
91: ; preds = %87
%92 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i8* %82)
br label %93
93: ; preds = %91, %87
%94 = call i64 @unlink(i8* %33)
%95 = icmp eq i64 %94, 0
br i1 %95, label %98, label %96
96: ; preds = %93
%97 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %33)
br label %98
98: ; preds = %96, %93
%99 = call i64 @unlink(i8* %9)
%100 = icmp eq i64 %99, 0
br i1 %100, label %103, label %101
101: ; preds = %98
%102 = call i32 (i32, i8*, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %9)
br label %103
103: ; preds = %101, %98
ret i32 0
}