#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int link(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int symlink(char *, char *);
int usage();
int ln_main(int argc, char *argv[]) {
  int symbolic = 0;
  int ret;
  if (argc < 2)
    return usage();
  if (!strcmp(argv[1], "-s")) {
    symbolic = 1;
    argc--;
    argv++;
  }
  if (argc < 3)
    return usage();
  if (symbolic) {
    ret = symlink(argv[1], argv[2]);
  } else {
    ret = link(argv[1], argv[2]);
  }
  if (ret < 0)
    fprintf(stderr, "link failed %s\n", strerror(errno));
  return ret;
}


x86 assembly (clang, -O0):
<ln_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118f <ln_main+0x2f>
mov    $0x0,%al
call   1060 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    125c <ln_main+0xfc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe62(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11c8 <ln_main+0x68>
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11e1 <ln_main+0x81>
mov    $0x0,%al
call   1060 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    125c <ln_main+0xfc>
cmpl   $0x0,-0x14(%rbp)
je     1208 <ln_main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <symlink@plt>
mov    %eax,-0x18(%rbp)
jmp    1220 <ln_main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1070 <link@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1256 <ln_main+0xf6>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xdb2(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ln_main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x1,%edi
jle    1194 <ln_main+0x34>
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x8(%rsi),%rbp
mov    0x8(%rsi),%rdi
lea    0xe83(%rip),%rsi
call   1040 <strcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
cmovne %r14,%rbp
sub    %ecx,%ebx
cmp    $0x2,%ebx
ja     119f <ln_main+0x3f>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <usage@plt>
mov    0x8(%rbp),%rdi
mov    0x10(%rbp),%rsi
test   %eax,%eax
je     11b2 <ln_main+0x52>
call   1070 <link@plt>
jmp    11b7 <ln_main+0x57>
call   1030 <symlink@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11e5 <ln_main+0x85>
mov    0x2e1c(%rip),%rax
mov    (%rax),%ebp
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe28(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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