#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;
scalar_t__ chdir(char *);
char getopt_long(int, char **, char *, struct option *, int *);
int /*<<< orphan*/ help();
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ version();
int main(int argc, char *argv[]) {
  int cmd_x;
  char optstring[] = "hv";
  char optch;
  struct option long_opts[] = {
      {"help", 0, 0, 'h'}, {"version", 0, 0, 'v'}, {NULL, 0, 0, 0}};
  while ((optch = getopt_long(argc, argv, optstring, long_opts, &cmd_x)) !=
         EOF) {
    switch (optch) {
    case 'h':
      help();
      return 0;
    case 'v':
      version();
      return 0;
    default:
      printf("-%c: Unkown option\n", optch);
      break;
    }
  }
  if (argc - optind < 1) {
    printf("Incomplete input\n");
    return 0;
  } else if (argc - optind > 1) {
    printf("Too much inputs\n");
    return 0;
  }
  if (chdir(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    0xe73(%rip),%ax
mov    %ax,-0x17(%rbp)
mov    0xe6b(%rip),%al
mov    %al,-0x15(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1060 <memset@plt>
lea    0xe52(%rip),%rax
mov    %rax,-0x60(%rbp)
movl   $0x68,-0x50(%rbp)
lea    0xe45(%rip),%rax
mov    %rax,-0x48(%rbp)
movl   $0x76,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x17(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <getopt_long@plt>
mov    %al,-0x18(%rbp)
movsbl %al,%eax
mov    0x2df5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1261 <main+0xf1>
movsbl -0x18(%rbp),%eax
mov    %eax,-0x64(%rbp)
sub    $0x68,%eax
je     1224 <main+0xb4>
jmp    1213 <main+0xa3>
mov    -0x64(%rbp),%eax
sub    $0x76,%eax
je     1237 <main+0xc7>
jmp    124a <main+0xda>
mov    $0x0,%al
call   1090 <help@plt>
movl   $0x0,-0x4(%rbp)
jmp    130f <main+0x19f>
mov    $0x0,%al
call   1070 <version@plt>
movl   $0x0,-0x4(%rbp)
jmp    130f <main+0x19f>
movsbl -0x18(%rbp),%esi
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ce <main+0x5e>
mov    -0x8(%rbp),%eax
mov    0x2d75(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jge    1290 <main+0x120>
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    130f <main+0x19f>
mov    -0x8(%rbp),%eax
mov    0x2d46(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x1,%eax
jle    12bf <main+0x14f>
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    130f <main+0x19f>
jmp    12c4 <main+0x154>
mov    -0x10(%rbp),%rax
mov    0x2d11(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
je     1308 <main+0x198>
mov    -0x10(%rbp),%rax
mov    0x2cf0(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    130f <main+0x19f>
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   $0x7668,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    0xe4d(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0x68,0x20(%rsp)
lea    0xe3e(%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    0x2df6(%rip),%r14
cmp    (%r14),%al
je     1243 <main+0xd3>
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     128e <main+0x11e>
cmp    $0x68,%esi
je     1297 <main+0x127>
lea    0xdec(%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    1210 <main+0xa0>
mov    0x2d96(%rip),%r14
movslq (%r14),%rax
sub    %eax,%ebp
jle    1272 <main+0x102>
cmp    $0x1,%ebp
jne    1280 <main+0x110>
mov    (%rbx,%rax,8),%rdi
call   1040 <chdir@plt>
test   %rax,%rax
je     129e <main+0x12e>
movslq (%r14),%rax
mov    (%rbx,%rax,8),%rdi
call   1080 <perror@plt>
jmp    129e <main+0x12e>
lea    0xdbb(%rip),%rdi
call   1030 <puts@plt>
jmp    129e <main+0x12e>
lea    0xd9d(%rip),%rdi
call   1030 <puts@plt>
jmp    129e <main+0x12e>
xor    %eax,%eax
call   1070 <version@plt>
jmp    129e <main+0x12e>
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

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
@__const.main.optstring = [3 x i8] c"hv\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 = [18 x i8] c"Incomplete input\0A\00"
@.str.4 = [17 x i8] c"Too much inputs\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [3 x i8]
%8 = alloca 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]* %7 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]* %7, 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* %8
%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* %8
%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 %72
34: ; preds = %29
%35 = call i32 (...) @version()
store i32 0, i32* %3
br label %72
36: ; preds = %29
%37 = load i8, i8* %8
%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 ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %72
48: ; preds = %41
%49 = load i32, i32* %4
%50 = load i32, i32* @optind
%51 = sub nsw i32 %49, %50
%52 = icmp sgt i32 %51, 1
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %72
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 = call i64 @chdir(i8* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %71
64: ; preds = %56
%65 = load i8**, i8*** %5
%66 = load i32, i32* @optind
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
%69 = load i8*, i8** %68
%70 = call i32 @perror(i8* %69)
store i32 0, i32* %3
br label %72
71: ; preds = %56
store i32 0, i32* %3
br label %72
72: ; preds = %71, %64, %53, %46, %34, %32
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@__const.main.optstring = [3 x i8] c"hv\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 = [16 x i8] c"Too much inputs\00"
@str.5 = [17 x i8] c"Incomplete input\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 %51
22: ; preds = %17
%23 = call i32 (...) @version()
br label %51
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 ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
br label %51
35: ; preds = %29
%36 = icmp eq i32 %31, 1
br i1 %36, label %39, label %37
37: ; preds = %35
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %51
39: ; preds = %35
%40 = sext i32 %30 to i64
%41 = getelementptr inbounds i8*, i8** %1, i64 %40
%42 = load i8*, i8** %41
%43 = call i64 @chdir(i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %39
%46 = load i32, i32* @optind
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 @perror(i8* %49)
br label %51
51: ; preds = %39, %45, %37, %33, %22, %20
ret i32 0
}