#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ src;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
char *getcwd(char *, int);
scalar_t__ link(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ unlink(char *);
int main(int argc, char *argv[]) {
  char src[128], dst[128];
  char *buf;
  printf("Input source file: ");
  scanf("%s", src);
  printf("Input destination file: ");
  scanf("%s", dst);
  if (link(src, dst) != 0) {
    perror(src);
    perror(dst);
    return 0;
  }
  printf("which link you wanna delete: ");
  scanf("%s", src);
  if (unlink(src) != 0) {
    perror(src);
    return 0;
  }
  if (getcwd(src, sizeof(src)) == NULL) {
    printf("%s\n", strerror(errno));
    return 0;
  } else {
    printf("%s\n", src);
  }
  buf = getcwd(NULL, -1);
  if (buf == NULL) {
    perror("getcwd()");
    return 0;
  } else {
    printf("%s\n", buf);
    free(buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xe5f(%rip),%rdi
call   1070 <scanf@plt>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x90(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1090 <link@plt>
cmp    $0x0,%rax
je     121c <main+0x9c>
lea    -0x90(%rbp),%rdi
call   1080 <perror@plt>
lea    -0x110(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1329 <main+0x1a9>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xddc(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x90(%rbp),%rdi
call   1040 <unlink@plt>
cmp    $0x0,%rax
je     126b <main+0xeb>
lea    -0x90(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1329 <main+0x1a9>
lea    -0x90(%rbp),%rdi
mov    $0x80,%esi
call   1060 <getcwd@plt>
cmp    $0x0,%rax
jne    12b1 <main+0x131>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1329 <main+0x1a9>
lea    -0x90(%rbp),%rsi
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
mov    $0xffffffff,%esi
call   1060 <getcwd@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    1301 <main+0x181>
lea    0xd62(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1329 <main+0x1a9>
mov    -0x118(%rbp),%rsi
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x118(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe63(%rip),%r15
mov    %rsp,%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x80(%rsp),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10a0 <link@plt>
test   %rax,%rax
jne    1279 <main+0xe9>
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe0b(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   1040 <unlink@plt>
mov    %rsp,%rdi
test   %rax,%rax
jne    1289 <main+0xf9>
mov    $0x80,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     1261 <main+0xd1>
mov    %rsp,%rdi
call   1050 <puts@plt>
xor    %edi,%edi
mov    $0xffffffff,%esi
call   1070 <getcwd@plt>
test   %rax,%rax
je     1290 <main+0x100>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    129c <main+0x10c>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
jmp    129c <main+0x10c>
mov    %rsp,%rdi
call   1090 <perror@plt>
lea    0x80(%rsp),%rdi
call   1090 <perror@plt>
jmp    129c <main+0x10c>
lea    0xdb7(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Input source file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [25 x i8] c"Input destination file: \00"
@.str.3 = [30 x i8] c"which link you wanna delete: \00"
@.str.4 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.5 = [9 x i8] c"getcwd()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca [128 x i8]
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%17 = call i64 @link(i8* %15, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%21 = call i32 @perror(i8* %20)
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%23 = call i32 @perror(i8* %22)
store i32 0, i32* %3
br label %57
24: ; preds = %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%29 = call i64 @unlink(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%33 = call i32 @perror(i8* %32)
store i32 0, i32* %3
br label %57
34: ; preds = %24
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%36 = call i8* @getcwd(i8* %35, i32 128)
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %40)
store i32 0, i32* %3
br label %57
42: ; preds = %34
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %42
%46 = call i8* @getcwd(i8* null, i32 -1)
store i8* %46, i8** %8
%47 = load i8*, i8** %8
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %57
51: ; preds = %45
%52 = load i8*, i8** %8
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %52)
%54 = load i8*, i8** %8
%55 = call i32 @free(i8* %54)
br label %56
56: ; preds = %51
store i32 0, i32* %3
br label %57
57: ; preds = %56, %49, %38, %31, %19
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [20 x i8] c"Input source file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [25 x i8] c"Input destination file: \00"
@.str.3 = [30 x i8] c"which link you wanna delete: \00"
@errno = global i32 0
@.str.5 = [9 x i8] c"getcwd()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = call i64 @link(i8* %5, i8* %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = call i32 @perror(i8* %5)
%15 = call i32 @perror(i8* %6)
br label %39
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%19 = call i64 @unlink(i8* %5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = call i32 @perror(i8* %5)
br label %39
23: ; preds = %16
%24 = call i8* @getcwd(i8* %5, i32 128)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @puts(i8* dereferenceable(1) %28)
br label %39
30: ; preds = %23
%31 = call i32 @puts(i8* %5)
%32 = call i8* @getcwd(i8* null, i32 -1)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %39
36: ; preds = %30
%37 = call i32 @puts(i8* %32)
%38 = call i32 @free(i8* %32)
br label %39
39: ; preds = %36, %34, %26, %21, %13
ret i32 0
}