#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 option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
};

/* Variables and functions */
char EOF;
char getopt_long(int, char **, char *, struct option *, int *);
int /*<<< orphan*/ help();
scalar_t__ link(char *, char *);
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ unlink(char *);
int /*<<< orphan*/ version();
int main(int argc, char *argv[]) {
  int cmd_x;
  char ch;
  char optstring[] = "vh";
  struct option long_opts[] = {
      {"help", 0, 0, 'h'}, {"version", 0, 0, 'v'}, {NULL, 0, 0, 0}};
  while ((ch = getopt_long(argc, argv, optstring, long_opts, &cmd_x)) != EOF) {
    switch (ch) {
    case 'h':
      help();
      return 0;
    case 'v':
      version();
      return 0;
    default:
      printf("-%c: unkown option\n", ch);
      break;
    }
  }
  if (argc - optind < 1) {
    printf("Missing input arguments\n");
    return 0;
  } else if (argc - optind > 2) {
    printf("too many input files\n");
    return 0;
  }
  if (link(argv[optind], argv[optind + 1]) != 0) {
    perror(argv[optind]);
    perror(argv[optind + 1]);
    return 0;
  }
  if (unlink(argv[optind]) != 0) {
    perror(argv[optind]);
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe63(%rip),%ax
mov    %ax,-0x18(%rbp)
mov    0xe5b(%rip),%al
mov    %al,-0x16(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1060 <memset@plt>
lea    0xe42(%rip),%rax
mov    %rax,-0x60(%rbp)
movl   $0x68,-0x50(%rbp)
lea    0xe35(%rip),%rax
mov    %rax,-0x48(%rbp)
movl   $0x76,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <getopt_long@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%eax
mov    0x2de5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1271 <main+0xf1>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x64(%rbp)
sub    $0x68,%eax
je     1234 <main+0xb4>
jmp    1223 <main+0xa3>
mov    -0x64(%rbp),%eax
sub    $0x76,%eax
je     1247 <main+0xc7>
jmp    125a <main+0xda>
mov    $0x0,%al
call   1090 <help@plt>
movl   $0x0,-0x4(%rbp)
jmp    1396 <main+0x216>
mov    $0x0,%al
call   1070 <version@plt>
movl   $0x0,-0x4(%rbp)
jmp    1396 <main+0x216>
movsbl -0x15(%rbp),%esi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11de <main+0x5e>
mov    -0x8(%rbp),%eax
mov    0x2d65(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jge    12a0 <main+0x120>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1396 <main+0x216>
mov    -0x8(%rbp),%eax
mov    0x2d36(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x2,%eax
jle    12cf <main+0x14f>
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1396 <main+0x216>
jmp    12d4 <main+0x154>
mov    -0x10(%rbp),%rax
mov    0x2d01(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rax
mov    0x2cef(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   10a0 <link@plt>
cmp    $0x0,%rax
je     134b <main+0x1cb>
mov    -0x10(%rbp),%rax
mov    0x2cc9(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x2cb2(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1396 <main+0x216>
mov    -0x10(%rbp),%rax
mov    0x2c8a(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     138f <main+0x20f>
mov    -0x10(%rbp),%rax
mov    0x2c69(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1396 <main+0x216>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movb   $0x0,0xa(%rsp)
movw   $0x6876,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movq   $0x0,0x50(%rsp)
lea    0xe3d(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0x68,0x20(%rsp)
lea    0xe2e(%rip),%rax
mov    %rax,0x28(%rsp)
movl   $0x76,0x38(%rsp)
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1050 <getopt_long@plt>
mov    0x2de6(%rip),%r14
cmp    (%r14),%al
je     125b <main+0xdb>
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%esi
cmp    $0x76,%esi
je     12b7 <main+0x137>
cmp    $0x68,%esi
je     12c0 <main+0x140>
lea    0xdd4(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1050 <getopt_long@plt>
cmp    (%r14),%al
jne    1220 <main+0xa0>
mov    0x2d7e(%rip),%r14
movslq (%r14),%rax
sub    %eax,%ebp
jle    127c <main+0xfc>
cmp    $0x3,%ebp
jb     128a <main+0x10a>
lea    0xdaf(%rip),%rdi
call   1040 <puts@plt>
jmp    12c7 <main+0x147>
lea    0xdb6(%rip),%rdi
call   1040 <puts@plt>
jmp    12c7 <main+0x147>
mov    (%rbx,%rax,8),%rdi
mov    0x8(%rbx,%rax,8),%rsi
call   10a0 <link@plt>
movslq (%r14),%rcx
mov    (%rbx,%rcx,8),%rdi
test   %rax,%rax
jne    12d8 <main+0x158>
call   1030 <unlink@plt>
test   %rax,%rax
je     12c7 <main+0x147>
movslq (%r14),%rax
mov    (%rbx,%rax,8),%rdi
jmp    12e5 <main+0x165>
xor    %eax,%eax
call   1070 <version@plt>
jmp    12c7 <main+0x147>
xor    %eax,%eax
call   1090 <help@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
call   1080 <perror@plt>
movslq (%r14),%rax
mov    0x8(%rbx,%rax,8),%rdi
call   1080 <perror@plt>
jmp    12c7 <main+0x147>

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
@__const.main.optstring = [3 x i8] c"vh\00"
@.str = [5 x i8] c"help\00"
@.str.1 = [8 x i8] c"version\00"
@EOF = global i8 0
@.str.2 = [20 x i8] c"-%c: unkown option\0A\00"
@optind = global i32 0
@.str.3 = [25 x i8] c"Missing input arguments\0A\00"
@.str.4 = [22 x i8] c"too many input files\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 [3 x i8]
%9 = alloca [3 x %struct.option]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [3 x i8]* %8 to i8*
%11 = bitcast [3 x %struct.option]* %9 to i8*
%12 = bitcast i8* %11 to [3 x %struct.option]*
%13 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %12, i32 0, i32 0
%14 = getelementptr inbounds %struct.option, %struct.option* %13, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds %struct.option, %struct.option* %13, i32 0, i32 3
store i32 104, i32* %15
%16 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %12, i32 0, i32 1
%17 = getelementptr inbounds %struct.option, %struct.option* %16, i32 0, i32 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds %struct.option, %struct.option* %16, i32 0, i32 3
store i32 118, i32* %18
br label %19
19: ; preds = %40, %2
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%23 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %9, i64 0, i64 0
%24 = call signext i8 @getopt_long(i32 %20, i8** %21, i8* %22, %struct.option* %23, i32* %6)
store i8 %24, i8* %7
%25 = sext i8 %24 to i32
%26 = load i8, i8* @EOF
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %25, %27
br i1 %28, label %29, label %41
29: ; preds = %19
%30 = load i8, i8* %7
%31 = sext i8 %30 to i32
switch i32 %31, label %36 [
i32 104, label %32
i32 118, label %34
]
32: ; preds = %29
%33 = call i32 (...) @help()
store i32 0, i32* %3
br label %100
34: ; preds = %29
%35 = call i32 (...) @version()
store i32 0, i32* %3
br label %100
36: ; preds = %29
%37 = load i8, i8* %7
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %36
br label %19
41: ; preds = %19
%42 = load i32, i32* %4
%43 = load i32, i32* @optind
%44 = sub nsw i32 %42, %43
%45 = icmp slt i32 %44, 1
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %100
48: ; preds = %41
%49 = load i32, i32* %4
%50 = load i32, i32* @optind
%51 = sub nsw i32 %49, %50
%52 = icmp sgt i32 %51, 2
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %100
55: ; preds = %48
br label %56
56: ; preds = %55
%57 = load i8**, i8*** %5
%58 = load i32, i32* @optind
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = load i8**, i8*** %5
%63 = load i32, i32* @optind
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8*, i8** %62, i64 %65
%67 = load i8*, i8** %66
%68 = call i64 @link(i8* %61, i8* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %84
70: ; preds = %56
%71 = load i8**, i8*** %5
%72 = load i32, i32* @optind
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i32 @perror(i8* %75)
%77 = load i8**, i8*** %5
%78 = load i32, i32* @optind
%79 = add nsw i32 %78, 1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8*, i8** %77, i64 %80
%82 = load i8*, i8** %81
%83 = call i32 @perror(i8* %82)
store i32 0, i32* %3
br label %100
84: ; preds = %56
%85 = load i8**, i8*** %5
%86 = load i32, i32* @optind
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8*, i8** %85, i64 %87
%89 = load i8*, i8** %88
%90 = call i64 @unlink(i8* %89)
%91 = icmp ne i64 %90, 0
br i1 %91, label %92, label %99
92: ; preds = %84
%93 = load i8**, i8*** %5
%94 = load i32, i32* @optind
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8*, i8** %93, i64 %95
%97 = load i8*, i8** %96
%98 = call i32 @perror(i8* %97)
store i32 0, i32* %3
br label %100
99: ; preds = %84
store i32 0, i32* %3
br label %100
100: ; preds = %99, %92, %70, %53, %46, %34, %32
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@__const.main.optstring = [3 x i8] c"vh\00"
@.str = [5 x i8] c"help\00"
@.str.1 = [8 x i8] c"version\00"
@EOF = global i8 0
@.str.2 = [20 x i8] c"-%c: unkown option\0A\00"
@optind = global i32 0
@str = [21 x i8] c"too many input files\00"
@str.5 = [24 x i8] c"Missing input arguments\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca [3 x i8]
%5 = alloca [3 x %struct.option]
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%8 = bitcast [3 x %struct.option]* %5 to i8*
%9 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %5, i64 0, i64 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %5, i64 0, i64 0, i32 3
store i32 104, i32* %10
%11 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %5, i64 0, i64 1, i32 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %5, i64 0, i64 1, i32 3
store i32 118, i32* %12
%13 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %5, i64 0, i64 0
%14 = call signext i8 @getopt_long(i32 %0, i8** %1, i8* %7, %struct.option* %13, i32* %3)
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %29, label %17
17: ; preds = %2, %24
%18 = phi i8 [ %26, %24 ], [ %14, %2 ]
%19 = sext i8 %18 to i32
switch i32 %19, label %24 [
i32 104, label %20
i32 118, label %22
]
20: ; preds = %17
%21 = call i32 (...) @help()
br label %70
22: ; preds = %17
%23 = call i32 (...) @version()
br label %70
24: ; preds = %17
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%26 = call signext i8 @getopt_long(i32 %0, i8** %1, i8* %7, %struct.option* %13, i32* %3)
%27 = load i8, i8* @EOF
%28 = icmp eq i8 %26, %27
br i1 %28, label %29, label %17
29: ; preds = %24, %2
%30 = load i32, i32* @optind
%31 = sub nsw i32 %0, %30
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
br label %70
35: ; preds = %29
%36 = icmp ugt i32 %31, 2
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %70
39: ; preds = %35
%40 = sext i32 %30 to i64
%41 = getelementptr inbounds i8*, i8** %1, i64 %40
%42 = load i8*, i8** %41
%43 = add nsw i32 %30, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %1, i64 %44
%46 = load i8*, i8** %45
%47 = call i64 @link(i8* %42, i8* %46)
%48 = icmp eq i64 %47, 0
%49 = load i32, i32* @optind
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %1, i64 %50
%52 = load i8*, i8** %51
br i1 %48, label %61, label %53
53: ; preds = %39
%54 = call i32 @perror(i8* %52)
%55 = load i32, i32* @optind
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %1, i64 %57
%59 = load i8*, i8** %58
%60 = call i32 @perror(i8* %59)
br label %70
61: ; preds = %39
%62 = call i64 @unlink(i8* %52)
%63 = icmp eq i64 %62, 0
br i1 %63, label %70, label %64
64: ; preds = %61
%65 = load i32, i32* @optind
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %1, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 @perror(i8* %68)
br label %70
70: ; preds = %61, %64, %53, %37, %33, %22, %20
ret i32 0
}