#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 aflag = 0;
  int bflag = 0;
  int cflag = 0;
  int ch = 0;
  while ((ch = getopt(argc, argv, "ab:c")) != -1) {
    printf("optind: %d\n", optind);
    switch (ch) {
    case 'a':
      printf("HAVE option: -a\n");
      aflag = 1;
      break;
    case 'b':
      printf("HAVE option: -b\n");
      bflag = 1;
      printf("The argument of -b is %s\n", optarg);
      break;
    case 'c':
      printf("HAVE option: -c\n");
      cflag = 1;
      break;
    case '?':
      printf("Unknown option: %c\n", (char)optopt);
      break;
    }
  }
  printf("optopt: %c\n", (char)optopt);
  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)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf34(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     1237 <main+0x117>
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xf18(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x24,%eax
ja     1232 <main+0x112>
mov    -0x28(%rbp),%rax
lea    0xe58(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeed(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1232 <main+0x112>
lea    0xee4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x18(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%rsi
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1232 <main+0x112>
lea    0xedd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1232 <main+0x112>
mov    0x2dc2(%rip),%rax
mov    (%rax),%rax
movsbl %al,%esi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1152 <main+0x32>
mov    0x2da2(%rip),%rax
mov    (%rax),%rax
movsbl %al,%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
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    0xf4d(%rip),%rdx
call   1050 <getopt@plt>
cmp    $0xffffffff,%eax
je     1221 <main+0xf1>
mov    %eax,%r13d
lea    0xf3a(%rip),%r14
lea    0xf2e(%rip),%r15
lea    0xe93(%rip),%r12
jmp    11a5 <main+0x75>
nop
mov    0x2e69(%rip),%rax
movsbl (%rax),%esi
lea    0xf3e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <getopt@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     1221 <main+0xf1>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffc1,%r13d
cmp    $0x24,%r13d
ja     1190 <main+0x60>
movslq (%r12,%r13,4),%rax
add    %r12,%rax
jmp    *%rax
lea    0xf2d(%rip),%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x60>
nopl   0x0(%rax)
lea    0xf08(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%rsi
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1190 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x60>
mov    0x2db8(%rip),%rax
movsbl (%rax),%esi
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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