#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;
scalar_t__ opterr;
int optind;
int optopt;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int ch;
  opterr = 0;
  while ((ch = getopt(argc, argv, "a:b:cd")) != -1) {
    printf("optind:%d\n", optind);
    printf("optarg:%s\n", optarg);
    printf("ch:%c\n", ch);
    switch (ch) {
    case 'a':
      printf("option a:%s\n", optarg);
      break;
    case 'b':
      printf("option b:%s\n", optarg);
      break;
    case 'c':
      printf("option c\n");
      break;
    case 'd':
      printf("option d\n");
      break;
    case '?':
      printf("unknown option:%c\n", (char)optopt);
      break;
    default:
      printf("other option:%c\n", ch);
    }
    printf("optopt:%i\n", optopt);
  }
  printf("argc:%d, optind:%d, %s, %s, %s\n", argc, optind, argv[optind],
         argv[optind + 1], argv[optind + 2]);
  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)
mov    0x2e8b(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf46(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     127d <main+0x15d>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xf2c(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x21(%rbp)
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
mov    0x2e71(%rip),%rcx
mov    (%rcx),%rsi
lea    0xf19(%rip),%rdi
call   1030 <printf@plt>
mov    -0x21(%rbp),%al
mov    -0x14(%rbp),%esi
lea    0xf12(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x25,%eax
ja     1250 <main+0x130>
mov    -0x20(%rbp),%rax
lea    0xe38(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e20(%rip),%rax
mov    (%rax),%rsi
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1261 <main+0x141>
mov    0x2e03(%rip),%rax
mov    (%rax),%rsi
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1261 <main+0x141>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1261 <main+0x141>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1261 <main+0x141>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
movsbl %al,%esi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1261 <main+0x141>
mov    -0x14(%rbp),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1144 <main+0x24>
mov    -0x8(%rbp),%esi
mov    0x2d51(%rip),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rax
mov    0x2d44(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x10(%rbp),%rax
mov    0x2d32(%rip),%rdi
mov    (%rdi),%edi
add    $0x1,%edi
movslq %edi,%rdi
mov    (%rax,%rdi,8),%r8
mov    -0x10(%rbp),%rax
mov    0x2d1b(%rip),%rdi
mov    (%rdi),%edi
add    $0x2,%edi
movslq %edi,%rdi
mov    (%rax,%rdi,8),%r9
lea    0xe49(%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
mov    0x2e81(%rip),%rax
movq   $0x0,(%rax)
lea    0xf43(%rip),%rdx
call   1050 <getopt@plt>
cmp    $0xffffffff,%eax
je     1264 <main+0x134>
mov    %eax,%r15d
mov    0x2e8b(%rip),%r12
mov    0x2e6c(%rip),%r13
lea    0xe85(%rip),%r14
jmp    11bd <main+0x8d>
lea    0xf65(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
lea    0xf61(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
lea    0xeec(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     1264 <main+0x134>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    0xed2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%rsi
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x3f(%r15),%eax
cmp    $0x25,%eax
ja     117d <main+0x4d>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
movsbl 0x0(%r13),%esi
lea    0xebd(%rip),%rdi
jmp    1187 <main+0x57>
mov    (%r12),%rsi
lea    0xe93(%rip),%rdi
jmp    1236 <main+0x106>
mov    (%r12),%rsi
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    118e <main+0x5e>
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
jmp    118e <main+0x5e>
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
jmp    118e <main+0x5e>
mov    0x2d6d(%rip),%rax
movslq (%rax),%rdx
mov    (%rbx,%rdx,8),%rcx
mov    0x8(%rbx,%rdx,8),%r8
mov    0x10(%rbx,%rdx,8),%r9
lea    0xe82(%rip),%rdi
mov    %ebp,%esi
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):
@opterr = global i64 0
@.str = [7 x i8] c"a:b:cd\00"
@.str.1 = [11 x i8] c"optind:%d\0A\00"
@optind = global i32 0
@.str.2 = [11 x i8] c"optarg:%s\0A\00"
@optarg = global i8* null
@.str.3 = [7 x i8] c"ch:%c\0A\00"
@.str.4 = [13 x i8] c"option a:%s\0A\00"
@.str.5 = [13 x i8] c"option b:%s\0A\00"
@.str.6 = [10 x i8] c"option c\0A\00"
@.str.7 = [10 x i8] c"option d\0A\00"
@.str.8 = [19 x i8] c"unknown option:%c\0A\00"
@optopt = global i32 0
@.str.9 = [17 x i8] c"other option:%c\0A\00"
@.str.10 = [11 x i8] c"optopt:%i\0A\00"
@.str.11 = [32 x i8] c"argc:%d, optind:%d, %s, %s, %s\0A\00"
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
store i64 0, i64* @opterr
br label %7
7: ; preds = %38, %2
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call i32 @getopt(i32 %8, i8** %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %10, i32* %6
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %41
12: ; preds = %7
%13 = load i32, i32* @optind
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** @optarg
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %6
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %6
switch i32 %19, label %35 [
i32 97, label %20
i32 98, label %23
i32 99, label %26
i32 100, label %28
i32 63, label %30
]
20: ; preds = %12
%21 = load i8*, i8** @optarg
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %21)
br label %38
23: ; preds = %12
%24 = load i8*, i8** @optarg
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %24)
br label %38
26: ; preds = %12
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %38
28: ; preds = %12
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
br label %38
30: ; preds = %12
%31 = load i32, i32* @optopt
%32 = trunc i32 %31 to i8
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %33)
br label %38
35: ; preds = %12
%36 = load i32, i32* %6
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %35, %30, %28, %26, %23, %20
%39 = load i32, i32* @optopt
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %39)
br label %7
41: ; preds = %7
%42 = load i32, i32* %4
%43 = load i32, i32* @optind
%44 = load i8**, i8*** %5
%45 = load i32, i32* @optind
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %5
%50 = load i32, i32* @optind
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %49, i64 %52
%54 = load i8*, i8** %53
%55 = load i8**, i8*** %5
%56 = load i32, i32* @optind
%57 = add nsw i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %55, i64 %58
%60 = load i8*, i8** %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0), i32 %42, i32 %43, i8* %48, i8* %54, i8* %60)
ret i32 0
}

LLVM IR (-O2):
@opterr = global i64 0
@.str = [7 x i8] c"a:b:cd\00"
@.str.1 = [11 x i8] c"optind:%d\0A\00"
@optind = global i32 0
@.str.2 = [11 x i8] c"optarg:%s\0A\00"
@optarg = global i8* null
@.str.3 = [7 x i8] c"ch:%c\0A\00"
@.str.4 = [13 x i8] c"option a:%s\0A\00"
@.str.5 = [13 x i8] c"option b:%s\0A\00"
@.str.8 = [19 x i8] c"unknown option:%c\0A\00"
@optopt = global i32 0
@.str.9 = [17 x i8] c"other option:%c\0A\00"
@.str.10 = [11 x i8] c"optopt:%i\0A\00"
@.str.11 = [32 x i8] c"argc:%d, optind:%d, %s, %s, %s\0A\00"
@str = [9 x i8] c"option d\00"
@str.12 = [9 x i8] c"option c\00"
define i32 @main(i32 %0, i8** %1) {
store i64 0, i64* @opterr
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, -1
br i1 %4, label %34, label %5
5: ; preds = %2, %29
%6 = phi i32 [ %32, %29 ], [ %3, %2 ]
%7 = load i32, i32* @optind
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load i8*, i8** @optarg
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %6)
switch i32 %6, label %27 [
i32 97, label %12
i32 98, label %15
i32 99, label %18
i32 100, label %20
i32 63, label %22
]
12: ; preds = %5
%13 = load i8*, i8** @optarg
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %13)
br label %29
15: ; preds = %5
%16 = load i8*, i8** @optarg
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* %16)
br label %29
18: ; preds = %5
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.12, i64 0, i64 0))
br label %29
20: ; preds = %5
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %29
22: ; preds = %5
%23 = load i32, i32* @optopt
%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.8, i64 0, i64 0), i32 %25)
br label %29
27: ; preds = %5
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i32 %6)
br label %29
29: ; preds = %27, %22, %20, %18, %15, %12
%30 = load i32, i32* @optopt
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %30)
%32 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %5
34: ; preds = %29, %2
%35 = load i32, i32* @optind
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %1, i64 %36
%38 = load i8*, i8** %37
%39 = add nsw i32 %35, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %1, i64 %40
%42 = load i8*, i8** %41
%43 = add nsw i32 %35, 2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %1, i64 %44
%46 = load i8*, i8** %45
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.11, i64 0, i64 0), i32 %0, i32 %35, i8* %38, i8* %42, i8* %46)
ret i32 0
}