#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 */
char getopt(int, char **, char *);
int optind;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  char optch;
  static char optstring[] = "gW:c";
  while ((optch = getopt(argc, argv, optstring)) != -1) {
    switch (optch) {
    case 'c':
      printf("-c processed\n");
      break;
    case 'g':
      printf("-g processed\n");
      break;
    case 'W':
      printf("-W processed\n");
      break;
    default:
      printf("Unknown options!\n");
      break;
    }
  }
  for (; optind < argc; optind++) {
    printf("argv[ %d ] = '%s'\n", optind, argv[optind]);
  }
  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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0x2eec(%rip),%rdx
call   1040 <getopt@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     11db <main+0xbb>
movsbl -0x11(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x57,%eax
je     11b5 <main+0x95>
jmp    116d <main+0x4d>
mov    -0x18(%rbp),%eax
sub    $0x63,%eax
je     118f <main+0x6f>
jmp    117e <main+0x5e>
mov    -0x18(%rbp),%eax
sub    $0x67,%eax
je     11a2 <main+0x82>
jmp    11c8 <main+0xa8>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d6 <main+0xb6>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d6 <main+0xb6>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d6 <main+0xb6>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1136 <main+0x16>
jmp    11e0 <main+0xc0>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1235 <main+0x115>
mov    0x2def(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rax
mov    0x2de2(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2dba(%rip),%rax
mov    %ecx,(%rax)
jmp    11e0 <main+0xc0>
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
lea    0x2ef1(%rip),%rdx
call   1050 <getopt@plt>
cmp    $0xff,%al
je     11b9 <main+0x89>
lea    0xed6(%rip),%r15
lea    0x2eda(%rip),%r14
lea    0xebb(%rip),%r13
lea    0xece(%rip),%r12
jmp    1189 <main+0x59>
xchg   %ax,%ax
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <getopt@plt>
cmp    $0xff,%al
je     11b9 <main+0x89>
movsbl %al,%eax
cmp    $0x57,%eax
je     11b0 <main+0x80>
mov    %r15,%rdi
cmp    $0x63,%eax
je     1173 <main+0x43>
cmp    $0x67,%eax
jne    1170 <main+0x40>
mov    %r13,%rdi
jmp    1173 <main+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe5c(%rip),%rdi
jmp    1173 <main+0x43>
mov    0x2e28(%rip),%r15
mov    (%r15),%eax
cmp    %ebp,%eax
jge    11ee <main+0xbe>
lea    0xe32(%rip),%r14
xchg   %ax,%ax
movslq %eax,%rsi
mov    (%rbx,%rsi,8),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%eax
add    $0x1,%eax
mov    %eax,(%r15)
cmp    %ebp,%eax
jl     11d0 <main+0xa0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.optstring = internal global [5 x i8] c"gW:c\00"
@.str = [14 x i8] c"-c processed\0A\00"
@.str.1 = [14 x i8] c"-g processed\0A\00"
@.str.2 = [14 x i8] c"-W processed\0A\00"
@.str.3 = [18 x i8] c"Unknown options!\0A\00"
@optind = global i32 0
@.str.4 = [19 x i8] c"argv[ %d ] = '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %7
7: ; preds = %24, %2
%8 = load i32, i32* %4
%9 = load i8**, i8*** %5
%10 = call signext i8 @getopt(i32 %8, i8** %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.optstring, i64 0, i64 0))
store i8 %10, i8* %6
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %25
13: ; preds = %7
%14 = load i8, i8* %6
%15 = sext i8 %14 to i32
switch i32 %15, label %22 [
i32 99, label %16
i32 103, label %18
i32 87, label %20
]
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %24
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %24
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %24
22: ; preds = %13
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %20, %18, %16
br label %7
25: ; preds = %7
br label %26
26: ; preds = %38, %25
%27 = load i32, i32* @optind
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %41
30: ; preds = %26
%31 = load i32, i32* @optind
%32 = load i8**, i8*** %5
%33 = load i32, i32* @optind
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %31, i8* %36)
br label %38
38: ; preds = %30
%39 = load i32, i32* @optind
%40 = add nsw i32 %39, 1
store i32 %40, i32* @optind
br label %26
41: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
@main.optstring = internal global [5 x i8] c"gW:c\00"
@optind = global i32 0
@.str.4 = [19 x i8] c"argv[ %d ] = '%s'\0A\00"
@str = [13 x i8] c"-W processed\00"
@str.5 = [13 x i8] c"-g processed\00"
@str.6 = [13 x i8] c"-c processed\00"
@str.7 = [17 x i8] c"Unknown options!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.optstring, i64 0, i64 0))
%4 = icmp eq i8 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %14, %2
%6 = load i32, i32* @optind
%7 = icmp slt i32 %6, %0
br i1 %7, label %19, label %28
8: ; preds = %2, %14
%9 = phi i8 [ %17, %14 ], [ %3, %2 ]
%10 = sext i8 %9 to i32
switch i32 %10, label %13 [
i32 99, label %14
i32 103, label %11
i32 87, label %12
]
11: ; preds = %8
br label %14
12: ; preds = %8
br label %14
13: ; preds = %8
br label %14
14: ; preds = %8, %13, %12, %11
%15 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0), %13 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0), %12 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.5, i64 0, i64 0), %11 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0), %8 ]
%16 = tail call i32 @puts(i8* dereferenceable(1) %15)
%17 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.optstring, i64 0, i64 0))
%18 = icmp eq i8 %17, -1
br i1 %18, label %5, label %8
19: ; preds = %5, %19
%20 = phi i32 [ %26, %19 ], [ %6, %5 ]
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %20, i8* %23)
%25 = load i32, i32* @optind
%26 = add nsw i32 %25, 1
store i32 %26, i32* @optind
%27 = icmp slt i32 %26, %0
br i1 %27, label %19, label %28
28: ; preds = %19, %5
ret i32 0
}