#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 EOF;
char getopt(int, char **, char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  char optstring[] = "abcd";
  char ch;
  while ((ch = getopt(argc, argv, optstring)) != EOF) {
    switch (ch) {
    case 'a':
      printf("option a caught\n");
      break;
    case 'b':
      printf("option b caugth\n");
      break;
    case 'c':
      printf("option c caught\n");
      break;
    case 'd':
      printf("option d caught\n");
      break;
    default:
      printf("Unkown options\n");
      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)
mov    0xed4(%rip),%eax
mov    %eax,-0x15(%rbp)
mov    0xecf(%rip),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x15(%rbp),%rdx
call   1040 <getopt@plt>
mov    %al,-0x16(%rbp)
movsbl %al,%eax
mov    0x2e83(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11ef <main+0xcf>
movsbl -0x16(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     11de <main+0xbe>
mov    -0x20(%rbp),%rax
lea    0xe6f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
jmp    11ea <main+0xca>
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
jmp    11ea <main+0xca>
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
jmp    11ea <main+0xca>
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
jmp    11ea <main+0xca>
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
jmp    1148 <main+0x28>
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
movb   $0x0,0x4(%rsp)
movl   $0x64636261,(%rsp)
mov    %rsp,%rdx
call   1040 <getopt@plt>
mov    0x2e9d(%rip),%r15
cmp    (%r15),%al
jne    1161 <main+0x41>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xedd(%rip),%r12
lea    0xee5(%rip),%r13
mov    %rsp,%r14
jmp    1197 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <getopt@plt>
cmp    (%r15),%al
je     1150 <main+0x30>
movsbl %al,%eax
add    $0xffffff9f,%eax
mov    %r12,%rdi
cmp    $0x3,%eax
ja     1180 <main+0x60>
cltq
movslq 0x0(%r13,%rax,4),%rdi
add    %r13,%rdi
jmp    1180 <main+0x60>

LLVM IR (-O0):
@__const.main.optstring = [5 x i8] c"abcd\00"
@EOF = global i8 0
@.str = [17 x i8] c"option a caught\0A\00"
@.str.1 = [17 x i8] c"option b caugth\0A\00"
@.str.2 = [17 x i8] c"option c caught\0A\00"
@.str.3 = [17 x i8] c"option d caught\0A\00"
@.str.4 = [16 x i8] c"Unkown options\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [5 x i8]
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [5 x i8]* %6 to i8*
br label %9
9: ; preds = %31, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%13 = call signext i8 @getopt(i32 %10, i8** %11, i8* %12)
store i8 %13, i8* %7
%14 = sext i8 %13 to i32
%15 = load i8, i8* @EOF
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %14, %16
br i1 %17, label %18, label %32
18: ; preds = %9
%19 = load i8, i8* %7
%20 = sext i8 %19 to i32
switch i32 %20, label %29 [
i32 97, label %21
i32 98, label %23
i32 99, label %25
i32 100, label %27
]
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %31
23: ; preds = %18
%24 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %31
25: ; preds = %18
%26 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %31
27: ; preds = %18
%28 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %31
29: ; preds = %18
%30 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %27, %25, %23, %21
br label %9
32: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@__const.main.optstring = [5 x i8] c"abcd\00"
@EOF = global i8 0
@str = [16 x i8] c"option d caught\00"
@str.5 = [16 x i8] c"option c caught\00"
@str.6 = [16 x i8] c"option b caugth\00"
@str.7 = [16 x i8] c"option a caught\00"
@str.8 = [15 x i8] c"Unkown options\00"
@reltable.main = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @str.7 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @str.6 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @str.5 to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @str to i64), i64 ptrtoint ([4 x i32]* @reltable.main to i64)) to i32)]
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%5 = call signext i8 @getopt(i32 %0, i8** %1, i8* %4)
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %23, label %8
8: ; preds = %2, %17
%9 = phi i8 [ %20, %17 ], [ %5, %2 ]
%10 = sext i8 %9 to i32
%11 = add nsw i32 %10, -97
%12 = icmp ult i32 %11, 4
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = sext i32 %11 to i64
%15 = shl i64 %14, 2
%16 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.main to i8*), i64 %15)
br label %17
17: ; preds = %8, %13
%18 = phi i8* [ %16, %13 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0), %8 ]
%19 = call i32 @puts(i8* dereferenceable(1) %18)
%20 = call signext i8 @getopt(i32 %0, i8** %1, i8* %4)
%21 = load i8, i8* @EOF
%22 = icmp eq i8 %20, %21
br i1 %22, label %23, label %8
23: ; preds = %17, %2
ret i32 0
}