#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ _test_sysio_shutdown();
int errno;
int /*<<< orphan*/ exit(int);
int getopt(int, char *const *, char *);
int link(char const *, char const *);
int lstat(char const *, struct stat *);
int optind;
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ usage();
int main(int argc, char *const argv[]) {
  int i;
  int err;
  int n;
  extern int _test_sysio_startup(void);
  while ((i = getopt(argc, argv, "")) != -1)
    switch (i) {
    default:
      usage();
    }
  err = _test_sysio_startup();
  if (err) {
    errno = -err;
    perror("sysio startup");
    exit(1);
  }
  n = argc - optind;
  if (n < 2)
    usage();
  while (optind < argc) {
    const char *old, *new;
    struct stat stbuf;
    old = argv[optind++];
    new = argv[optind++];
    if ((err = link(old, new)) != 0) {
      perror("link");
      break;
    }
    if ((err = lstat(new, &stbuf)) != 0) {
      perror(new);
      break;
    }
  }
  _test_sysio_shutdown();
  return err ? -1 : 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6e(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11c1 <main+0x41>
mov    $0x0,%al
call   1050 <usage@plt>
jmp    1196 <main+0x16>
call   1060 <_test_sysio_startup@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11f7 <main+0x77>
xor    %ecx,%ecx
sub    -0x18(%rbp),%ecx
mov    0x2df9(%rip),%rax
mov    %ecx,(%rax)
lea    0xe18(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%eax
mov    0x2de7(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    1217 <main+0x97>
mov    $0x0,%al
call   1050 <usage@plt>
jmp    121c <main+0x9c>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    12d0 <main+0x150>
mov    -0x10(%rbp),%rax
mov    0x2daf(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2da1(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d89(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    0x2d7b(%rip),%rdx
mov    %esi,(%rdx)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <link@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     12a4 <main+0x124>
lea    0xd74(%rip),%rdi
call   1070 <perror@plt>
jmp    12d0 <main+0x150>
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <lstat@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     12cb <main+0x14b>
mov    -0x30(%rbp),%rdi
call   1070 <perror@plt>
jmp    12d0 <main+0x150>
jmp    121c <main+0x9c>
mov    $0x0,%al
call   1030 <_test_sysio_shutdown@plt>
mov    -0x18(%rbp),%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x40,%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,%rbx
mov    %edi,%r12d
lea    0xe7a(%rip),%rdx
call   1080 <getopt@plt>
cmp    $0xffffffff,%eax
je     11ca <main+0x4a>
lea    0xe69(%rip),%rbp
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <usage@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1080 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x30>
call   1060 <_test_sysio_startup@plt>
test   %eax,%eax
jne    1276 <main+0xf6>
mov    0x2e0a(%rip),%r13
mov    0x0(%r13),%eax
mov    %r12d,%ecx
sub    %eax,%ecx
cmp    $0x1,%ecx
jg     11f7 <main+0x77>
xor    %eax,%eax
call   1050 <usage@plt>
mov    0x0(%r13),%eax
xor    %r14d,%r14d
cmp    %r12d,%eax
jge    1246 <main+0xc6>
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cltq
mov    (%rbx,%rax,8),%rdi
lea    0x2(%rax),%ecx
mov    %ecx,0x0(%r13)
mov    0x8(%rbx,%rax,8),%rbp
mov    %rbp,%rsi
call   1090 <link@plt>
test   %eax,%eax
jne    125f <main+0xdf>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <lstat@plt>
test   %eax,%eax
jne    1266 <main+0xe6>
mov    0x0(%r13),%eax
cmp    %r12d,%eax
jl     1210 <main+0x90>
xor    %eax,%eax
call   1030 <_test_sysio_shutdown@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda8(%rip),%rbp
mov    %rbp,%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1246 <main+0xc6>
neg    %eax
mov    0x2d59(%rip),%rcx
mov    %eax,(%rcx)
lea    0xd78(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [1 x i8] zeroinitializer
@errno = global i32 0
@.str.1 = [14 x i8] c"sysio startup\00"
@optind = global i32 0
@.str.2 = [5 x i8] c"link\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 i8*
%11 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %12
12: ; preds = %21, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %19 [
]
19: ; preds = %17
%20 = call i32 (...) @usage()
br label %21
21: ; preds = %19
br label %12
22: ; preds = %12
%23 = call i32 @_test_sysio_startup()
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i32, i32* %7
%28 = sub nsw i32 0, %27
store i32 %28, i32* @errno
%29 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = load i32, i32* %4
%33 = load i32, i32* @optind
%34 = sub nsw i32 %32, %33
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 2
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 (...) @usage()
br label %39
39: ; preds = %37, %31
br label %40
40: ; preds = %70, %39
%41 = load i32, i32* @optind
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %71
44: ; preds = %40
%45 = load i8**, i8*** %5
%46 = load i32, i32* @optind
%47 = add nsw i32 %46, 1
store i32 %47, i32* @optind
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8*, i8** %45, i64 %48
%50 = load i8*, i8** %49
store i8* %50, i8** %9
%51 = load i8**, i8*** %5
%52 = load i32, i32* @optind
%53 = add nsw i32 %52, 1
store i32 %53, i32* @optind
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i8*, i8** %51, i64 %54
%56 = load i8*, i8** %55
store i8* %56, i8** %10
%57 = load i8*, i8** %9
%58 = load i8*, i8** %10
%59 = call i32 @link(i8* %57, i8* %58)
store i32 %59, i32* %7
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %44
%62 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %71
63: ; preds = %44
%64 = load i8*, i8** %10
%65 = call i32 @lstat(i8* %64, %struct.stat* %11)
store i32 %65, i32* %7
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i8*, i8** %10
%69 = call i32 @perror(i8* %68)
br label %71
70: ; preds = %63
br label %40
71: ; preds = %67, %61, %40
%72 = call i32 (...) @_test_sysio_shutdown()
%73 = load i32, i32* %7
%74 = icmp ne i32 %73, 0
%75 = zext i1 %74 to i64
%76 = select i1 %74, i32 -1, i32 0
ret i32 %76
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [1 x i8] zeroinitializer
@errno = global i32 0
@.str.1 = [14 x i8] c"sysio startup\00"
@optind = global i32 0
@.str.2 = [5 x i8] c"link\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, -1
br i1 %5, label %10, label %6
6: ; preds = %2, %6
%7 = tail call i32 (...) @usage()
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %6
10: ; preds = %6, %2
%11 = tail call i32 @_test_sysio_startup()
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = sub nsw i32 0, %11
store i32 %14, i32* @errno
%15 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = load i32, i32* @optind
%19 = sub nsw i32 %0, %18
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = tail call i32 (...) @usage()
%23 = load i32, i32* @optind
br label %24
24: ; preds = %21, %17
%25 = phi i32 [ %23, %21 ], [ %18, %17 ]
%26 = icmp slt i32 %25, %0
br i1 %26, label %27, label %50
27: ; preds = %24
%28 = bitcast %struct.stat* %3 to i8*
br label %29
29: ; preds = %27, %47
%30 = phi i32 [ %25, %27 ], [ %48, %47 ]
%31 = add nsw i32 %30, 1
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8*, i8** %1, i64 %32
%34 = load i8*, i8** %33
%35 = add nsw i32 %30, 2
store i32 %35, i32* @optind
%36 = sext i32 %31 to i64
%37 = getelementptr inbounds i8*, i8** %1, i64 %36
%38 = load i8*, i8** %37
%39 = tail call i32 @link(i8* %34, i8* %38)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %29
%42 = call i32 @lstat(i8* %38, %struct.stat* %3)
%43 = icmp eq i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41, %29
%45 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %29 ], [ %38, %41 ]
%46 = tail call i32 @perror(i8* %45)
br label %50
47: ; preds = %41
%48 = load i32, i32* @optind
%49 = icmp slt i32 %48, %0
br i1 %49, label %29, label %50
50: ; preds = %47, %24, %44
%51 = phi i32 [ -1, %44 ], [ 0, %24 ], [ 0, %47 ]
%52 = tail call i32 (...) @_test_sysio_shutdown()
ret i32 %51
}