#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int link(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int symlink(char *, char *);
int main(int argc, char **argv) {
  if (argc < 3 || argc > 4) {
    fprintf(stderr, "USAGE: ln [-s] file linkname\n");
    return 1;
  }
  if (argc == 3) {
    if (link(argv[1], argv[2]) == -1) {
      perror("ln");
      return 1;
    } else
      return 0;
  }
  if (strcmp(argv[1], "-s")) {
    fprintf(stderr, "Unknown argument: %s\n", argv[1]);
    return 1;
  }
  if (symlink(argv[1], argv[2]) == -1) {
    perror("ln -s");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     117a <main+0x2a>
cmpl   $0x4,-0x8(%rbp)
jle    119d <main+0x4d>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126f <main+0x11f>
cmpl   $0x3,-0x8(%rbp)
jne    11e9 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <link@plt>
cmp    $0xffffffff,%eax
jne    11dd <main+0x8d>
lea    0xe52(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    126f <main+0x11f>
movl   $0x0,-0x4(%rbp)
jmp    126f <main+0x11f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe42(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1232 <main+0xe2>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126f <main+0x11f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <symlink@plt>
cmp    $0xffffffff,%eax
jne    1268 <main+0x118>
lea    0xde0(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    126f <main+0x11f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %edi,%eax
lea    -0x5(%rax),%ecx
cmp    $0xfffffffd,%ecx
ja     1174 <main+0x24>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11c0 <main+0x70>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
cmp    $0x3,%eax
jne    1194 <main+0x44>
mov    0x10(%rbx),%rsi
call   1070 <link@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     11e6 <main+0x96>
pop    %rbx
ret
lea    0xe9f(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11c7 <main+0x77>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe68(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1030 <symlink@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1192 <main+0x42>
lea    0xe53(%rip),%rdi
jmp    11ed <main+0x9d>
lea    0xe31(%rip),%rdi
call   1060 <perror@plt>
jmp    11c0 <main+0x70>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"USAGE: ln [-s] file linkname\0A\00"
@.str.1 = [3 x i8] c"ln\00"
@.str.2 = [3 x i8] c"-s\00"
@.str.3 = [22 x i8] c"Unknown argument: %s\0A\00"
@.str.4 = [6 x i8] c"ln -s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 3
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 4
br i1 %10, label %11, label %14
11: ; preds = %8, %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %53
14: ; preds = %8
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @link(i8* %20, i8* %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %17
%27 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %53
28: ; preds = %17
store i32 0, i32* %3
br label %53
29: ; preds = %14
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %39)
store i32 1, i32* %3
br label %53
41: ; preds = %29
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @symlink(i8* %44, i8* %47)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %41
%51 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %53
52: ; preds = %41
store i32 0, i32* %3
br label %53
53: ; preds = %52, %50, %35, %28, %26, %11
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"USAGE: ln [-s] file linkname\0A\00"
@.str.1 = [3 x i8] c"ln\00"
@.str.2 = [3 x i8] c"-s\00"
@.str.3 = [22 x i8] c"Unknown argument: %s\0A\00"
@.str.4 = [6 x i8] c"ln -s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -5
%4 = icmp ult i32 %3, -2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %34
8: ; preds = %2
%9 = icmp eq i32 %0, 3
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
br i1 %9, label %12, label %19
12: ; preds = %8
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @link(i8* %11, i8* %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %34
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %34
19: ; preds = %8
%20 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %10
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %34
26: ; preds = %19
%27 = load i8*, i8** %10
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i32 @symlink(i8* %27, i8* %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %26, %12, %32, %22, %17, %5
%35 = phi i32 [ 1, %5 ], [ 1, %17 ], [ 1, %22 ], [ 1, %32 ], [ 0, %12 ], [ 0, %26 ]
ret i32 %35
}