#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
char *optarg;
scalar_t__ opterr;
int optind;
char optopt;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int a = 0, b = 0;
  char *cstr = NULL;
  int arg;
  opterr = 0;
  while ((arg = getopt(argc, argv, "abc:")) != -1) {
    switch (arg) {
    case 'a':
      a = 1;
      break;
    case 'b':
      b = 1;
      break;
    case 'c':
      cstr = optarg;
      break;
    case '?':
      if (optopt == 'c') {
        fprintf(stderr, "-c requires an argument.\n");
      } else {
        fprintf(stderr, "Unknown flag '%c'.\n", optopt);
      }
    default:
      exit(EXIT_FAILURE);
    }
  }
  fprintf(stdout, "a = %d\nb = %d\ncstr = %s\n", a, b, cstr);
  for (int i = optind; i < argc; i++) {
    printf("Additional argument %s\n", argv[i]);
  }
  exit(EXIT_SUCCESS);
  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)
movq   $0x0,-0x20(%rbp)
mov    0x2e45(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf0c(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1255 <main+0x115>
mov    -0x24(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x24,%eax
ja     1242 <main+0x102>
mov    -0x30(%rbp),%rax
lea    0xe47(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x14(%rbp)
jmp    1250 <main+0x110>
movl   $0x1,-0x18(%rbp)
jmp    1250 <main+0x110>
mov    0x2e17(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1250 <main+0x110>
mov    0x2dec(%rip),%rax
movsbl (%rax),%eax
cmp    $0x63,%eax
jne    121c <main+0xdc>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    123d <main+0xfd>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    0x2db4(%rip),%rax
movsbl (%rax),%edx
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1242 <main+0x102>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    117a <main+0x3a>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b4 <main+0x174>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1282 <main+0x142>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e61(%rip),%rax
movq   $0x0,(%rax)
xor    %r15d,%r15d
lea    0xe98(%rip),%r13
xor    %r12d,%r12d
xor    %ebp,%ebp
nopl   (%rax)
mov    %ebp,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   1050 <getopt@plt>
mov    $0x1,%ecx
cmp    $0x61,%eax
je     1180 <main+0x40>
cmp    $0x62,%eax
jg     11b0 <main+0x70>
jne    11c5 <main+0x85>
mov    $0x1,%r15d
jmp    1170 <main+0x30>
nopl   0x0(%rax,%rax,1)
cmp    $0x63,%eax
jne    1272 <main+0x132>
mov    0x2e38(%rip),%rax
mov    (%rax),%r12
jmp    1170 <main+0x30>
cmp    $0xffffffff,%eax
je     11fb <main+0xbb>
cmp    $0x3f,%eax
jne    1272 <main+0x132>
mov    0x2e06(%rip),%rax
movsbl (%rax),%edx
mov    0x2de4(%rip),%rax
cmp    $0x63,%edx
jne    1262 <main+0x122>
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1272 <main+0x132>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r12,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2db7(%rip),%rax
movslq (%rax),%rax
cmp    %ebx,%eax
jge    1254 <main+0x114>
lea    (%r14,%rax,8),%r15
sub    %eax,%ebx
xor    %ebp,%ebp
lea    0xe15(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbp,8),%rsi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %ebp,%ebx
jne    1240 <main+0x100>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@opterr = global i64 0
@.str = [5 x i8] c"abc:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"-c requires an argument.\0A\00"
@.str.2 = [20 x i8] c"Unknown flag '%c'.\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.3 = [25 x i8] c"a = %d\0Ab = %d\0Acstr = %s\0A\00"
@optind = global i32 0
@.str.4 = [24 x i8] c"Additional argument %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = 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 i8* null, i8** %8
store i64 0, i64* @opterr
br label %11
11: ; preds = %38, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %9
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %39
16: ; preds = %11
%17 = load i32, i32* %9
switch i32 %17, label %35 [
i32 97, label %18
i32 98, label %19
i32 99, label %20
i32 63, label %22
]
18: ; preds = %16
store i32 1, i32* %6
br label %38
19: ; preds = %16
store i32 1, i32* %7
br label %38
20: ; preds = %16
%21 = load i8*, i8** @optarg
store i8* %21, i8** %8
br label %38
22: ; preds = %16
%23 = load i8, i8* @optopt
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 99
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %34
29: ; preds = %22
%30 = load i32, i32* @stderr
%31 = load i8, i8* @optopt
%32 = sext i8 %31 to i32
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %29, %26
br label %35
35: ; preds = %16, %34
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %20, %19, %18
br label %11
39: ; preds = %11
%40 = load i32, i32* @stdout
%41 = load i32, i32* %6
%42 = load i32, i32* %7
%43 = load i8*, i8** %8
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %41, i32 %42, i8* %43)
%45 = load i32, i32* @optind
store i32 %45, i32* %10
br label %46
46: ; preds = %57, %39
%47 = load i32, i32* %10
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %60
50: ; preds = %46
%51 = load i8**, i8*** %5
%52 = load i32, i32* %10
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %50
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
store i32 %59, i32* %10
br label %46
60: ; preds = %46
%61 = load i32, i32* @EXIT_SUCCESS
%62 = call i32 @exit(i32 %61)
unreachable
}

LLVM IR (-O2):
@opterr = global i64 0
@.str = [5 x i8] c"abc:\00"
@optarg = global i8* null
@optopt = global i8 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"-c requires an argument.\0A\00"
@.str.2 = [20 x i8] c"Unknown flag '%c'.\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.3 = [25 x i8] c"a = %d\0Ab = %d\0Acstr = %s\0A\00"
@optind = global i32 0
@.str.4 = [24 x i8] c"Additional argument %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
store i64 0, i64* @opterr
br label %3
3: ; preds = %10, %2
%4 = phi i32 [ 0, %2 ], [ 1, %10 ]
%5 = phi i8* [ null, %2 ], [ %8, %10 ]
%6 = phi i32 [ 0, %2 ], [ %11, %10 ]
br label %7
7: ; preds = %3, %13
%8 = phi i8* [ %5, %3 ], [ %14, %13 ]
%9 = phi i32 [ %6, %3 ], [ %11, %13 ]
br label %10
10: ; preds = %7, %10
%11 = phi i32 [ 1, %10 ], [ %9, %7 ]
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %12, label %25 [
i32 -1, label %28
i32 97, label %10
i32 98, label %3
i32 99, label %13
i32 63, label %15
]
13: ; preds = %10
%14 = load i8*, i8** @optarg
br label %7
15: ; preds = %10
%16 = load i8, i8* @optopt
%17 = icmp eq i8 %16, 99
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %25
21: ; preds = %15
%22 = sext i8 %16 to i32
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %25
25: ; preds = %10, %18, %21
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %10
%29 = load i32, i32* @stdout
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %4, i8* %8)
%31 = load i32, i32* @optind
%32 = icmp slt i32 %31, %0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = sext i32 %31 to i64
br label %38
35: ; preds = %38, %28
%36 = load i32, i32* @EXIT_SUCCESS
%37 = tail call i32 @exit(i32 %36)
unreachable
38: ; preds = %33, %38
%39 = phi i64 [ %34, %33 ], [ %43, %38 ]
%40 = getelementptr inbounds i8*, i8** %1, i64 %39
%41 = load i8*, i8** %40
%42 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = add nsw i64 %39, 1
%44 = trunc i64 %43 to i32
%45 = icmp eq i32 %44, %0
br i1 %45, label %35, label %38
}