#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ analysis_file(char *);
int /*<<< orphan*/ loop_dir(char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ strcmp(char *, char *);
size_t strlen(char *);
int /*<<< orphan*/ usage_and_quit();
void process_cmdline(int argc, char **argv) {
  if (argc == 1)
    usage_and_quit();
  argv++;
  if (!strcmp(*argv, "-h") || !strcmp(*argv, "--help"))
    usage_and_quit();
  struct stat info;
  while (*argv) {
    if (stat(*argv, &info)) {
      perror(*argv);
      argv++;
      continue;
    }
    if (S_ISREG(info.st_mode))
      analysis_file(*argv);
    else if (S_ISDIR(info.st_mode)) {
      size_t len = strlen(*argv);
      if (*(*argv + len - 1) == '/' && len > 1)
        *(*argv + len - 1) = '\0';
      loop_dir(*argv);
    }
    argv++;
  }
}


x86 assembly (clang, -O0):
<process_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jne    11b0 <process_cmdline+0x20>
mov    $0x0,%al
call   10a0 <usage_and_quit@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe36(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11f4 <process_cmdline+0x64>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe1d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11fb <process_cmdline+0x6b>
mov    $0x0,%al
call   10a0 <usage_and_quit@plt>
jmp    1200 <process_cmdline+0x70>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12e0 <process_cmdline+0x150>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
je     1245 <process_cmdline+0xb5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10b0 <perror@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1200 <process_cmdline+0x70>
mov    -0x18(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     1268 <process_cmdline+0xd8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <analysis_file@plt>
jmp    12cf <process_cmdline+0x13f>
mov    -0x18(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12ca <process_cmdline+0x13a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    12be <process_cmdline+0x12e>
cmpq   $0x1,-0x20(%rbp)
jbe    12be <process_cmdline+0x12e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,-0x1(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <loop_dir@plt>
jmp    12cf <process_cmdline+0x13f>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    1200 <process_cmdline+0x70>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_cmdline>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
cmp    $0x1,%edi
jne    11a8 <process_cmdline+0x18>
xor    %eax,%eax
call   10a0 <usage_and_quit@plt>
mov    0x8(%r15),%rbx
add    $0x8,%r15
lea    0xe49(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11d6 <process_cmdline+0x46>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11e0 <process_cmdline+0x50>
xor    %eax,%eax
call   10a0 <usage_and_quit@plt>
mov    (%r15),%rbx
test   %rbx,%rbx
je     1265 <process_cmdline+0xd5>
lea    0x8(%rsp),%r14
jmp    1205 <process_cmdline+0x75>
mov    (%r15),%rdi
call   1060 <analysis_file@plt>
mov    0x8(%r15),%rbx
add    $0x8,%r15
test   %rbx,%rbx
je     1265 <process_cmdline+0xd5>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <stat@plt>
test   %rax,%rax
jne    125b <process_cmdline+0xcb>
mov    0x8(%rsp),%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
jne    11f0 <process_cmdline+0x60>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     11f8 <process_cmdline+0x68>
mov    (%r15),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmpb   $0x2f,-0x1(%rbx,%rax,1)
jne    1251 <process_cmdline+0xc1>
cmp    $0x2,%rax
jb     1251 <process_cmdline+0xc1>
movb   $0x0,-0x1(%rbx,%rax,1)
mov    (%r15),%rbx
mov    %rbx,%rdi
call   1070 <loop_dir@plt>
jmp    11f8 <process_cmdline+0x68>
mov    (%r15),%rdi
call   10b0 <perror@plt>
jmp    11f8 <process_cmdline+0x68>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
define void @process_cmdline(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.stat
%6 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (...) @usage_and_quit()
br label %11
11: ; preds = %9, %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i32 1
store i8** %13, i8*** %4
%14 = load i8**, i8*** %4
%15 = load i8*, i8** %14
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %11
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %18, %11
%24 = call i32 (...) @usage_and_quit()
br label %25
25: ; preds = %23, %18
br label %26
26: ; preds = %81, %35, %25
%27 = load i8**, i8*** %4
%28 = load i8*, i8** %27
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %84
30: ; preds = %26
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = call i64 @stat(i8* %32, %struct.stat* %5)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i8**, i8*** %4
%37 = load i8*, i8** %36
%38 = call i32 @perror(i8* %37)
%39 = load i8**, i8*** %4
%40 = getelementptr inbounds i8*, i8** %39, i32 1
store i8** %40, i8*** %4
br label %26
41: ; preds = %30
%42 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i64 @S_ISREG(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %41
%47 = load i8**, i8*** %4
%48 = load i8*, i8** %47
%49 = call i32 @analysis_file(i8* %48)
br label %81
50: ; preds = %41
%51 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i64 @S_ISDIR(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %80
55: ; preds = %50
%56 = load i8**, i8*** %4
%57 = load i8*, i8** %56
%58 = call i64 @strlen(i8* %57)
store i64 %58, i64* %6
%59 = load i8**, i8*** %4
%60 = load i8*, i8** %59
%61 = load i64, i64* %6
%62 = getelementptr inbounds i8, i8* %60, i64 %61
%63 = getelementptr inbounds i8, i8* %62, i64 -1
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 47
br i1 %66, label %67, label %76
67: ; preds = %55
%68 = load i64, i64* %6
%69 = icmp ugt i64 %68, 1
br i1 %69, label %70, label %76
70: ; preds = %67
%71 = load i8**, i8*** %4
%72 = load i8*, i8** %71
%73 = load i64, i64* %6
%74 = getelementptr inbounds i8, i8* %72, i64 %73
%75 = getelementptr inbounds i8, i8* %74, i64 -1
store i8 0, i8* %75
br label %76
76: ; preds = %70, %67, %55
%77 = load i8**, i8*** %4
%78 = load i8*, i8** %77
%79 = call i32 @loop_dir(i8* %78)
br label %80
80: ; preds = %76, %50
br label %81
81: ; preds = %80, %46
%82 = load i8**, i8*** %4
%83 = getelementptr inbounds i8*, i8** %82, i32 1
store i8** %83, i8*** %4
br label %26
84: ; preds = %26
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
define void @process_cmdline(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (...) @usage_and_quit()
br label %7
7: ; preds = %5, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12, %7
%16 = tail call i32 (...) @usage_and_quit()
%17 = load i8*, i8** %8
br label %18
18: ; preds = %15, %12
%19 = phi i8* [ %17, %15 ], [ %9, %12 ]
%20 = bitcast %struct.stat* %3 to i8*
%21 = icmp eq i8* %19, null
br i1 %21, label %61, label %22
22: ; preds = %18
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %24
24: ; preds = %22, %32
%25 = phi i8* [ %19, %22 ], [ %34, %32 ]
%26 = phi i8** [ %8, %22 ], [ %33, %32 ]
%27 = call i64 @stat(i8* %25, %struct.stat* %3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %24
%30 = load i8*, i8** %26
%31 = call i32 @perror(i8* %30)
br label %32
32: ; preds = %40, %58, %43, %29
%33 = getelementptr inbounds i8*, i8** %26, i64 1
%34 = load i8*, i8** %33
%35 = icmp eq i8* %34, null
br i1 %35, label %61, label %24
36: ; preds = %24
%37 = load i32, i32* %23
%38 = call i64 @S_ISREG(i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = load i8*, i8** %26
%42 = call i32 @analysis_file(i8* %41)
br label %32
43: ; preds = %36
%44 = load i32, i32* %23
%45 = call i64 @S_ISDIR(i32 %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %32, label %47
47: ; preds = %43
%48 = load i8*, i8** %26
%49 = call i64 @strlen(i8* dereferenceable(1) %48)
%50 = getelementptr inbounds i8, i8* %48, i64 -1
%51 = getelementptr inbounds i8, i8* %50, i64 %49
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 47
%54 = icmp ugt i64 %49, 1
%55 = select i1 %53, i1 %54, i1 false
br i1 %55, label %56, label %58
56: ; preds = %47
store i8 0, i8* %51
%57 = load i8*, i8** %26
br label %58
58: ; preds = %56, %47
%59 = phi i8* [ %57, %56 ], [ %48, %47 ]
%60 = call i32 @loop_dir(i8* %59)
br label %32
61: ; preds = %32, %18
ret void
}