#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 */
scalar_t__ file_exists(char *);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ print_version_info(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
char **parseopts(int argc, char **argv, int *script_argc) {
  int i;
  char **script_and_args = NULL;
  for (i = 1; i < argc; i++) {
    if (!strcmp(argv[i], "-V")) {
      if (script_and_args != NULL) {
        free(script_and_args);
        *(script_argc) = 0;
        script_and_args = NULL;
      }
      print_version_info(argv[0]);
      break;
    } else if (file_exists(argv[i])) {
      *(script_argc) = argc - i;
      script_and_args = argv + i * sizeof(char);
      break;
    } else {
      printf("warning, unrecognised argument \"%s\"\n", argv[i]);
    }
  }
  return script_and_args;
}


x86 assembly (clang, -O0):
<parseopts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1249 <parseopts+0xf9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11d6 <parseopts+0x86>
cmpq   $0x0,-0x28(%rbp)
je     11c5 <parseopts+0x75>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <print_version_info@plt>
jmp    1249 <parseopts+0xf9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%rax
je     1219 <parseopts+0xc9>
mov    -0x4(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0x0,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1249 <parseopts+0xf9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdd7(%rip),%rdi
call   1050 <printf@plt>
jmp    1236 <parseopts+0xe6>
jmp    123b <parseopts+0xeb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1172 <parseopts+0x22>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseopts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     11c6 <parseopts+0x86>
mov    %rdx,0x10(%rsp)
mov    %edi,%r14d
mov    %rsi,0x8(%rsp)
lea    0x8(%rsi),%rbx
mov    $0x1,%r15d
lea    0xe8f(%rip),%r12
lea    0xe8b(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rbp
mov    %rbp,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11b9 <parseopts+0x79>
mov    %rbp,%rdi
call   1030 <file_exists@plt>
test   %rax,%rax
jne    11da <parseopts+0x9a>
mov    (%rbx),%rsi
mov    %r13,%rdi
call   1040 <printf@plt>
add    $0x1,%r15
add    $0x8,%rbx
cmp    %r15,%r14
jne    1180 <parseopts+0x40>
jmp    11c6 <parseopts+0x86>
mov    0x8(%rsp),%rax
mov    (%rax),%rdi
call   1060 <print_version_info@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
sub    %r15d,%r14d
mov    0x10(%rsp),%rax
mov    %r14d,(%rax)
jmp    11c8 <parseopts+0x88>

LLVM IR (-O0):
@.str = [3 x i8] c"-V\00"
@.str.1 = [37 x i8] c"warning, unrecognised argument \22%s\22\0A\00"
define i8** @parseopts(i32 %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8**
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
store i8** null, i8*** %8
store i32 1, i32* %7
br label %9
9: ; preds = %60, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %63
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %33, label %21
21: ; preds = %13
%22 = load i8**, i8*** %8
%23 = icmp ne i8** %22, null
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i8**, i8*** %8
%26 = call i32 @free(i8** %25)
%27 = load i32*, i32** %6
store i32 0, i32* %27
store i8** null, i8*** %8
br label %28
28: ; preds = %24, %21
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @print_version_info(i8* %31)
br label %63
33: ; preds = %13
%34 = load i8**, i8*** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i64 @file_exists(i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %51
41: ; preds = %33
%42 = load i32, i32* %4
%43 = load i32, i32* %7
%44 = sub nsw i32 %42, %43
%45 = load i32*, i32** %6
store i32 %44, i32* %45
%46 = load i8**, i8*** %5
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = mul i64 %48, 1
%50 = getelementptr inbounds i8*, i8** %46, i64 %49
store i8** %50, i8*** %8
br label %63
51: ; preds = %33
%52 = load i8**, i8*** %5
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %56)
br label %58
58: ; preds = %51
br label %59
59: ; preds = %58
br label %60
60: ; preds = %59
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %9
63: ; preds = %41, %28, %9
%64 = load i8**, i8*** %8
ret i8** %64
}

LLVM IR (-O2):
@.str = [3 x i8] c"-V\00"
@.str.1 = [37 x i8] c"warning, unrecognised argument \22%s\22\0A\00"
define i8** @parseopts(i32 %0, i8** %1, i32* nocapture writeonly %2) {
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %27
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %22
%8 = phi i64 [ 1, %5 ], [ %25, %22 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i8*, i8** %1
%15 = tail call i32 @print_version_info(i8* %14)
br label %27
16: ; preds = %7
%17 = tail call i64 @file_exists(i8* %10)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = trunc i64 %8 to i32
%21 = sub nsw i32 %0, %20
store i32 %21, i32* %2
br label %27
22: ; preds = %16
%23 = load i8*, i8** %9
%24 = tail call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = add nuw nsw i64 %8, 1
%26 = icmp eq i64 %25, %6
br i1 %26, label %27, label %7
27: ; preds = %22, %3, %19, %13
%28 = phi i8** [ %9, %19 ], [ null, %13 ], [ null, %3 ], [ null, %22 ]
ret i8** %28
}