#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 *);
int /*<<< orphan*/ optarg;
scalar_t__ optind;
int /*<<< orphan*/ printf(char *, int, ...);
int sscanf(int /*<<< orphan*/, char *, int *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int aflag = 0, boolv = 0, ch;
  while ((ch = getopt(argc, argv, "ab:h")) != -1) {
    switch (ch) {
    case 'a':
      aflag = 1;
      printf("got aflag=%d\n", aflag);
      break;
    case 'b':
      if (sscanf(optarg, "%d", &boolv) != 1)
        usage();
      printf("got boolv=%d\n", boolv);
      break;
    case 'h':
    case '?':
    default:
      usage();
    }
  }
  argc -= optind;
  argv += optind;
  printf("argc=%d\n", argc);
  for (int argi = 0; argi < argc; argi++)
    printf("argv[%d]=%s\n", argi, argv[argi]);
  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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1237 <main+0xf7>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x3f,%eax
je     1226 <main+0xe6>
jmp    1197 <main+0x57>
mov    -0x24(%rbp),%eax
sub    $0x61,%eax
je     11ca <main+0x8a>
jmp    11a8 <main+0x68>
mov    -0x24(%rbp),%eax
sub    $0x62,%eax
je     11e7 <main+0xa7>
jmp    11b9 <main+0x79>
mov    -0x24(%rbp),%eax
sub    $0x68,%eax
je     1226 <main+0xe6>
jmp    122b <main+0xeb>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1232 <main+0xf2>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     1210 <main+0xd0>
mov    $0x0,%al
call   1050 <usage@plt>
mov    -0x18(%rbp),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1232 <main+0xf2>
jmp    122b <main+0xeb>
mov    $0x0,%al
call   1050 <usage@plt>
jmp    1164 <main+0x24>
mov    0x2da2(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b0 <main+0x170>
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1279 <main+0x139>
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,%r14
mov    %edi,%ebx
movl   $0x0,0x4(%rsp)
lea    0xea1(%rip),%r15
lea    0xead(%rip),%r13
lea    0x4(%rsp),%rbp
lea    0xea4(%rip),%r12
jmp    118e <main+0x4e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x4(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <getopt@plt>
cmp    $0x61,%eax
je     11c0 <main+0x80>
cmp    $0x62,%eax
je     11d0 <main+0x90>
cmp    $0xffffffff,%eax
je     11f2 <main+0xb2>
xor    %eax,%eax
call   1050 <usage@plt>
jmp    118e <main+0x4e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe3e(%rip),%rdi
mov    $0x1,%esi
jmp    1187 <main+0x47>
xchg   %ax,%ax
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     1180 <main+0x40>
xor    %eax,%eax
call   1050 <usage@plt>
jmp    1180 <main+0x40>
mov    0x2de7(%rip),%rax
mov    (%rax),%rbp
sub    %ebp,%ebx
lea    0xe1f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebx,%ebx
jle    1249 <main+0x109>
lea    (%r14,%rbp,8),%r14
mov    %ebx,%ebx
lea    0xe0e(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbp,8),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1230 <main+0xf0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"ab:h\00"
@.str.1 = [14 x i8] c"got aflag=%d\0A\00"
@optarg = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [14 x i8] c"got boolv=%d\0A\00"
@optind = global i64 0
@.str.4 = [9 x i8] c"argc=%d\0A\00"
@.str.5 = [13 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 i32
%7 = alloca i32
%8 = alloca i32
%9 = 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
br label %10
10: ; preds = %32, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %8
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %33
15: ; preds = %10
%16 = load i32, i32* %8
switch i32 %16, label %30 [
i32 97, label %17
i32 98, label %20
i32 104, label %29
i32 63, label %29
]
17: ; preds = %15
store i32 1, i32* %6
%18 = load i32, i32* %6
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %32
20: ; preds = %15
%21 = load i32, i32* @optarg
%22 = call i32 @sscanf(i32 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 (...) @usage()
br label %26
26: ; preds = %24, %20
%27 = load i32, i32* %7
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %32
29: ; preds = %15, %15
br label %30
30: ; preds = %15, %29
%31 = call i32 (...) @usage()
br label %32
32: ; preds = %30, %26, %17
br label %10
33: ; preds = %10
%34 = load i64, i64* @optind
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = sub nsw i64 %36, %34
%38 = trunc i64 %37 to i32
store i32 %38, i32* %4
%39 = load i64, i64* @optind
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 %39
store i8** %41, i8*** %5
%42 = load i32, i32* %4
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %42)
store i32 0, i32* %9
br label %44
44: ; preds = %56, %33
%45 = load i32, i32* %9
%46 = load i32, i32* %4
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %59
48: ; preds = %44
%49 = load i32, i32* %9
%50 = load i8**, i8*** %5
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %49, i8* %54)
br label %56
56: ; preds = %48
%57 = load i32, i32* %9
%58 = add nsw i32 %57, 1
store i32 %58, i32* %9
br label %44
59: ; preds = %44
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"ab:h\00"
@.str.1 = [14 x i8] c"got aflag=%d\0A\00"
@optarg = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [14 x i8] c"got boolv=%d\0A\00"
@optind = global i64 0
@.str.4 = [9 x i8] c"argc=%d\0A\00"
@.str.5 = [13 x i8] c"argv[%d]=%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
br label %5
5: ; preds = %20, %2
%6 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %18 [
i32 -1, label %21
i32 97, label %7
i32 98, label %9
]
7: ; preds = %5
%8 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %20
9: ; preds = %5
%10 = load i32, i32* @optarg
%11 = call i32 @sscanf(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%12 = icmp eq i32 %11, 1
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 (...) @usage()
br label %15
15: ; preds = %13, %9
%16 = load i32, i32* %3
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %16)
br label %20
18: ; preds = %5
%19 = call i32 (...) @usage()
br label %20
20: ; preds = %18, %15, %7
br label %5
21: ; preds = %5
%22 = load i64, i64* @optind
%23 = trunc i64 %22 to i32
%24 = sub i32 %0, %23
%25 = getelementptr inbounds i8*, i8** %1, i64 %22
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%27 = icmp sgt i32 %24, 0
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = zext i32 %24 to i64
br label %31
30: ; preds = %31, %21
ret i32 0
31: ; preds = %28, %31
%32 = phi i64 [ 0, %28 ], [ %37, %31 ]
%33 = getelementptr inbounds i8*, i8** %25, i64 %32
%34 = load i8*, i8** %33
%35 = trunc i64 %32 to i32
%36 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %35, i8* %34)
%37 = add nuw nsw i64 %32, 1
%38 = icmp eq i64 %37, %29
br i1 %38, label %30, label %31
}