#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*/ fprintf(int /*<<< orphan*/, char *, char *, char);
int getopt(int, char **, char const *);
char *optarg;
int optind;
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
int getoldopt(int argc, char **argv, const char *optstring) {
  static char *key;
  static char use_getopt;
  char c;
  char *place;
  optarg = NULL;
  if (key == NULL) {
    if (argc < 2)
      return (-1);
    key = argv[1];
    if (*key == '-')
      use_getopt++;
    else
      optind = 2;
  }
  if (use_getopt)
    return (getopt(argc, argv, optstring));
  c = *key++;
  if (c == '\0') {
    key--;
    return (-1);
  }
  place = strchr(optstring, c);
  if (place == NULL || c == ':') {
    fprintf(stderr, "%s: unknown option %c\n", argv[0], c);
    return ('?');
  }
  place++;
  if (*place == ':') {
    if (optind < argc) {
      optarg = argv[optind];
      optind++;
    } else {
      fprintf(stderr, "%s: %c argument missing\n", argv[0], c);
      return ('?');
    }
  }
  return (c);
}


x86 assembly (clang, -O0):
<getoldopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2eae(%rip),%rax
movq   $0x0,(%rax)
cmpq   $0x0,0x2ee7(%rip)
jne    11bc <getoldopt+0x8c>
cmpl   $0x2,-0x8(%rbp)
jge    1175 <getoldopt+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    1317 <getoldopt+0x1e7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,0x2ebc(%rip)
mov    0x2eb5(%rip),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11aa <getoldopt+0x7a>
mov    0x2eab(%rip),%al
add    $0x1,%al
mov    %al,0x2ea3(%rip)
jmp    11b7 <getoldopt+0x87>
mov    0x2e2f(%rip),%rax
movl   $0x2,(%rax)
jmp    11bc <getoldopt+0x8c>
cmpb   $0x0,0x2e85(%rip)
je     11e1 <getoldopt+0xb1>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x4(%rbp)
jmp    1317 <getoldopt+0x1e7>
mov    0x2e58(%rip),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,0x2e4a(%rip)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    1226 <getoldopt+0xf6>
mov    0x2e31(%rip),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x2e26(%rip)
movl   $0xffffffff,-0x4(%rbp)
jmp    1317 <getoldopt+0x1e7>
mov    -0x18(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     124f <getoldopt+0x11f>
movsbl -0x19(%rbp),%eax
cmp    $0x3a,%eax
jne    127b <getoldopt+0x14b>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd9a(%rip),%rsi
movsbl -0x19(%rbp),%ecx
call   1040 <fprintf@plt>
movl   $0x3f,-0x4(%rbp)
jmp    1317 <getoldopt+0x1e7>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    1310 <getoldopt+0x1e0>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    12df <getoldopt+0x1af>
mov    -0x10(%rbp),%rax
mov    0x2d2c(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rcx
mov    0x2d36(%rip),%rax
mov    %rcx,(%rax)
mov    0x2d14(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2d08(%rip),%rax
mov    %ecx,(%rax)
jmp    130b <getoldopt+0x1db>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd21(%rip),%rsi
movsbl -0x19(%rbp),%ecx
call   1040 <fprintf@plt>
movl   $0x3f,-0x4(%rbp)
jmp    1317 <getoldopt+0x1e7>
jmp    1310 <getoldopt+0x1e0>
movsbl -0x19(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getoldopt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2eb5(%rip),%r15
movq   $0x0,(%r15)
mov    0x2eef(%rip),%rax
test   %rax,%rax
je     1174 <getoldopt+0x44>
mov    0x2eec(%rip),%cl
test   %cl,%cl
je     11a5 <getoldopt+0x75>
mov    %ebx,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <getopt@plt>
mov    $0xffffffff,%ebp
cmp    $0x2,%ebx
jl     1242 <getoldopt+0x112>
mov    0x8(%r14),%rax
mov    %rax,0x2eb3(%rip)
cmpb   $0x2d,(%rax)
jne    1211 <getoldopt+0xe1>
mov    0x2eb0(%rip),%cl
add    $0x1,%cl
mov    %cl,0x2ea7(%rip)
test   %cl,%cl
jne    1160 <getoldopt+0x30>
lea    0x1(%rax),%rcx
mov    %rcx,0x2e90(%rip)
movsbl (%rax),%ebp
test   %ebp,%ebp
je     11ee <getoldopt+0xbe>
mov    %rdx,%rdi
mov    %ebp,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11fc <getoldopt+0xcc>
cmp    $0x3a,%bpl
je     11fc <getoldopt+0xcc>
cmpb   $0x3a,0x1(%rax)
jne    1242 <getoldopt+0x112>
mov    0x2e07(%rip),%rax
movslq (%rax),%rcx
cmp    %ebx,%ecx
jge    1223 <getoldopt+0xf3>
mov    (%r14,%rcx,8),%rdx
mov    %rdx,(%r15)
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1242 <getoldopt+0x112>
mov    %rax,0x2e4b(%rip)
mov    $0xffffffff,%ebp
jmp    1242 <getoldopt+0x112>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdf1(%rip),%rsi
jmp    1236 <getoldopt+0x106>
mov    0x2dc8(%rip),%rcx
movl   $0x2,(%rcx)
jmp    1156 <getoldopt+0x26>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xde1(%rip),%rsi
mov    %ebp,%ecx
call   1040 <fprintf@plt>
mov    $0x3f,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@getoldopt.key = internal global i8* null
@getoldopt.use_getopt = internal global i8 0
@optarg = global i8* null
@optind = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"%s: unknown option %c\0A\00"
@.str.1 = [25 x i8] c"%s: %c argument missing\0A\00"
define i32 @getoldopt(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8*
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
store i8* null, i8** @optarg
%10 = load i8*, i8** @getoldopt.key
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %29
12: ; preds = %3
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 -1, i32* %4
br label %94
16: ; preds = %12
%17 = load i8**, i8*** %6
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** @getoldopt.key
%20 = load i8*, i8** @getoldopt.key
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 45
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = load i8, i8* @getoldopt.use_getopt
%26 = add i8 %25, 1
store i8 %26, i8* @getoldopt.use_getopt
br label %28
27: ; preds = %16
store i32 2, i32* @optind
br label %28
28: ; preds = %27, %24
br label %29
29: ; preds = %28, %3
%30 = load i8, i8* @getoldopt.use_getopt
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i32, i32* %5
%34 = load i8**, i8*** %6
%35 = load i8*, i8** %7
%36 = call i32 @getopt(i32 %33, i8** %34, i8* %35)
store i32 %36, i32* %4
br label %94
37: ; preds = %29
%38 = load i8*, i8** @getoldopt.key
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** @getoldopt.key
%40 = load i8, i8* %38
store i8 %40, i8* %8
%41 = load i8, i8* %8
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %37
%45 = load i8*, i8** @getoldopt.key
%46 = getelementptr inbounds i8, i8* %45, i32 -1
store i8* %46, i8** @getoldopt.key
store i32 -1, i32* %4
br label %94
47: ; preds = %37
%48 = load i8*, i8** %7
%49 = load i8, i8* %8
%50 = call i8* @strchr(i8* %48, i8 signext %49)
store i8* %50, i8** %9
%51 = load i8*, i8** %9
%52 = icmp eq i8* %51, null
br i1 %52, label %57, label %53
53: ; preds = %47
%54 = load i8, i8* %8
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 58
br i1 %56, label %57, label %64
57: ; preds = %53, %47
%58 = load i32, i32* @stderr
%59 = load i8**, i8*** %6
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i8, i8* %8
%63 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %61, i8 signext %62)
store i32 63, i32* %4
br label %94
64: ; preds = %53
%65 = load i8*, i8** %9
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %9
%67 = load i8*, i8** %9
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 58
br i1 %70, label %71, label %91
71: ; preds = %64
%72 = load i32, i32* @optind
%73 = load i32, i32* %5
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %83
75: ; preds = %71
%76 = load i8**, i8*** %6
%77 = load i32, i32* @optind
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %76, i64 %78
%80 = load i8*, i8** %79
store i8* %80, i8** @optarg
%81 = load i32, i32* @optind
%82 = add nsw i32 %81, 1
store i32 %82, i32* @optind
br label %90
83: ; preds = %71
%84 = load i32, i32* @stderr
%85 = load i8**, i8*** %6
%86 = getelementptr inbounds i8*, i8** %85, i64 0
%87 = load i8*, i8** %86
%88 = load i8, i8* %8
%89 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %87, i8 signext %88)
store i32 63, i32* %4
br label %94
90: ; preds = %75
br label %91
91: ; preds = %90, %64
%92 = load i8, i8* %8
%93 = sext i8 %92 to i32
store i32 %93, i32* %4
br label %94
94: ; preds = %91, %83, %57, %44, %32, %15
%95 = load i32, i32* %4
ret i32 %95
}

LLVM IR (-O2):
@getoldopt.key = internal unnamed_addr global i8* null
@getoldopt.use_getopt = internal unnamed_addr global i8 0
@optarg = global i8* null
@optind = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"%s: unknown option %c\0A\00"
@.str.1 = [25 x i8] c"%s: %c argument missing\0A\00"
define i32 @getoldopt(i32 %0, i8** %1, i8* %2) {
store i8* null, i8** @optarg
%4 = load i8*, i8** @getoldopt.key
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %17
6: ; preds = %3
%7 = icmp slt i32 %0, 2
br i1 %7, label %57, label %8
8: ; preds = %6
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
store i8* %10, i8** @getoldopt.key
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 45
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8, i8* @getoldopt.use_getopt
%15 = add i8 %14, 1
store i8 %15, i8* @getoldopt.use_getopt
br label %20
16: ; preds = %8
store i32 2, i32* @optind
br label %17
17: ; preds = %3, %16
%18 = phi i8* [ %4, %3 ], [ %10, %16 ]
%19 = load i8, i8* @getoldopt.use_getopt
br label %20
20: ; preds = %17, %13
%21 = phi i8* [ %18, %17 ], [ %10, %13 ]
%22 = phi i8 [ %19, %17 ], [ %15, %13 ]
%23 = icmp eq i8 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = tail call i32 @getopt(i32 %0, i8** %1, i8* %2)
br label %57
26: ; preds = %20
%27 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %27, i8** @getoldopt.key
%28 = load i8, i8* %21
%29 = sext i8 %28 to i32
%30 = icmp eq i8 %28, 0
br i1 %30, label %31, label %32
31: ; preds = %26
store i8* %21, i8** @getoldopt.key
br label %57
32: ; preds = %26
%33 = tail call i8* @strchr(i8* dereferenceable(1) %2, i8 signext %28)
%34 = icmp eq i8* %33, null
%35 = icmp eq i8 %28, 58
%36 = select i1 %34, i1 true, i1 %35
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %1
%40 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %39, i8 signext %28)
br label %57
41: ; preds = %32
%42 = getelementptr inbounds i8, i8* %33, i64 1
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 58
br i1 %44, label %45, label %57
45: ; preds = %41
%46 = load i32, i32* @optind
%47 = icmp slt i32 %46, %0
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = sext i32 %46 to i64
%50 = getelementptr inbounds i8*, i8** %1, i64 %49
%51 = load i8*, i8** %50
store i8* %51, i8** @optarg
%52 = add nsw i32 %46, 1
store i32 %52, i32* @optind
br label %57
53: ; preds = %45
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %1
%56 = tail call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %55, i8 signext %28)
br label %57
57: ; preds = %41, %48, %6, %53, %37, %31, %24
%58 = phi i32 [ %25, %24 ], [ -1, %31 ], [ 63, %37 ], [ 63, %53 ], [ -1, %6 ], [ %29, %48 ], [ %29, %41 ]
ret i32 %58
}