#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 const *);
scalar_t__ opterr;
scalar_t__ optind;
int /*<<< orphan*/ printf(char *);
int ls(int argc, char **argv) {
  const char *optString = "lah";
  opterr = 0;
  int opt;
  while ((opt = getopt(argc, argv, optString)) != -1) {
    switch (opt) {
    case 'l':
      printf("this -l option\n");
      break;
    case 'a':
      printf("this -a option\n");
      break;
    case 'h':
      printf("in this cmd, you have 3 option can use:\n");
      printf("-l\n");
      printf("-a\n");
      printf("-h\n");
      break;
    default:
      break;
    }
  }
  optind = 0;
  return 0;
}


x86 assembly (clang, -O0):
<ls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e97(%rip),%rax
movq   $0x0,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11fb <ls+0xdb>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x61,%eax
je     11ab <ls+0x8b>
jmp    1178 <ls+0x58>
mov    -0x20(%rbp),%eax
sub    $0x68,%eax
je     11bc <ls+0x9c>
jmp    1189 <ls+0x69>
mov    -0x20(%rbp),%eax
sub    $0x6c,%eax
jne    11f1 <ls+0xd1>
jmp    119a <ls+0x7a>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
jmp    11f6 <ls+0xd6>
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
jmp    11f6 <ls+0xd6>
lea    0xe61(%rip),%rdi
call   1030 <printf@plt>
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
jmp    11f6 <ls+0xd6>
jmp    11f6 <ls+0xd6>
jmp    1148 <ls+0x28>
mov    0x2de6(%rip),%rax
movq   $0x0,(%rax)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ea1(%rip),%rax
movq   $0x0,(%rax)
lea    0xebb(%rip),%r14
lea    0xef8(%rip),%r15
lea    0xedc(%rip),%r13
lea    0xed8(%rip),%r12
jmp    1188 <ls+0x68>
nopl   0x0(%rax)
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <getopt@plt>
cmp    $0x67,%eax
jle    11b0 <ls+0x90>
cmp    $0x68,%eax
je     1160 <ls+0x40>
mov    %r15,%rdi
cmp    $0x6c,%eax
je     1183 <ls+0x63>
jmp    1188 <ls+0x68>
nopl   0x0(%rax)
cmp    $0x61,%eax
jne    11c3 <ls+0xa3>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
jmp    1188 <ls+0x68>
cmp    $0xffffffff,%eax
jne    1188 <ls+0x68>
mov    0x2e19(%rip),%rax
movq   $0x0,(%rax)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"lah\00"
@opterr = global i64 0
@.str.1 = [16 x i8] c"this -l option\0A\00"
@.str.2 = [16 x i8] c"this -a option\0A\00"
@.str.3 = [41 x i8] c"in this cmd, you have 3 option can use:\0A\00"
@.str.4 = [4 x i8] c"-l\0A\00"
@.str.5 = [4 x i8] c"-a\0A\00"
@.str.6 = [4 x i8] c"-h\0A\00"
@optind = global i64 0
define i32 @ls(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %5
store i64 0, i64* @opterr
br label %7
7: ; preds = %25, %2
%8 = load i32, i32* %3
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %5
%11 = call i32 @getopt(i32 %8, i8** %9, i8* %10)
store i32 %11, i32* %6
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %26
13: ; preds = %7
%14 = load i32, i32* %6
switch i32 %14, label %24 [
i32 108, label %15
i32 97, label %17
i32 104, label %19
]
15: ; preds = %13
%16 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %25
17: ; preds = %13
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %25
19: ; preds = %13
%20 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %25
24: ; preds = %13
br label %25
25: ; preds = %24, %19, %17, %15
br label %7
26: ; preds = %7
store i64 0, i64* @optind
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"lah\00"
@opterr = global i64 0
@optind = global i64 0
@str = [40 x i8] c"in this cmd, you have 3 option can use:\00"
@str.7 = [3 x i8] c"-l\00"
@str.8 = [3 x i8] c"-a\00"
@str.9 = [3 x i8] c"-h\00"
@str.10 = [15 x i8] c"this -a option\00"
@str.11 = [15 x i8] c"this -l option\00"
define i32 @ls(i32 %0, i8** %1) {
store i64 0, i64* @opterr
br label %3
3: ; preds = %13, %2
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %4, label %13 [
i32 -1, label %14
i32 108, label %10
i32 97, label %5
i32 104, label %6
]
5: ; preds = %3
br label %10
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.7, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.8, i64 0, i64 0))
br label %10
10: ; preds = %3, %5, %6
%11 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.9, i64 0, i64 0), %6 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.10, i64 0, i64 0), %5 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0), %3 ]
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
br label %13
13: ; preds = %10, %3
br label %3
14: ; preds = %3
store i64 0, i64* @optind
ret i32 0
}