#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int EOF;
int PATH_MAX;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int getopt(int, char **, char *);
int link(char *, char *);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
int optind;
int optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strrchr(char *, char);
int symlink(char *, char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  int c, s, f;
  char *p;
  struct stat sb;
  s = f = 0;
  do {
    c = getopt(argc, argv, "sf");
    if (c == EOF)
      break;
    switch (c) {
    case 's':
      s = 1;
      break;
    case 'f':
      f = 1;
      break;
    case '?':
      fprintf(stderr, "%s: invalid option -%c\n", argv[0], optopt);
      return 1;
    }
  } while (1);
  if (optind == argc) {
    fprintf(stderr, "Usage: %s [-s] [-f] target link\n", argv[0]);
    return 1;
  }
  memset(&sb, 0, sizeof(struct stat));
  if (stat(argv[argc - 1], &sb) < 0 && argc - optind > 2) {
    if (!(S_ISDIR(sb.st_mode))) {
      fprintf(stderr, "multiple targets and %s is not a directory\n",
              argv[argc - 1]);
      return 1;
    }
  }
  for (c = optind; c < argc - 1; c++) {
    char target[PATH_MAX];
    p = strrchr(argv[c], '/');
    p++;
    if (S_ISDIR(sb.st_mode))
      snprintf(target, PATH_MAX, "%s/%s", argv[argc - 1], p);
    else
      snprintf(target, PATH_MAX, "%s", argv[argc - 1]);
    if (f)
      unlink(target);
    if (s) {
      if (symlink(argv[c], target) == -1)
        perror(target);
    } else {
      if (link(argv[c], target) == -1)
        perror(target);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe1e(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2de4(%rip),%rcx
cmp    (%rcx),%eax
jne    1201 <main+0x51>
jmp    1296 <main+0xe6>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x3f,%eax
je     124f <main+0x9f>
jmp    1215 <main+0x65>
mov    -0x44(%rbp),%eax
sub    $0x66,%eax
je     1243 <main+0x93>
jmp    1226 <main+0x76>
mov    -0x44(%rbp),%eax
sub    $0x73,%eax
jne    1282 <main+0xd2>
jmp    1237 <main+0x87>
movl   $0x1,-0x18(%rbp)
jmp    1282 <main+0xd2>
movl   $0x1,-0x1c(%rbp)
jmp    1282 <main+0xd2>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    0x2d7a(%rip),%rax
mov    (%rax),%ecx
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14d9 <main+0x329>
jmp    1287 <main+0xd7>
mov    $0x1,%al
test   $0x1,%al
jne    11d4 <main+0x24>
jmp    1296 <main+0xe6>
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    12d2 <main+0x122>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd5c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14d9 <main+0x329>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x30(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
jge    1366 <main+0x1b6>
mov    -0x8(%rbp),%eax
mov    0x2cc0(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x2,%eax
jle    1366 <main+0x1b6>
mov    -0x30(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
jne    1361 <main+0x1b1>
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xcee(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14d9 <main+0x329>
jmp    1366 <main+0x1b6>
mov    0x2c63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    14d2 <main+0x322>
mov    0x2c66(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     141c <main+0x26c>
mov    -0x50(%rbp),%rdi
mov    0x2bfe(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x28(%rbp),%r8
lea    0xc58(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
jmp    1448 <main+0x298>
mov    -0x50(%rbp),%rdi
mov    0x2bc9(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xc2a(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     145b <main+0x2ab>
mov    -0x50(%rbp),%rdi
call   1030 <unlink@plt>
cmpl   $0x0,-0x18(%rbp)
je     1491 <main+0x2e1>
mov    -0x50(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <symlink@plt>
cmp    $0xffffffff,%eax
jne    148c <main+0x2dc>
mov    -0x50(%rbp),%rdi
call   10b0 <perror@plt>
jmp    14bd <main+0x30d>
mov    -0x50(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10d0 <link@plt>
cmp    $0xffffffff,%eax
jne    14b8 <main+0x308>
mov    -0x50(%rbp),%rdi
call   10b0 <perror@plt>
jmp    14bd <main+0x30d>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1372 <main+0x1c2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r12
mov    %edi,%ebx
lea    0xe33(%rip),%rdx
call   10c0 <getopt@plt>
mov    0x2dff(%rip),%r14
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
cmp    (%r14),%eax
jne    1218 <main+0x68>
mov    0x2ddd(%rip),%r14
cmp    %ebx,(%r14)
jne    1269 <main+0xb9>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe0f(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1412 <main+0x262>
movl   $0x0,-0x38(%rbp)
lea    0xdda(%rip),%r15
movl   $0x0,-0x34(%rbp)
jmp    1249 <main+0x99>
nop
movl   $0x1,-0x34(%rbp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   10c0 <getopt@plt>
cmp    (%r14),%eax
je     11ec <main+0x3c>
cmp    $0x66,%eax
je     1260 <main+0xb0>
cmp    $0x73,%eax
je     1230 <main+0x80>
cmp    $0x3f,%eax
jne    1237 <main+0x87>
jmp    13ee <main+0x23e>
nopl   (%rax)
movl   $0x1,-0x38(%rbp)
jmp    1237 <main+0x87>
lea    -0x30(%rbp),%rdi
xor    %r13d,%r13d
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
movslq %ebx,%r15
mov    -0x8(%r12,%r15,8),%rdi
add    $0xffffffffffffffff,%r15
lea    -0x30(%rbp),%rsi
call   10a0 <stat@plt>
test   %rax,%rax
jns    12b1 <main+0x101>
mov    %ebx,%eax
sub    (%r14),%eax
cmp    $0x3,%eax
jl     12b1 <main+0x101>
mov    -0x30(%rbp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     142a <main+0x27a>
movslq (%r14),%rax
cmp    %r15d,%eax
jge    1418 <main+0x268>
mov    %r15,-0x40(%rbp)
mov    %r12,-0x48(%rbp)
lea    (%r12,%rax,8),%rcx
mov    %rcx,-0x50(%rbp)
not    %eax
add    %ebx,%eax
mov    0x2d18(%rip),%r12
xor    %r15d,%r15d
mov    %rax,-0x58(%rbp)
jmp    131c <main+0x16c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rsi
call   10d0 <link@plt>
cmp    $0xffffffff,%eax
je     13af <main+0x1ff>
mov    %r14,%rsp
add    $0x1,%r15
mov    -0x58(%rbp),%rax
cmp    %r15d,%eax
mov    0x2cda(%rip),%r12
je     13e9 <main+0x239>
mov    %rsp,%r14
mov    (%r12),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    -0x50(%rbp),%rax
mov    (%rax,%r15,8),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,%rbx
mov    -0x30(%rbp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     13c0 <main+0x210>
add    $0x1,%rbx
mov    (%r12),%esi
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    %r13,%rdi
lea    0xcf4(%rip),%rdx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
cmpl   $0x0,-0x38(%rbp)
je     138c <main+0x1dc>
mov    %r13,%rdi
call   1030 <unlink@plt>
mov    -0x50(%rbp),%rax
mov    (%rax,%r15,8),%rdi
cmpl   $0x0,-0x34(%rbp)
je     12f0 <main+0x140>
mov    %r13,%rsi
call   1050 <symlink@plt>
cmp    $0xffffffff,%eax
jne    1301 <main+0x151>
mov    %r13,%rdi
call   10b0 <perror@plt>
jmp    1301 <main+0x151>
nopl   0x0(%rax)
mov    (%r12),%esi
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    %r13,%rdi
lea    0xc91(%rip),%rdx
xor    %eax,%eax
call   1060 <snprintf@plt>
cmpl   $0x0,-0x38(%rbp)
jne    1384 <main+0x1d4>
jmp    138c <main+0x1dc>
xor    %r13d,%r13d
jmp    1418 <main+0x268>
mov    0x2bcb(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
mov    0x2bde(%rip),%rax
mov    (%rax),%ecx
lea    0xbf8(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%r13d
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b8f(%rip),%rax
mov    (%rax),%edi
mov    (%r12,%r15,8),%rdx
lea    0xbfe(%rip),%rsi
jmp    120c <main+0x5c>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"sf\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"%s: invalid option -%c\0A\00"
@optopt = global i32 0
@optind = global i32 0
@.str.2 = [33 x i8] c"Usage: %s [-s] [-f] target link\0A\00"
@.str.3 = [44 x i8] c"multiple targets and %s is not a directory\0A\00"
@PATH_MAX = global i32 0
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.stat
%11 = alloca i8*
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %7
br label %13
13: ; preds = %33, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %13
br label %34
21: ; preds = %13
%22 = load i32, i32* %6
switch i32 %22, label %32 [
i32 115, label %23
i32 102, label %24
i32 63, label %25
]
23: ; preds = %21
store i32 1, i32* %7
br label %32
24: ; preds = %21
store i32 1, i32* %8
br label %32
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = load i32, i32* @optopt
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 %30)
store i32 1, i32* %3
br label %153
32: ; preds = %21, %24, %23
br label %33
33: ; preds = %32
br i1 true, label %13, label %34
34: ; preds = %33, %20
%35 = load i32, i32* @optind
%36 = load i32, i32* %4
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %42)
store i32 1, i32* %3
br label %153
44: ; preds = %34
%45 = call i32 @memset(%struct.stat* %10, i32 0, i32 4)
%46 = load i8**, i8*** %5
%47 = load i32, i32* %4
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %46, i64 %49
%51 = load i8*, i8** %50
%52 = call i64 @stat(i8* %51, %struct.stat* %10)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %74
54: ; preds = %44
%55 = load i32, i32* %4
%56 = load i32, i32* @optind
%57 = sub nsw i32 %55, %56
%58 = icmp sgt i32 %57, 2
br i1 %58, label %59, label %74
59: ; preds = %54
%60 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i64 @S_ISDIR(i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %73, label %64
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = load i8**, i8*** %5
%67 = load i32, i32* %4
%68 = sub nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %66, i64 %69
%71 = load i8*, i8** %70
%72 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %71)
store i32 1, i32* %3
br label %153
73: ; preds = %59
br label %74
74: ; preds = %73, %54, %44
%75 = load i32, i32* @optind
store i32 %75, i32* %6
br label %76
76: ; preds = %149, %74
%77 = load i32, i32* %6
%78 = load i32, i32* %4
%79 = sub nsw i32 %78, 1
%80 = icmp slt i32 %77, %79
br i1 %80, label %81, label %152
81: ; preds = %76
%82 = load i32, i32* @PATH_MAX
%83 = zext i32 %82 to i64
%84 = call i8* @llvm.stacksave()
store i8* %84, i8** %11
%85 = alloca i8, i64 %83
store i64 %83, i64* %12
%86 = load i8**, i8*** %5
%87 = load i32, i32* %6
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8*, i8** %86, i64 %88
%90 = load i8*, i8** %89
%91 = call i8* @strrchr(i8* %90, i8 signext 47)
store i8* %91, i8** %9
%92 = load i8*, i8** %9
%93 = getelementptr inbounds i8, i8* %92, i32 1
store i8* %93, i8** %9
%94 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%95 = load i32, i32* %94
%96 = call i64 @S_ISDIR(i32 %95)
%97 = icmp ne i64 %96, 0
br i1 %97, label %98, label %108
98: ; preds = %81
%99 = load i32, i32* @PATH_MAX
%100 = load i8**, i8*** %5
%101 = load i32, i32* %4
%102 = sub nsw i32 %101, 1
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8*, i8** %100, i64 %103
%105 = load i8*, i8** %104
%106 = load i8*, i8** %9
%107 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %85, i32 %99, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %105, i8* %106)
br label %117
108: ; preds = %81
%109 = load i32, i32* @PATH_MAX
%110 = load i8**, i8*** %5
%111 = load i32, i32* %4
%112 = sub nsw i32 %111, 1
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i8*, i8** %110, i64 %113
%115 = load i8*, i8** %114
%116 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %85, i32 %109, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %115)
br label %117
117: ; preds = %108, %98
%118 = load i32, i32* %8
%119 = icmp ne i32 %118, 0
br i1 %119, label %120, label %122
120: ; preds = %117
%121 = call i32 @unlink(i8* %85)
br label %122
122: ; preds = %120, %117
%123 = load i32, i32* %7
%124 = icmp ne i32 %123, 0
br i1 %124, label %125, label %136
125: ; preds = %122
%126 = load i8**, i8*** %5
%127 = load i32, i32* %6
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds i8*, i8** %126, i64 %128
%130 = load i8*, i8** %129
%131 = call i32 @symlink(i8* %130, i8* %85)
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %135
133: ; preds = %125
%134 = call i32 @perror(i8* %85)
br label %135
135: ; preds = %133, %125
br label %147
136: ; preds = %122
%137 = load i8**, i8*** %5
%138 = load i32, i32* %6
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds i8*, i8** %137, i64 %139
%141 = load i8*, i8** %140
%142 = call i32 @link(i8* %141, i8* %85)
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %146
144: ; preds = %136
%145 = call i32 @perror(i8* %85)
br label %146
146: ; preds = %144, %136
br label %147
147: ; preds = %146, %135
%148 = load i8*, i8** %11
br label %149
149: ; preds = %147
%150 = load i32, i32* %6
%151 = add nsw i32 %150, 1
store i32 %151, i32* %6
br label %76
152: ; preds = %76
store i32 0, i32* %3
br label %153
153: ; preds = %152, %64, %38, %25
%154 = load i32, i32* %3
ret i32 %154
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"sf\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"%s: invalid option -%c\0A\00"
@optopt = global i32 0
@optind = global i32 0
@.str.2 = [33 x i8] c"Usage: %s [-s] [-f] target link\0A\00"
@.str.3 = [44 x i8] c"multiple targets and %s is not a directory\0A\00"
@PATH_MAX = global i32 0
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %25, label %8
8: ; preds = %2, %19
%9 = phi i32 [ %22, %19 ], [ %5, %2 ]
%10 = phi i32 [ %21, %19 ], [ 0, %2 ]
%11 = phi i32 [ %20, %19 ], [ 0, %2 ]
switch i32 %9, label %19 [
i32 115, label %12
i32 102, label %13
i32 63, label %14
]
12: ; preds = %8
br label %19
13: ; preds = %8
br label %19
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = load i32, i32* @optopt
%18 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 %17)
br label %101
19: ; preds = %12, %13, %8
%20 = phi i32 [ %11, %8 ], [ %11, %13 ], [ 1, %12 ]
%21 = phi i32 [ %10, %8 ], [ 1, %13 ], [ %10, %12 ]
%22 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %8
25: ; preds = %19, %2
%26 = phi i32 [ 0, %2 ], [ %20, %19 ]
%27 = phi i32 [ 0, %2 ], [ %21, %19 ]
%28 = load i32, i32* @optind
%29 = icmp eq i32 %28, %0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %1
%33 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %101
34: ; preds = %25
%35 = call i32 @memset(%struct.stat* %3, i32 0, i32 4)
%36 = add nsw i32 %0, -1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %1, i64 %37
%39 = load i8*, i8** %38
%40 = call i64 @stat(i8* %39, %struct.stat* %3)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %55
42: ; preds = %34
%43 = load i32, i32* @optind
%44 = sub nsw i32 %0, %43
%45 = icmp sgt i32 %44, 2
br i1 %45, label %46, label %55
46: ; preds = %42
%47 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%48 = load i32, i32* %47
%49 = call i64 @S_ISDIR(i32 %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %46
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %38
%54 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %53)
br label %101
55: ; preds = %46, %42, %34
%56 = load i32, i32* @optind
%57 = icmp slt i32 %56, %36
br i1 %57, label %58, label %101
58: ; preds = %55
%59 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%60 = icmp eq i32 %27, 0
%61 = icmp eq i32 %26, 0
%62 = sext i32 %56 to i64
br label %63
63: ; preds = %58, %97
%64 = phi i64 [ %62, %58 ], [ %98, %97 ]
%65 = load i32, i32* @PATH_MAX
%66 = zext i32 %65 to i64
%67 = call i8* @llvm.stacksave()
%68 = alloca i8, i64 %66
%69 = getelementptr inbounds i8*, i8** %1, i64 %64
%70 = load i8*, i8** %69
%71 = call i8* @strrchr(i8* dereferenceable(1) %70, i8 signext 47)
%72 = load i32, i32* %59
%73 = call i64 @S_ISDIR(i32 %72)
%74 = icmp eq i64 %73, 0
br i1 %74, label %80, label %75
75: ; preds = %63
%76 = getelementptr inbounds i8, i8* %71, i64 1
%77 = load i32, i32* @PATH_MAX
%78 = load i8*, i8** %38
%79 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %68, i32 %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %78, i8* %76)
br label %84
80: ; preds = %63
%81 = load i32, i32* @PATH_MAX
%82 = load i8*, i8** %38
%83 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %68, i32 %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %82)
br label %84
84: ; preds = %80, %75
br i1 %60, label %87, label %85
85: ; preds = %84
%86 = call i32 @unlink(i8* %68)
br label %87
87: ; preds = %85, %84
%88 = load i8*, i8** %69
br i1 %61, label %92, label %89
89: ; preds = %87
%90 = call i32 @symlink(i8* %88, i8* %68)
%91 = icmp eq i32 %90, -1
br i1 %91, label %95, label %97
92: ; preds = %87
%93 = call i32 @link(i8* %88, i8* %68)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %97
95: ; preds = %92, %89
%96 = call i32 @perror(i8* %68)
br label %97
97: ; preds = %95, %92, %89
%98 = add nsw i64 %64, 1
%99 = trunc i64 %98 to i32
%100 = icmp eq i32 %36, %99
br i1 %100, label %101, label %63
101: ; preds = %97, %55, %51, %30, %14
%102 = phi i32 [ 1, %30 ], [ 1, %51 ], [ 1, %14 ], [ 0, %55 ], [ 0, %97 ]
ret i32 %102
}