#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int isadir(char *);
scalar_t__ link(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int dirflag;
  char *srcname, *destname, *lastarg;
  if (argv[1][0] == '-') {
    fprintf(stderr, "%s: unknown option %s\n", argv[0], argv[1]);
    return 1;
  }
  lastarg = argv[argc - 1];
  dirflag = isadir(lastarg);
  if ((argc > 3) && !dirflag) {
    fprintf(stderr, "%s: not a directory\n", lastarg);
    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    11bc <main+0x5c>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bf <main+0x15f>
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   1030 <isadir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1218 <main+0xb8>
cmpl   $0x0,-0x14(%rbp)
jne    1218 <main+0xb8>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bf <main+0x15f>
jmp    121d <main+0xbd>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x2,%eax
jle    12b8 <main+0x158>
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   1050 <access@plt>
cmp    $0x0,%rax
jge    126b <main+0x10b>
mov    -0x20(%rbp),%rdi
call   1060 <perror@plt>
jmp    121d <main+0xbd>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     128e <main+0x12e>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <buildname@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <link@plt>
cmp    $0x0,%rax
jge    12b3 <main+0x153>
mov    -0x28(%rbp),%rdi
call   1060 <perror@plt>
jmp    121d <main+0xbd>
jmp    121d <main+0xbd>
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,%r13
mov    0x8(%rsi),%rcx
cmpb   $0x2d,(%rcx)
jne    1194 <main+0x34>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xe75(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11ce <main+0x6e>
mov    %edi,%r12d
movslq %edi,%rbx
mov    -0x8(%r13,%rbx,8),%r14
mov    %r14,%rdi
call   1030 <isadir@plt>
mov    %eax,%r15d
cmp    $0x4,%ebx
jl     11e2 <main+0x82>
test   %r15d,%r15d
jne    11e2 <main+0x82>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
cmp    $0x3,%r12d
jl     11d3 <main+0x73>
add    $0x1,%r12d
add    $0x8,%r13
jmp    1221 <main+0xc1>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <link@plt>
mov    %rbp,%rbx
test   %rax,%rax
js     124c <main+0xec>
add    $0xffffffff,%r12d
add    $0x8,%r13
cmp    $0x3,%r12d
jbe    1256 <main+0xf6>
mov    0x0(%r13),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <access@plt>
test   %rax,%rax
js     124c <main+0xec>
mov    %r14,%rbp
test   %r15d,%r15d
je     1200 <main+0xa0>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <buildname@plt>
mov    %rax,%rbp
jmp    1200 <main+0xa0>
mov    %rbx,%rdi
call   1060 <perror@plt>
jmp    1213 <main+0xb3>
xor    %eax,%eax
jmp    11d3 <main+0x73>

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

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