#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 */
scalar_t__ access(char *, int /*<<< orphan*/);
char *buildname(char *, char *);
int isadir(char *);
scalar_t__ link(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ write(int, char *, int);
int /*<<< orphan*/ writes(int, char *);
int main(int argc, char *argv[]) {
  int dirflag;
  char *srcname, *destname, *lastarg;
  if (argv[1][0] == '-') {
    writes(2, argv[0]);
    writes(2, ": unknown option ");
    writes(2, argv[1]);
    write(2, "\n", 1);
    return 1;
  }
  lastarg = argv[argc - 1];
  dirflag = isadir(lastarg);
  if ((argc > 3) && !dirflag) {
    writes(2, lastarg);
    writes(2, ": not a directory\n");
    return 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;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    11f0 <main+0x80>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    $0x2,%edi
call   1050 <writes@plt>
mov    $0x2,%edi
lea    0xe49(%rip),%rsi
call   1050 <writes@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x2,%edi
call   1050 <writes@plt>
mov    $0x2,%edi
lea    0xe49(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f7 <main+0x187>
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   1040 <isadir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1250 <main+0xe0>
cmpl   $0x0,-0x14(%rbp)
jne    1250 <main+0xe0>
mov    -0x30(%rbp),%rsi
mov    $0x2,%edi
call   1050 <writes@plt>
mov    $0x2,%edi
lea    0xdd3(%rip),%rsi
call   1050 <writes@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f7 <main+0x187>
jmp    1255 <main+0xe5>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x2,%eax
jle    12f0 <main+0x180>
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   1060 <access@plt>
cmp    $0x0,%rax
jge    12a3 <main+0x133>
mov    -0x20(%rbp),%rdi
call   1070 <perror@plt>
jmp    1255 <main+0xe5>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     12c6 <main+0x156>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <buildname@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <link@plt>
cmp    $0x0,%rax
jge    12eb <main+0x17b>
mov    -0x28(%rbp),%rdi
call   1070 <perror@plt>
jmp    1255 <main+0xe5>
jmp    1255 <main+0xe5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    0x8(%rsi),%rax
cmpb   $0x2d,(%rax)
jne    11d5 <main+0x65>
mov    (%r12),%rsi
mov    $0x2,%edi
call   1050 <writes@plt>
lea    0xe64(%rip),%rsi
mov    $0x2,%edi
call   1050 <writes@plt>
mov    0x8(%r12),%rsi
mov    $0x2,%edi
call   1050 <writes@plt>
lea    0xe67(%rip),%rsi
mov    $0x1,%ebx
mov    $0x2,%edi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1288 <main+0x118>
mov    %edi,%r13d
movslq %edi,%rbx
mov    -0x8(%r12,%rbx,8),%r14
mov    %r14,%rdi
call   1040 <isadir@plt>
mov    %eax,%r15d
cmp    $0x4,%ebx
jl     121a <main+0xaa>
test   %r15d,%r15d
jne    121a <main+0xaa>
mov    $0x2,%edi
mov    %r14,%rsi
call   1050 <writes@plt>
lea    0xe09(%rip),%rsi
mov    $0x2,%edi
call   1050 <writes@plt>
mov    $0x1,%ebx
jmp    1288 <main+0x118>
xor    %ebx,%ebx
cmp    $0x3,%r13d
jl     1288 <main+0x118>
add    $0x1,%r13d
add    $0x8,%r12
jmp    1251 <main+0xe1>
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <link@plt>
mov    %rbx,%rbp
test   %rax,%rax
js     127c <main+0x10c>
add    $0xffffffff,%r13d
add    $0x8,%r12
cmp    $0x3,%r13d
jbe    1286 <main+0x116>
mov    (%r12),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <access@plt>
test   %rax,%rax
js     127c <main+0x10c>
mov    %r14,%rbx
test   %r15d,%r15d
je     1230 <main+0xc0>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1090 <buildname@plt>
mov    %rax,%rbx
jmp    1230 <main+0xc0>
mov    %rbp,%rdi
call   1070 <perror@plt>
jmp    1243 <main+0xd3>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c": unknown option \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [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 %28
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @writes(i32 2, i8* %20)
%22 = call i32 @writes(i32 2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @writes(i32 2, i8* %25)
%27 = call i32 @write(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32 1, i32* %3
br label %79
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %29, i64 %32
%34 = load i8*, i8** %33
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = call i32 @isadir(i8* %35)
store i32 %36, i32* %6
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 3
br i1 %38, label %39, label %46
39: ; preds = %28
%40 = load i32, i32* %6
%41 = icmp ne i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = load i8*, i8** %9
%44 = call i32 @writes(i32 2, i8* %43)
%45 = call i32 @writes(i32 2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %79
46: ; preds = %39, %28
br label %47
47: ; preds = %77, %74, %58, %46
%48 = load i32, i32* %4
%49 = add nsw i32 %48, -1
store i32 %49, i32* %4
%50 = icmp sgt i32 %48, 2
br i1 %50, label %51, label %78
51: ; preds = %47
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i32 1
store i8** %53, i8*** %5
%54 = load i8*, i8** %53
store i8* %54, i8** %7
%55 = load i8*, i8** %7
%56 = call i64 @access(i8* %55, i32 0)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %51
%59 = load i8*, i8** %7
%60 = call i32 @perror(i8* %59)
br label %47
61: ; preds = %51
%62 = load i8*, i8** %9
store i8* %62, i8** %8
%63 = load i32, i32* %6
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %61
%66 = load i8*, i8** %8
%67 = load i8*, i8** %7
%68 = call i8* @buildname(i8* %66, i8* %67)
store i8* %68, i8** %8
br label %69
69: ; preds = %65, %61
%70 = load i8*, i8** %7
%71 = load i8*, i8** %8
%72 = call i64 @link(i8* %70, i8* %71)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %69
%75 = load i8*, i8** %8
%76 = call i32 @perror(i8* %75)
br label %47
77: ; preds = %69
br label %47
78: ; preds = %47
store i32 0, i32* %3
br label %79
79: ; preds = %78, %42, %17
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
@.str = [18 x i8] c": unknown option \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [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 %14
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @writes(i32 2, i8* %8)
%10 = tail call i32 @writes(i32 2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %3
%12 = tail call i32 @writes(i32 2, i8* %11)
%13 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %48
14: ; preds = %2
%15 = add nsw i32 %0, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @isadir(i8* %18)
%20 = icmp slt i32 %0, 4
%21 = icmp ne i32 %19, 0
%22 = select i1 %20, i1 true, i1 %21
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = icmp sgt i32 %0, 2
br i1 %24, label %28, label %48
25: ; preds = %14
%26 = tail call i32 @writes(i32 2, i8* %18)
%27 = tail call i32 @writes(i32 2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %48
28: ; preds = %23, %39
%29 = phi i32 [ %31, %39 ], [ %0, %23 ]
%30 = phi i8** [ %32, %39 ], [ %1, %23 ]
%31 = add nsw i32 %29, -1
%32 = getelementptr inbounds i8*, i8** %30, i64 1
%33 = load i8*, i8** %32
%34 = tail call i64 @access(i8* %33, i32 0)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %28, %44
%37 = phi i8* [ %45, %44 ], [ %33, %28 ]
%38 = tail call i32 @perror(i8* %37)
br label %39
39: ; preds = %36, %44
%40 = icmp ugt i32 %29, 3
br i1 %40, label %28, label %48
41: ; preds = %28
br i1 %21, label %42, label %44
42: ; preds = %41
%43 = tail call i8* @buildname(i8* %18, i8* %33)
br label %44
44: ; preds = %42, %41
%45 = phi i8* [ %43, %42 ], [ %18, %41 ]
%46 = tail call i64 @link(i8* %33, i8* %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %36, label %39
48: ; preds = %39, %23, %25, %7
%49 = phi i32 [ 1, %7 ], [ 1, %25 ], [ 0, %23 ], [ 0, %39 ]
ret i32 %49
}