#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 */

/* Variables and functions */
int /*<<< orphan*/ err_quit(char *, char *);
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int readlink(char *, char *, int);
int symlink(char *, char *);
int main(int argc, char *argv[]) {
  char buf[20];
  int len;
  if (argc <= 2)
    err_quit("usage: %s <oldpath> <newpath>", argv[0]);
  if (symlink(argv[1], argv[2]) == -1)
    err_sys("symlink error");
  else
    printf("create %s success\n", argv[2]);
  if ((len = readlink(argv[2], buf, 20)) == -1)
    err_sys("readlink error");
  if (len > 20 - 1)
    len = 20 - 1;
  buf[len] = '\0';
  puts(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     1193 <main+0x33>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
call   1080 <err_quit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <symlink@plt>
cmp    $0xffffffff,%eax
jne    11c2 <main+0x62>
lea    0xe66(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11d6 <main+0x76>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe5b(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1050 <readlink@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    1204 <main+0xa4>
lea    0xe40(%rip),%rdi
call   1040 <err_sys@plt>
cmpl   $0x13,-0x34(%rbp)
jle    1215 <main+0xb5>
movl   $0x13,-0x34(%rbp)
movslq -0x34(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     117c <main+0x1c>
mov    (%rbx),%rsi
lea    0xe89(%rip),%rdi
call   1080 <err_quit@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1070 <symlink@plt>
cmp    $0xffffffff,%eax
je     11a0 <main+0x40>
mov    0x10(%rbx),%rsi
lea    0xe93(%rip),%rdi
call   1060 <printf@plt>
jmp    11ac <main+0x4c>
lea    0xe77(%rip),%rdi
call   1040 <err_sys@plt>
mov    0x10(%rbx),%rdi
mov    %rsp,%rsi
mov    $0x14,%edx
call   1050 <readlink@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11d0 <main+0x70>
lea    0xe74(%rip),%rdi
call   1040 <err_sys@plt>
cmp    $0x13,%ebx
mov    $0x13,%eax
cmovl  %ebx,%eax
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"usage: %s <oldpath> <newpath>\00"
@.str.1 = [14 x i8] c"symlink error\00"
@.str.2 = [19 x i8] c"create %s success\0A\00"
@.str.3 = [15 x i8] c"readlink error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @err_quit(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %10, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @symlink(i8* %18, i8* %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %31
26: ; preds = %15
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %26, %24
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%36 = call i32 @readlink(i8* %34, i8* %35, i32 20)
store i32 %36, i32* %7
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 @err_sys(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %31
%41 = load i32, i32* %7
%42 = icmp sgt i32 %41, 19
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 19, i32* %7
br label %44
44: ; preds = %43, %40
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 %46
store i8 0, i8* %47
%48 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%49 = call i32 @puts(i8* %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"usage: %s <oldpath> <newpath>\00"
@.str.1 = [14 x i8] c"symlink error\00"
@.str.2 = [19 x i8] c"create %s success\0A\00"
@.str.3 = [15 x i8] c"readlink error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @err_quit(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %9
9: ; preds = %6, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @symlink(i8* %11, i8* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = tail call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %21
18: ; preds = %9
%19 = load i8*, i8** %12
%20 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %16
%22 = load i8*, i8** %12
%23 = call i32 @readlink(i8* %22, i8* %4, i32 20)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @err_sys(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = icmp slt i32 %23, 19
%29 = select i1 %28, i32 %23, i32 19
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i32 @puts(i8* %4)
ret i32 0
}