#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*/ STDERR_FILENO;
scalar_t__ access(char *, int /*<<< orphan*/);
char *buildname(char *, char *);
int /*<<< orphan*/ exit(int);
int isadir(char *);
scalar_t__ link(char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
scalar_t__ symlink(char *, char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int argc, char **argv) {
  int dirflag;
  char *srcname;
  char *destname;
  char *lastarg;
  if (argv[1][0] == '-') {
    if (strcmp(argv[1], "-s")) {
      write(STDERR_FILENO, "Unknown option\n", 15);
      exit(1);
    }
    if (argc != 4) {
      write(STDERR_FILENO, "Wrong number of arguments for symbolic link\n", 44);
      exit(1);
    }
    if (symlink(argv[2], argv[3]) < 0) {
      perror(argv[3]);
      exit(1);
    }
    exit(0);
  }
  lastarg = argv[argc - 1];
  dirflag = isadir(lastarg);
  if ((argc > 3) && !dirflag) {
    write(STDERR_FILENO, lastarg, strlen(lastarg));
    write(STDERR_FILENO, ": not a directory\n", 18);
    exit(1);
  }
  while (argc-- > 2) {
    srcname = *(++argv);
    if (access(srcname, 0) < 0) {
      perror(srcname);
      continue;
    }
    destname = lastarg;
    if (dirflag)
      destname = buildname(destname, srcname);
    if (link(srcname, destname) < 0) {
      perror(destname);
      continue;
    }
  }
  exit(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)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1277 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe27(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     120c <main+0x6c>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    $0xf,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
cmpl   $0x4,-0x8(%rbp)
je     123a <main+0x9a>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    $0x2c,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1060 <symlink@plt>
cmp    $0x0,%rax
jge    1270 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <isadir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    12fb <main+0x15b>
cmpl   $0x0,-0x14(%rbp)
jne    12fb <main+0x15b>
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
mov    $0x12,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1300 <main+0x160>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x2,%eax
jle    139b <main+0x1fb>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1080 <access@plt>
cmp    $0x0,%rax
jge    134e <main+0x1ae>
mov    -0x20(%rbp),%rdi
call   1090 <perror@plt>
jmp    1300 <main+0x160>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1371 <main+0x1d1>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10c0 <buildname@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <link@plt>
cmp    $0x0,%rax
jge    1396 <main+0x1f6>
mov    -0x28(%rbp),%rdi
call   1090 <perror@plt>
jmp    1300 <main+0x160>
jmp    1300 <main+0x160>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%r13d
mov    0x8(%rsi),%rdi
cmpb   $0x2d,(%rdi)
jne    1205 <main+0x65>
lea    0xe3f(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12cd <main+0x12d>
cmp    $0x4,%r13d
jne    12e4 <main+0x144>
mov    0x10(%r12),%rdi
mov    0x18(%r12),%rsi
call   1060 <symlink@plt>
test   %rax,%rax
jns    12c6 <main+0x126>
mov    0x18(%r12),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movslq %r13d,%rbx
mov    -0x8(%r12,%rbx,8),%r14
mov    %r14,%rdi
call   1050 <isadir@plt>
mov    %eax,%r15d
cmp    $0x4,%ebx
jl     1254 <main+0xb4>
test   %r15d,%r15d
jne    1254 <main+0xb4>
mov    0x2db7(%rip),%rbp
mov    0x0(%rbp),%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x0(%rbp),%edi
lea    0xdf6(%rip),%rsi
mov    $0x12,%edx
jmp    12f9 <main+0x159>
cmp    $0x3,%r13d
jl     12c6 <main+0x126>
add    $0x1,%r13d
add    $0x8,%r12
jmp    1291 <main+0xf1>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <link@plt>
mov    %rbx,%rbp
test   %rax,%rax
js     12bc <main+0x11c>
add    $0xffffffff,%r13d
add    $0x8,%r12
cmp    $0x3,%r13d
jbe    12c6 <main+0x126>
mov    (%r12),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
call   1080 <access@plt>
test   %rax,%rax
js     12bc <main+0x11c>
mov    %r14,%rbx
test   %r15d,%r15d
je     1270 <main+0xd0>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10c0 <buildname@plt>
mov    %rax,%rbx
jmp    1270 <main+0xd0>
mov    %rbp,%rdi
call   1090 <perror@plt>
jmp    1283 <main+0xe3>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
lea    0xd26(%rip),%rsi
mov    $0xf,%edx
jmp    12f9 <main+0x159>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
lea    0xd1f(%rip),%rsi
mov    $0x2c,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"-s\00"
@STDERR_FILENO = global i32 0
@.str.1 = [16 x i8] c"Unknown option\0A\00"
@.str.2 = [45 x i8] c"Wrong number of arguments for symbolic link\0A\00"
@.str.3 = [19 x i8] c": not a directory\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 45
br i1 %16, label %17, label %51
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* @STDERR_FILENO
%25 = call i32 @write(i32 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 15)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 4
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* @STDERR_FILENO
%32 = call i32 @write(i32 %31, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 44)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %27
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 3
%40 = load i8*, i8** %39
%41 = call i64 @symlink(i8* %37, i8* %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %34
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 3
%46 = load i8*, i8** %45
%47 = call i32 @perror(i8* %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %34
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %2
%52 = load i8**, i8*** %5
%53 = load i32, i32* %4
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %52, i64 %55
%57 = load i8*, i8** %56
store i8* %57, i8** %9
%58 = load i8*, i8** %9
%59 = call i32 @isadir(i8* %58)
store i32 %59, i32* %6
%60 = load i32, i32* %4
%61 = icmp sgt i32 %60, 3
br i1 %61, label %62, label %74
62: ; preds = %51
%63 = load i32, i32* %6
%64 = icmp ne i32 %63, 0
br i1 %64, label %74, label %65
65: ; preds = %62
%66 = load i32, i32* @STDERR_FILENO
%67 = load i8*, i8** %9
%68 = load i8*, i8** %9
%69 = call i32 @strlen(i8* %68)
%70 = call i32 @write(i32 %66, i8* %67, i32 %69)
%71 = load i32, i32* @STDERR_FILENO
%72 = call i32 @write(i32 %71, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 18)
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %62, %51
br label %75
75: ; preds = %105, %102, %86, %74
%76 = load i32, i32* %4
%77 = add nsw i32 %76, -1
store i32 %77, i32* %4
%78 = icmp sgt i32 %76, 2
br i1 %78, label %79, label %106
79: ; preds = %75
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i32 1
store i8** %81, i8*** %5
%82 = load i8*, i8** %81
store i8* %82, i8** %7
%83 = load i8*, i8** %7
%84 = call i64 @access(i8* %83, i32 0)
%85 = icmp slt i64 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %79
%87 = load i8*, i8** %7
%88 = call i32 @perror(i8* %87)
br label %75
89: ; preds = %79
%90 = load i8*, i8** %9
store i8* %90, i8** %8
%91 = load i32, i32* %6
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %89
%94 = load i8*, i8** %8
%95 = load i8*, i8** %7
%96 = call i8* @buildname(i8* %94, i8* %95)
store i8* %96, i8** %8
br label %97
97: ; preds = %93, %89
%98 = load i8*, i8** %7
%99 = load i8*, i8** %8
%100 = call i64 @link(i8* %98, i8* %99)
%101 = icmp slt i64 %100, 0
br i1 %101, label %102, label %105
102: ; preds = %97
%103 = load i8*, i8** %8
%104 = call i32 @perror(i8* %103)
br label %75
105: ; preds = %97
br label %75
106: ; preds = %75
%107 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"-s\00"
@STDERR_FILENO = global i32 0
@.str.1 = [16 x i8] c"Unknown option\0A\00"
@.str.2 = [45 x i8] c"Wrong number of arguments for symbolic link\0A\00"
@.str.3 = [19 x i8] c": not a directory\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 45
br i1 %6, label %7, label %33
7: ; preds = %2
%8 = tail call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load i32, i32* @STDERR_FILENO
%12 = tail call i32 @write(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 15)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
%15 = icmp eq i32 %0, 4
br i1 %15, label %20, label %16
16: ; preds = %14
%17 = load i32, i32* @STDERR_FILENO
%18 = tail call i32 @write(i32 %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 44)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %14
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i64 @symlink(i8* %22, i8* %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = load i8*, i8** %23
%29 = tail call i32 @perror(i8* %28)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %20
%32 = tail call i32 @exit(i32 0)
unreachable
33: ; preds = %2
%34 = add nsw i32 %0, -1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %1, i64 %35
%37 = load i8*, i8** %36
%38 = tail call i32 @isadir(i8* %37)
%39 = icmp slt i32 %0, 4
%40 = icmp ne i32 %38, 0
%41 = select i1 %39, i1 true, i1 %40
br i1 %41, label %42, label %44
42: ; preds = %33
%43 = icmp sgt i32 %0, 2
br i1 %43, label %51, label %71
44: ; preds = %33
%45 = load i32, i32* @STDERR_FILENO
%46 = tail call i32 @strlen(i8* %37)
%47 = tail call i32 @write(i32 %45, i8* %37, i32 %46)
%48 = load i32, i32* @STDERR_FILENO
%49 = tail call i32 @write(i32 %48, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 18)
%50 = tail call i32 @exit(i32 1)
unreachable
51: ; preds = %42, %62
%52 = phi i32 [ %54, %62 ], [ %0, %42 ]
%53 = phi i8** [ %55, %62 ], [ %1, %42 ]
%54 = add nsw i32 %52, -1
%55 = getelementptr inbounds i8*, i8** %53, i64 1
%56 = load i8*, i8** %55
%57 = tail call i64 @access(i8* %56, i32 0)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %51, %67
%60 = phi i8* [ %68, %67 ], [ %56, %51 ]
%61 = tail call i32 @perror(i8* %60)
br label %62
62: ; preds = %59, %67
%63 = icmp ugt i32 %52, 3
br i1 %63, label %51, label %71
64: ; preds = %51
br i1 %40, label %65, label %67
65: ; preds = %64
%66 = tail call i8* @buildname(i8* %37, i8* %56)
br label %67
67: ; preds = %65, %64
%68 = phi i8* [ %66, %65 ], [ %37, %64 ]
%69 = tail call i64 @link(i8* %56, i8* %68)
%70 = icmp slt i64 %69, 0
br i1 %70, label %59, label %62
71: ; preds = %62, %42
%72 = tail call i32 @exit(i32 0)
unreachable
}