#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_CREAT;
int S_IRGRP;
int S_IROTH;
int S_IRWXU;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int readlink(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
scalar_t__ symlink(char *, char *);
int main(int argc, char *argv[]) {
  int fd;
  char buf[1024];
  ssize_t buf_len;
  if (argc < 3) {
    fprintf(stderr, "Usage: %s <default file> <symbolic-link>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fd = open(argv[1], O_CREAT, (S_IRWXU | S_IRGRP | S_IROTH))) < 0) {
    fprintf(stderr, "Err.:(%d) - %s: %s\n", errno, strerror(errno), argv[1]);
    exit(EXIT_FAILURE);
  }
  if (symlink(argv[1], argv[2]) < 0) {
    fprintf(stderr, "Err.:(%d) - Create symbolic-link: %s\n", errno,
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  buf_len = readlink(argv[2], buf, 1024 - 1);
  if (buf_len == -1) {
    fprintf(stderr, "Err.:(%d) - Read symbolic-link: %s\n", errno,
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  buf[buf_len] = '\0';
  printf("         default file: '%s'\n", argv[1]);
  printf("        symbolic-link: '%s'\n", argv[2]);
  printf("symbolic-link content: '%s'\n", buf);
  close(fd);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11cf <main+0x4f>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
mov    0x2dd0(%rip),%rax
or     (%rax),%edx
mov    0x2dbf(%rip),%rax
or     (%rax),%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    126b <main+0xeb>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x42c(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x42c(%rbp),%edi
mov    -0x428(%rbp),%edx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1050 <symlink@plt>
cmp    $0x0,%rax
jge    12e1 <main+0x161>
mov    0x2d3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x434(%rbp)
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x430(%rbp)
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x434(%rbp),%edi
mov    -0x430(%rbp),%edx
mov    %rax,%rcx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x3ff,%edx
call   1030 <readlink@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    1364 <main+0x1e4>
mov    0x2cbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x43c(%rbp)
mov    0x2ca5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x438(%rbp)
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%edx
mov    %rax,%rcx
lea    0xd15(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c53(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movslq -0x424(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd06(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd0f(%rip),%rdi
call   1040 <printf@plt>
lea    -0x420(%rbp),%rsi
lea    0xd19(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    0x2beb(%rip),%rax
mov    (%rax),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    124f <main+0xcf>
mov    0x8(%rbx),%rdi
mov    0x2e56(%rip),%rax
mov    0x2e37(%rip),%rcx
mov    0x2e10(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    (%rax),%esi
mov    0x2dfb(%rip),%rax
or     (%rax),%edx
call   1080 <open@plt>
test   %eax,%eax
js     126e <main+0xee>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1050 <symlink@plt>
test   %rax,%rax
js     12a4 <main+0x124>
mov    0x10(%rbx),%rdi
mov    %rsp,%rsi
mov    $0x3ff,%edx
call   1030 <readlink@plt>
cmp    $0xffffffff,%eax
je     12c6 <main+0x146>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    0x8(%rbx),%rsi
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
lea    0xe97(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd9e(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12f4 <main+0x174>
mov    0x2d5b(%rip),%rax
mov    (%rax),%r14d
mov    0x2d49(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10a0 <strerror@plt>
mov    0x8(%rbx),%r8
lea    0xd97(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    12f4 <main+0x174>
mov    0x2d25(%rip),%rax
mov    (%rax),%ebx
mov    0x2d14(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10a0 <strerror@plt>
lea    0xd7a(%rip),%rsi
jmp    12e6 <main+0x166>
mov    0x2d03(%rip),%rax
mov    (%rax),%ebx
mov    0x2cf2(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10a0 <strerror@plt>
lea    0xd7e(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"Usage: %s <default file> <symbolic-link>\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [20 x i8] c"Err.:(%d) - %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [38 x i8] c"Err.:(%d) - Create symbolic-link: %s\0A\00"
@.str.3 = [36 x i8] c"Err.:(%d) - Read symbolic-link: %s\0A\00"
@.str.4 = [29 x i8] c" default file: '%s'\0A\00"
@.str.5 = [29 x i8] c" symbolic-link: '%s'\0A\00"
@.str.6 = [29 x i8] c"symbolic-link content: '%s'\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_CREAT
%24 = load i32, i32* @S_IRWXU
%25 = load i32, i32* @S_IRGRP
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IROTH
%28 = or i32 %26, %27
%29 = call i32 @open(i8* %22, i32 %23, i32 %28)
store i32 %29, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %19
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %33, i8* %35, i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %19
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = call i64 @symlink(i8* %45, i8* %48)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %59
51: ; preds = %42
%52 = load i32, i32* @stderr
%53 = load i32, i32* @errno
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %53, i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %42
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 2
%62 = load i8*, i8** %61
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%64 = call i32 @readlink(i8* %62, i8* %63, i32 1023)
store i32 %64, i32* %8
%65 = load i32, i32* %8
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %75
67: ; preds = %59
%68 = load i32, i32* @stderr
%69 = load i32, i32* @errno
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %69, i8* %71)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %59
%76 = load i32, i32* %8
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %77
store i8 0, i8* %78
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %81)
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 2
%85 = load i8*, i8** %84
%86 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %85)
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%88 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %87)
%89 = load i32, i32* %6
%90 = call i32 @close(i32 %89)
%91 = load i32, i32* @EXIT_SUCCESS
ret i32 %91
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"Usage: %s <default file> <symbolic-link>\0A\00"
@EXIT_FAILURE = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [20 x i8] c"Err.:(%d) - %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [38 x i8] c"Err.:(%d) - Create symbolic-link: %s\0A\00"
@.str.3 = [36 x i8] c"Err.:(%d) - Read symbolic-link: %s\0A\00"
@.str.4 = [29 x i8] c" default file: '%s'\0A\00"
@.str.5 = [29 x i8] c" symbolic-link: '%s'\0A\00"
@.str.6 = [29 x i8] c"symbolic-link content: '%s'\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_CREAT
%16 = load i32, i32* @S_IRWXU
%17 = load i32, i32* @S_IRGRP
%18 = or i32 %17, %16
%19 = load i32, i32* @S_IROTH
%20 = or i32 %18, %19
%21 = tail call i32 @open(i8* %14, i32 %15, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %12
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = load i8*, i8** %13
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* %26, i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @exit(i32 %29)
unreachable
31: ; preds = %12
%32 = load i8*, i8** %13
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = tail call i64 @symlink(i8* %32, i8* %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = tail call i8* @strerror(i32 %39)
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %39, i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = tail call i32 @exit(i32 %42)
unreachable
44: ; preds = %31
%45 = load i8*, i8** %33
%46 = call i32 @readlink(i8* %45, i8* %4, i32 1023)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %55
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = tail call i8* @strerror(i32 %50)
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %50, i8* %51)
%53 = load i32, i32* @EXIT_FAILURE
%54 = tail call i32 @exit(i32 %53)
unreachable
55: ; preds = %44
%56 = sext i32 %46 to i64
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %56
store i8 0, i8* %57
%58 = load i8*, i8** %13
%59 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %58)
%60 = load i8*, i8** %33
%61 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %60)
%62 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%63 = call i32 @close(i32 %21)
%64 = load i32, i32* @EXIT_SUCCESS
ret i32 %64
}