#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 */
int /*<<< orphan*/ free(char **);
char getopt(int, char **, char *);
char **malloc(int);
int opterr;
int optind;
int optopt;
int /*<<< orphan*/ print_help(char *);
int /*<<< orphan*/ print_version(char *);
int preprocess_options(int argc, char *argv[]) {
  char **tmp_buf = malloc(sizeof(char *) * (argc));
  char c;
  int ret = 0;
  int i;
  int my_optind = optind;
  int my_opterr = opterr;
  int my_optopt = optopt;
  for (i = 0; i < argc; i++) {
    tmp_buf[i] = argv[i];
  }
  while ((c = getopt(argc, tmp_buf, "d:p:u:H:R:Vh")) != -1) {
    switch (c) {
    case 'V':
      print_version(argv[0]);
      ret = 1;
      break;
    case 'h':
      print_help(argv[0]);
      ret = 1;
      break;
    }
  }
  optind = my_optind;
  opterr = my_opterr;
  optopt = my_optopt;
  free(tmp_buf);
  return ret;
}


x86 assembly (clang, -O0):
<preprocess_options>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d6 <preprocess_options+0x86>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a4 <preprocess_options+0x54>
jmp    11db <preprocess_options+0x8b>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    0xe17(%rip),%rdx
call   1060 <getopt@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1253 <preprocess_options+0x103>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x56,%eax
je     1223 <preprocess_options+0xd3>
jmp    1212 <preprocess_options+0xc2>
mov    -0x34(%rbp),%eax
sub    $0x68,%eax
je     123b <preprocess_options+0xeb>
jmp    124e <preprocess_options+0xfe>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <print_version@plt>
movl   $0x1,-0x20(%rbp)
jmp    124e <preprocess_options+0xfe>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <print_help@plt>
movl   $0x1,-0x20(%rbp)
jmp    11db <preprocess_options+0x8b>
mov    -0x28(%rbp),%ecx
mov    0x2d83(%rip),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    0x2d67(%rip),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%ecx
mov    0x2d73(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<preprocess_options>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x0(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x2e49(%rip),%rax
mov    (%rax),%r13d
test   %ebx,%ebx
jle    11b7 <preprocess_options+0x57>
mov    %ebx,%edx
shl    $0x3,%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <memcpy@plt>
lea    0xe42(%rip),%rdx
mov    %ebx,%edi
mov    %r15,%rsi
call   1070 <getopt@plt>
xor    %ebp,%ebp
cmp    $0xff,%al
je     1215 <preprocess_options+0xb5>
lea    0xe2b(%rip),%r12
jmp    11fe <preprocess_options+0x9e>
nopw   0x0(%rax,%rax,1)
mov    (%r14),%rdi
call   1080 <print_help@plt>
mov    $0x1,%ebp
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1070 <getopt@plt>
cmp    $0xff,%al
je     1215 <preprocess_options+0xb5>
movsbl %al,%eax
cmp    $0x68,%eax
je     11e0 <preprocess_options+0x80>
cmp    $0x56,%eax
jne    11ed <preprocess_options+0x8d>
mov    (%r14),%rdi
call   1040 <print_version@plt>
jmp    11e8 <preprocess_options+0x88>
mov    0x2dc4(%rip),%rax
mov    0x4(%rsp),%ecx
mov    %ecx,(%rax)
mov    0x2da7(%rip),%rax
mov    (%rsp),%ecx
mov    %ecx,(%rax)
mov    0x2db3(%rip),%rax
mov    %r13d,(%rax)
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@optind = global i32 0
@opterr = global i32 0
@optopt = global i32 0
@.str = [13 x i8] c"d:p:u:H:R:Vh\00"
define i32 @preprocess_options(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = mul i64 8, %13
%15 = trunc i64 %14 to i32
%16 = call i8** @malloc(i32 %15)
store i8** %16, i8*** %5
store i32 0, i32* %7
%17 = load i32, i32* @optind
store i32 %17, i32* %9
%18 = load i32, i32* @opterr
store i32 %18, i32* %10
%19 = load i32, i32* @optopt
store i32 %19, i32* %11
store i32 0, i32* %8
br label %20
20: ; preds = %34, %2
%21 = load i32, i32* %8
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %37
24: ; preds = %20
%25 = load i8**, i8*** %4
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = load i8**, i8*** %5
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
store i8* %29, i8** %33
br label %34
34: ; preds = %24
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %20
37: ; preds = %20
br label %38
38: ; preds = %57, %37
%39 = load i32, i32* %3
%40 = load i8**, i8*** %5
%41 = call signext i8 @getopt(i32 %39, i8** %40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8 %41, i8* %6
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, -1
br i1 %43, label %44, label %58
44: ; preds = %38
%45 = load i8, i8* %6
%46 = sext i8 %45 to i32
switch i32 %46, label %57 [
i32 86, label %47
i32 104, label %52
]
47: ; preds = %44
%48 = load i8**, i8*** %4
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = call i32 @print_version(i8* %50)
store i32 1, i32* %7
br label %57
52: ; preds = %44
%53 = load i8**, i8*** %4
%54 = getelementptr inbounds i8*, i8** %53, i64 0
%55 = load i8*, i8** %54
%56 = call i32 @print_help(i8* %55)
store i32 1, i32* %7
br label %57
57: ; preds = %44, %52, %47
br label %38
58: ; preds = %38
%59 = load i32, i32* %9
store i32 %59, i32* @optind
%60 = load i32, i32* %10
store i32 %60, i32* @opterr
%61 = load i32, i32* %11
store i32 %61, i32* @optopt
%62 = load i8**, i8*** %5
%63 = call i32 @free(i8** %62)
%64 = load i32, i32* %7
ret i32 %64
}

LLVM IR (-O2):
@optind = global i32 0
@opterr = global i32 0
@optopt = global i32 0
@.str = [13 x i8] c"d:p:u:H:R:Vh\00"
define i32 @preprocess_options(i32 %0, i8** nocapture %1) {
%3 = shl i32 %0, 3
%4 = tail call i8** @malloc(i32 %3)
%5 = load i32, i32* @optind
%6 = load i32, i32* @opterr
%7 = load i32, i32* @optopt
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = bitcast i8** %4 to i8*
%11 = bitcast i8** %1 to i8*
%12 = zext i32 %0 to i64
%13 = shl nuw nsw i64 %12, 3
br label %14
14: ; preds = %9, %2
%15 = tail call signext i8 @getopt(i32 %0, i8** %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8 %15, -1
br i1 %16, label %31, label %17
17: ; preds = %14, %27
%18 = phi i8 [ %29, %27 ], [ %15, %14 ]
%19 = phi i32 [ %28, %27 ], [ 0, %14 ]
%20 = sext i8 %18 to i32
switch i32 %20, label %27 [
i32 86, label %21
i32 104, label %24
]
21: ; preds = %17
%22 = load i8*, i8** %1
%23 = tail call i32 @print_version(i8* %22)
br label %27
24: ; preds = %17
%25 = load i8*, i8** %1
%26 = tail call i32 @print_help(i8* %25)
br label %27
27: ; preds = %17, %24, %21
%28 = phi i32 [ %19, %17 ], [ 1, %24 ], [ 1, %21 ]
%29 = tail call signext i8 @getopt(i32 %0, i8** %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i8 %29, -1
br i1 %30, label %31, label %17
31: ; preds = %27, %14
%32 = phi i32 [ 0, %14 ], [ %28, %27 ]
store i32 %5, i32* @optind
store i32 %6, i32* @opterr
store i32 %7, i32* @optopt
%33 = tail call i32 @free(i8** %4)
ret i32 %32
}