#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 getopt(int, char **, char *);
char *optarg;
int optind;
scalar_t__ optopt;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int arg;
  if (argc < 2) {
    printf("no arguments\n");
  }
  while ((arg = getopt(argc, argv, "ab:c")) != -1) {
    printf("optind: %d\n", optind);
    switch (arg) {
    case 'a':
      printf("option: a\n");
      break;
    case 'b':
      printf("option: b\n");
      printf("argument of -b: %s\n", optarg);
      break;
    case 'c':
      printf("option: c\n");
      break;
    default:
      printf("unknow option: %c\n", (char)optopt);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    114e <main+0x2e>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1153 <main+0x33>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xead(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1230 <main+0x110>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x61,%eax
je     11bf <main+0x9f>
jmp    119d <main+0x7d>
mov    -0x18(%rbp),%eax
sub    $0x62,%eax
je     11d2 <main+0xb2>
jmp    11ae <main+0x8e>
mov    -0x18(%rbp),%eax
sub    $0x63,%eax
je     11fd <main+0xdd>
jmp    1210 <main+0xf0>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122b <main+0x10b>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122b <main+0x10b>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122b <main+0x10b>
mov    0x2dc9(%rip),%rax
mov    (%rax),%rax
movsbl %al,%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1153 <main+0x33>
xor    %eax,%eax
add    $0x20,%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
cmp    $0x1,%edi
jg     1151 <main+0x21>
lea    0xf0a(%rip),%rdi
call   1030 <puts@plt>
lea    0xea8(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <getopt@plt>
cmp    $0xffffffff,%eax
je     122a <main+0xfa>
mov    %eax,%r15d
mov    0x2e63(%rip),%r13
lea    0xe89(%rip),%r14
lea    0xe7d(%rip),%r12
jmp    11c9 <main+0x99>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%rsi
lea    0xe64(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1050 <getopt@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     122a <main+0xfa>
mov    0x0(%r13),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x63,%r15d
je     1200 <main+0xd0>
cmp    $0x62,%r15d
je     1190 <main+0x60>
cmp    $0x61,%r15d
jne    1210 <main+0xe0>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
jmp    11b4 <main+0x84>
nopw   0x0(%rax,%rax,1)
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
jmp    11b4 <main+0x84>
xchg   %ax,%ax
mov    0x2dc9(%rip),%rax
movsbl (%rax),%esi
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b4 <main+0x84>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"no arguments\0A\00"
@.str.1 = [5 x i8] c"ab:c\00"
@.str.2 = [12 x i8] c"optind: %d\0A\00"
@optind = global i32 0
@.str.3 = [11 x i8] c"option: a\0A\00"
@.str.4 = [11 x i8] c"option: b\0A\00"
@.str.5 = [20 x i8] c"argument of -b: %s\0A\00"
@optarg = global i8* null
@.str.6 = [11 x i8] c"option: c\0A\00"
@.str.7 = [19 x i8] c"unknow option: %c\0A\00"
@optopt = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
br label %12
12: ; preds = %34, %11
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %35
17: ; preds = %12
%18 = load i32, i32* @optind
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %6
switch i32 %20, label %29 [
i32 97, label %21
i32 98, label %23
i32 99, label %27
]
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %34
23: ; preds = %17
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%25 = load i8*, i8** @optarg
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %25)
br label %34
27: ; preds = %17
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %34
29: ; preds = %17
%30 = load i64, i64* @optopt
%31 = trunc i64 %30 to i8
%32 = sext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %29, %27, %23, %21
br label %12
35: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"ab:c\00"
@.str.2 = [12 x i8] c"optind: %d\0A\00"
@optind = global i32 0
@.str.5 = [20 x i8] c"argument of -b: %s\0A\00"
@optarg = global i8* null
@.str.7 = [19 x i8] c"unknow option: %c\0A\00"
@optopt = global i64 0
@str = [10 x i8] c"option: c\00"
@str.8 = [10 x i8] c"option: b\00"
@str.9 = [10 x i8] c"option: a\00"
@str.10 = [13 x i8] c"no arguments\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.10, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, -1
br i1 %8, label %30, label %9
9: ; preds = %6, %27
%10 = phi i32 [ %28, %27 ], [ %7, %6 ]
%11 = load i32, i32* @optind
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %11)
switch i32 %10, label %21 [
i32 97, label %13
i32 98, label %15
i32 99, label %19
]
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.9, i64 0, i64 0))
br label %27
15: ; preds = %9
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0))
%17 = load i8*, i8** @optarg
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %17)
br label %27
19: ; preds = %9
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %27
21: ; preds = %9
%22 = load i64, i64* @optopt
%23 = trunc i64 %22 to i32
%24 = shl i32 %23, 24
%25 = ashr exact i32 %24, 24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %21, %19, %15, %13
%28 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %9
30: ; preds = %27, %6
ret i32 0
}