#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int getopt(int, char **, char const *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int ret;
  int i;
  uint8_t buf[0x1000];
  extern char *optarg;
  extern int optind, opterr, optopt;
  const char *optstring = "abc:d:e::fg:";
  for (i = 0; i < argc; ++i) {
    printf("%2d: %s\n", i, argv[i]);
  }
  printf("optstring: %s\n", optstring);
  while (1) {
    ret = getopt(argc, argv, optstring);
    if (ret == -1) {
      break;
    }
    printf("ret = %c\n", (char)ret);
    printf("optarg = %s\n", optarg);
    printf("optind = %d\n", optind);
    printf("opterr = %d\n", opterr);
    printf("optopt = %d\n", optopt);
    printf("====================\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec0(%rip),%rax
mov    %rax,-0x4028(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1185 <main+0x65>
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114e <main+0x2e>
mov    -0x4028(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x4028(%rbp),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11bf <main+0x9f>
jmp    1243 <main+0x123>
mov    -0x14(%rbp),%eax
movsbl %al,%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119a <main+0x7a>
xor    %eax,%eax
add    $0x4030,%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,%r15
mov    %edi,%r13d
test   %edi,%edi
jle    1179 <main+0x49>
mov    %r13d,%ebx
lea    0xebe(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbp,8),%rdx
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <main+0x30>
lea    0xe96(%rip),%rdi
lea    0xe79(%rip),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1050 <getopt@plt>
cmp    $0xffffffff,%eax
je     124f <main+0x11f>
mov    0x2e31(%rip),%rbp
lea    0xea0(%rip),%r14
lea    0xea6(%rip),%rbx
lea    0xe3c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%esi
lea    0xe4b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%rsi
lea    0xe3d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <getopt@plt>
cmp    $0xffffffff,%eax
jne    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):
@.str = [13 x i8] c"abc:d:e::fg:\00"
@.str.1 = [9 x i8] c"%2d: %s\0A\00"
@.str.2 = [15 x i8] c"optstring: %s\0A\00"
@.str.3 = [10 x i8] c"ret = %c\0A\00"
@.str.4 = [13 x i8] c"optarg = %s\0A\00"
@optarg = external global i8*
@.str.5 = [13 x i8] c"optind = %d\0A\00"
@optind = external global i32
@.str.6 = [13 x i8] c"opterr = %d\0A\00"
@opterr = external global i32
@.str.7 = [13 x i8] c"optopt = %d\0A\00"
@optopt = external global i32
@.str.8 = [22 x i8] 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 [4096 x i32]
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %9
store i32 0, i32* %7
br label %10
10: ; preds = %22, %2
%11 = load i32, i32* %7
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* %7
%16 = load i8**, i8*** %5
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %20)
br label %22
22: ; preds = %14
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %10
25: ; preds = %10
%26 = load i8*, i8** %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %36
%29 = load i32, i32* %4
%30 = load i8**, i8*** %5
%31 = load i8*, i8** %9
%32 = call i32 @getopt(i32 %29, i8** %30, i8* %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %28
br label %50
36: ; preds = %28
%37 = load i32, i32* %6
%38 = trunc i32 %37 to i8
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = load i8*, i8** @optarg
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = load i32, i32* @optind
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %43)
%45 = load i32, i32* @opterr
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%47 = load i32, i32* @optopt
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
br label %28
50: ; preds = %35
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"abc:d:e::fg:\00"
@.str.1 = [9 x i8] c"%2d: %s\0A\00"
@.str.2 = [15 x i8] c"optstring: %s\0A\00"
@.str.3 = [10 x i8] c"ret = %c\0A\00"
@.str.4 = [13 x i8] c"optarg = %s\0A\00"
@optarg = external global i8*
@.str.5 = [13 x i8] c"optind = %d\0A\00"
@optind = external global i32
@.str.6 = [13 x i8] c"opterr = %d\0A\00"
@opterr = external global i32
@.str.7 = [13 x i8] c"optopt = %d\0A\00"
@optopt = external global i32
@str = [21 x i8] c"====================\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %14
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %12, %6 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = trunc i64 %7 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %10, i8* %9)
%12 = add nuw nsw i64 %7, 1
%13 = icmp eq i64 %12, %5
br i1 %13, label %14, label %6
14: ; preds = %6, %2
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32 %16, -1
br i1 %17, label %34, label %18
18: ; preds = %14, %18
%19 = phi i32 [ %32, %18 ], [ %16, %14 ]
%20 = shl i32 %19, 24
%21 = ashr exact i32 %20, 24
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** @optarg
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @optind
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @opterr
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @optopt
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %29)
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%32 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %18
34: ; preds = %18, %14
ret i32 0
}