#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 st_nlink;
  scalar_t__ st_ino;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ link(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int);
scalar_t__ unlink(char *);
int main(int argc, char *argv[]) {
  struct stat statbuf_old, statbuf_new;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <pathname> <new pathname>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (link(argv[1], argv[2]) < 0) {
    fprintf(stderr, "Err.: %d link(); %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (stat(argv[1], &statbuf_old) < 0) {
    fprintf(stderr, "Err.: %d stat(); %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (stat(argv[2], &statbuf_new) < 0) {
    fprintf(stderr, "Err.: %d stat(); %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("    i-node link: %d '%s'\n", (int)statbuf_new.st_ino, argv[2]);
  printf("i-node pathname: %d '%s'\n", (int)statbuf_new.st_ino, argv[1]);
  printf("     link count: '%s' = %d\n", argv[1], statbuf_old.st_nlink);
  if (unlink(argv[2]) < 0) {
    fprintf(stderr, "Err.: %d unlink(); %s\n", errno, strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("hard link '%s' removed ", argv[2]);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11bc <main+0x4c>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <link@plt>
cmp    $0x0,%rax
jge    1226 <main+0xb6>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    %rax,%rcx
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    128c <main+0x11c>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    -0x3c(%rbp),%edx
mov    %rax,%rcx
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    12f2 <main+0x182>
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    -0x44(%rbp),%edx
mov    %rax,%rcx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%edx
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    13a5 <main+0x235>
mov    0x2c7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2c5f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    -0x4c(%rbp),%edx
mov    %rax,%rcx
lea    0xd0f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2c32(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c06(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    125a <main+0xea>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1070 <link@plt>
test   %rax,%rax
js     1276 <main+0x106>
mov    0x8(%rbx),%rdi
lea    0x18(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
js     1238 <main+0xc8>
mov    0x10(%rbx),%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
js     1238 <main+0xc8>
mov    0x10(%rsp),%esi
mov    0x10(%rbx),%rdx
lea    0xe7e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    0x8(%rbx),%rdx
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rsi
mov    0x18(%rsp),%edx
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     1298 <main+0x128>
mov    0x10(%rbx),%rsi
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2da1(%rip),%rax
mov    (%rax),%ebx
mov    0x2d90(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xde2(%rip),%rsi
jmp    12b8 <main+0x148>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd93(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12c6 <main+0x156>
mov    0x2d63(%rip),%rax
mov    (%rax),%ebx
mov    0x2d52(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xd8f(%rip),%rsi
jmp    12b8 <main+0x148>
mov    0x2d41(%rip),%rax
mov    (%rax),%ebx
mov    0x2d30(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xde7(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s <pathname> <new pathname>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"Err.: %d link(); %s\0A\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"Err.: %d stat(); %s\0A\00"
@.str.3 = [26 x i8] c" i-node link: %d '%s'\0A\00"
@.str.4 = [26 x i8] c"i-node pathname: %d '%s'\0A\00"
@.str.5 = [28 x i8] c" link count: '%s' = %d\0A\00"
@.str.6 = [23 x i8] c"Err.: %d unlink(); %s\0A\00"
@.str.7 = [24 x i8] c"hard link '%s' removed \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i64 @link(i8* %21, i8* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %18
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %29, i8* %31)
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %18
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i64 @stat(i8* %38, %struct.stat* %6)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = load i32, i32* @errno
%45 = call i8* @strerror(i32 %44)
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %43, i8* %45)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %35
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i64 @stat(i8* %52, %struct.stat* %7)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %49
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %57, i8* %59)
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %49
%64 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%65 = load i64, i64* %64
%66 = trunc i64 %65 to i32
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 2
%69 = load i8*, i8** %68
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %66, i8* %69)
%71 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%72 = load i64, i64* %71
%73 = trunc i64 %72 to i32
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = load i8*, i8** %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %73, i8* %76)
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%82 = load i32, i32* %81
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %80, i32 %82)
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 2
%86 = load i8*, i8** %85
%87 = call i64 @unlink(i8* %86)
%88 = icmp slt i64 %87, 0
br i1 %88, label %89, label %97
89: ; preds = %63
%90 = load i32, i32* @stderr
%91 = load i32, i32* @errno
%92 = load i32, i32* @errno
%93 = call i8* @strerror(i32 %92)
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %91, i8* %93)
%95 = load i32, i32* @EXIT_FAILURE
%96 = call i32 @exit(i32 %95)
unreachable
97: ; preds = %63
%98 = load i8**, i8*** %5
%99 = getelementptr inbounds i8*, i8** %98, i64 2
%100 = load i8*, i8** %99
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %100)
%102 = load i32, i32* @EXIT_SUCCESS
ret i32 %102
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s <pathname> <new pathname>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"Err.: %d link(); %s\0A\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"Err.: %d stat(); %s\0A\00"
@.str.3 = [26 x i8] c" i-node link: %d '%s'\0A\00"
@.str.4 = [26 x i8] c"i-node pathname: %d '%s'\0A\00"
@.str.5 = [28 x i8] c" link count: '%s' = %d\0A\00"
@.str.6 = [23 x i8] c"Err.: %d unlink(); %s\0A\00"
@.str.7 = [24 x i8] c"hard link '%s' removed \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i64 @link(i8* %16, i8* %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = tail call i8* @strerror(i32 %23)
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %14
%29 = load i8*, i8** %15
%30 = call i64 @stat(i8* %29, %struct.stat* %3)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %34, i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %28
%40 = load i8*, i8** %17
%41 = call i64 @stat(i8* %40, %struct.stat* %4)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %45, i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %39
%51 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%52 = load i64, i64* %51
%53 = trunc i64 %52 to i32
%54 = load i8*, i8** %17
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %53, i8* %54)
%56 = load i64, i64* %51
%57 = trunc i64 %56 to i32
%58 = load i8*, i8** %15
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %57, i8* %58)
%60 = load i8*, i8** %15
%61 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %60, i32 %62)
%64 = load i8*, i8** %17
%65 = call i64 @unlink(i8* %64)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %74
67: ; preds = %50
%68 = load i32, i32* @stderr
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %69, i8* %70)
%72 = load i32, i32* @EXIT_FAILURE
%73 = call i32 @exit(i32 %72)
unreachable
74: ; preds = %50
%75 = load i8*, i8** %17
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %75)
%77 = load i32, i32* @EXIT_SUCCESS
ret i32 %77
}