#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 *, ...);
int getopt(int, char **, char *);
char *optarg;
int optind;
int optopt;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int opt;
  char *pstr;
  pstr = NULL;
  while ((opt = getopt(argc, argv, ":ngl:")) != -1) {
    switch (opt) {
    case 'n':
      printf("my name\n");
      break;
    case 'g':
      printf("my girlfriend\n");
      break;
    case 'l':
      pstr = optarg;
      printf("%s\n", pstr);
      break;
    case ':':
      fprintf(stderr, "Missing argument (-%c)\n", optopt);
      break;
    case '?':
      fprintf(stderr, "Unrecognized option (-%c)\n", optopt);
      break;
    default:
      fprintf(stderr, "Unexpected case in switch()\n");
      break;
    }
  }
  printf("argc = %d, optind = %d\n", argc, optind);
  if (optind < argc) {
    printf("non-option ARGV-elements:\n");
    while (optind < argc) {
      printf("\"%s\" at argv[%d]\n", argv[optind], optind);
      ++optind;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xea4(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1276 <main+0x146>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x3a,%eax
je     1210 <main+0xe0>
jmp    1181 <main+0x51>
mov    -0x24(%rbp),%eax
sub    $0x3f,%eax
je     1235 <main+0x105>
jmp    1192 <main+0x62>
mov    -0x24(%rbp),%eax
sub    $0x67,%eax
je     11d8 <main+0xa8>
jmp    11a3 <main+0x73>
mov    -0x24(%rbp),%eax
sub    $0x6c,%eax
je     11eb <main+0xbb>
jmp    11b4 <main+0x84>
mov    -0x24(%rbp),%eax
sub    $0x6e,%eax
jne    125a <main+0x12a>
jmp    11c5 <main+0x95>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <main+0x141>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <main+0x141>
mov    0x2e06(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1271 <main+0x141>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1271 <main+0x141>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    0x2d9b(%rip),%rax
mov    (%rax),%edx
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1271 <main+0x141>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    114e <main+0x1e>
mov    -0x8(%rbp),%esi
mov    0x2d58(%rip),%rax
mov    (%rax),%edx
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    130a <main+0x1da>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1305 <main+0x1d5>
mov    -0x10(%rbp),%rax
mov    0x2d0b(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
mov    0x2cfd(%rip),%rax
mov    (%rax),%edx
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2cda(%rip),%rax
mov    %ecx,(%rax)
jmp    12b0 <main+0x180>
jmp    130a <main+0x1da>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xea9(%rip),%r14
mov    0x2e6a(%rip),%r13
mov    0x2e7b(%rip),%r15
lea    0xf3c(%rip),%r12
jmp    1183 <main+0x43>
mov    0x0(%r13),%edi
mov    (%r15),%edx
lea    0xe8a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
cmp    $0x66,%eax
jle    11b0 <main+0x70>
cmp    $0x67,%eax
je     11ca <main+0x8a>
cmp    $0x6c,%eax
je     11d8 <main+0x98>
cmp    $0x6e,%eax
jne    11ee <main+0xae>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    1183 <main+0x43>
xchg   %ax,%ax
cmp    $0x3a,%eax
je     116e <main+0x2e>
cmp    $0x3f,%eax
jne    11e9 <main+0xa9>
mov    0x0(%r13),%edi
mov    (%r15),%edx
lea    0xe56(%rip),%rsi
jmp    117c <main+0x3c>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
jmp    1183 <main+0x43>
mov    0x2e19(%rip),%rax
mov    (%rax),%rdi
call   1030 <puts@plt>
jmp    1183 <main+0x43>
cmp    $0xffffffff,%eax
je     1202 <main+0xc2>
mov    0x0(%r13),%edi
lea    0xe40(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1183 <main+0x43>
mov    0x2dcf(%rip),%r15
mov    (%r15),%edx
lea    0xe43(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebp,(%r15)
jge    125e <main+0x11e>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%eax
cmp    %ebp,%eax
jge    125e <main+0x11e>
lea    0xe33(%rip),%r14
nopl   0x0(%rax,%rax,1)
movslq %eax,%rdx
mov    (%rbx,%rdx,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%eax
add    $0x1,%eax
mov    %eax,(%r15)
cmp    %ebp,%eax
jl     1240 <main+0x100>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c":ngl:\00"
@.str.1 = [9 x i8] c"my name\0A\00"
@.str.2 = [15 x i8] c"my girlfriend\0A\00"
@optarg = global i8* null
@.str.3 = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Missing argument (-%c)\0A\00"
@optopt = global i32 0
@.str.5 = [27 x i8] c"Unrecognized option (-%c)\0A\00"
@.str.6 = [29 x i8] c"Unexpected case in switch()\0A\00"
@.str.7 = [24 x i8] c"argc = %d, optind = %d\0A\00"
@optind = global i32 0
@.str.8 = [27 x i8] c"non-option ARGV-elements:\0A\00"
@.str.9 = [18 x i8] c"\22%s\22 at argv[%d]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
br label %8
8: ; preds = %34, %2
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %6
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %35
13: ; preds = %8
%14 = load i32, i32* %6
switch i32 %14, label %31 [
i32 110, label %15
i32 103, label %17
i32 108, label %19
i32 58, label %23
i32 63, label %27
]
15: ; preds = %13
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %34
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %34
19: ; preds = %13
%20 = load i8*, i8** @optarg
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %21)
br label %34
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = load i32, i32* @optopt
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %34
27: ; preds = %13
%28 = load i32, i32* @stderr
%29 = load i32, i32* @optopt
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %29)
br label %34
31: ; preds = %13
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %34
34: ; preds = %31, %27, %23, %19, %17, %15
br label %8
35: ; preds = %8
%36 = load i32, i32* %4
%37 = load i32, i32* @optind
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %36, i32 %37)
%39 = load i32, i32* @optind
%40 = load i32, i32* %4
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %59
42: ; preds = %35
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
br label %44
44: ; preds = %48, %42
%45 = load i32, i32* @optind
%46 = load i32, i32* %4
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %58
48: ; preds = %44
%49 = load i8**, i8*** %5
%50 = load i32, i32* @optind
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = load i32, i32* @optind
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %53, i32 %54)
%56 = load i32, i32* @optind
%57 = add nsw i32 %56, 1
store i32 %57, i32* @optind
br label %44
58: ; preds = %44
br label %59
59: ; preds = %58, %35
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c":ngl:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.4 = [24 x i8] c"Missing argument (-%c)\0A\00"
@optopt = global i32 0
@.str.5 = [27 x i8] c"Unrecognized option (-%c)\0A\00"
@.str.6 = [29 x i8] c"Unexpected case in switch()\0A\00"
@.str.7 = [24 x i8] c"argc = %d, optind = %d\0A\00"
@optind = global i32 0
@.str.9 = [18 x i8] c"\22%s\22 at argv[%d]\0A\00"
@str = [26 x i8] c"non-option ARGV-elements:\00"
@str.10 = [14 x i8] c"my girlfriend\00"
@str.11 = [8 x i8] c"my name\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %23, %2
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %4, label %20 [
i32 -1, label %24
i32 110, label %5
i32 103, label %7
i32 108, label %9
i32 58, label %12
i32 63, label %16
]
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.11, i64 0, i64 0))
br label %23
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.10, i64 0, i64 0))
br label %23
9: ; preds = %3
%10 = load i8*, i8** @optarg
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
br label %23
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i32, i32* @optopt
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %14)
br label %23
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i32, i32* @optopt
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %18)
br label %23
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %23
23: ; preds = %20, %16, %12, %9, %7, %5
br label %3
24: ; preds = %3
%25 = load i32, i32* @optind
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %0, i32 %25)
%27 = load i32, i32* @optind
%28 = icmp slt i32 %27, %0
br i1 %28, label %29, label %42
29: ; preds = %24
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%31 = load i32, i32* @optind
%32 = icmp slt i32 %31, %0
br i1 %32, label %33, label %42
33: ; preds = %29, %33
%34 = phi i32 [ %40, %33 ], [ %31, %29 ]
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %1, i64 %35
%37 = load i8*, i8** %36
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %37, i32 %34)
%39 = load i32, i32* @optind
%40 = add nsw i32 %39, 1
store i32 %40, i32* @optind
%41 = icmp slt i32 %40, %0
br i1 %41, label %33, label %42
42: ; preds = %33, %29, %24
ret i32 0
}