#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 */
int EXIT_FAILURE;
int PATH_MAX;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ dorealpath(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ help_print(int);
size_t optind;
int optopt;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ recursedir(char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  int opt;
  struct stat sb;
  char topdir[PATH_MAX];
  strcpy(topdir, getenv("HOME"));
  while ((opt = getopt(argc, argv, ":h")) != -1) {
    switch (opt) {
    case 'h':
      help_print(0);
      break;
    case ':':
      fprintf(stderr, "Option %c requires an argument\n", optopt);
      help_print(1);
      break;
    case '?':
      fprintf(stderr, "Illegal option: %c\n", optopt);
      help_print(1);
      break;
    }
  }
  if ((argv[optind])) {
    strcpy(topdir, argv[optind]);
    if (topdir[0] != '/')
      dorealpath(argv[optind], topdir);
  }
  if ((stat(topdir, &sb)) == -1) {
    perror(topdir);
    help_print(EXIT_FAILURE);
  }
  if (!(S_ISDIR(sb.st_mode))) {
    fprintf(stderr, "Not a directory: %s\n", topdir);
    help_print(EXIT_FAILURE);
  }
  recursedir(topdir);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe17(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdfd(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     12b9 <main+0x119>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3a,%eax
je     125b <main+0xbb>
jmp    122d <main+0x8d>
mov    -0x34(%rbp),%eax
sub    $0x3f,%eax
je     128a <main+0xea>
jmp    123e <main+0x9e>
mov    -0x34(%rbp),%eax
sub    $0x68,%eax
jne    12b4 <main+0x114>
jmp    124f <main+0xaf>
xor    %edi,%edi
call   10a0 <help_print@plt>
jmp    12b4 <main+0x114>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    0x2d75(%rip),%rax
mov    (%rax),%edx
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <help_print@plt>
jmp    12b4 <main+0x114>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%edx
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <help_print@plt>
jmp    11fa <main+0x5a>
mov    -0x10(%rbp),%rax
mov    0x2d14(%rip),%rcx
mov    (%rcx),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     131d <main+0x17d>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x2cf7(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1318 <main+0x178>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x2ccc(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <dorealpath@plt>
jmp    131d <main+0x17d>
mov    -0x30(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    134a <main+0x1aa>
mov    -0x30(%rbp),%rdi
call   10b0 <perror@plt>
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
call   10a0 <help_print@plt>
mov    -0x18(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1384 <main+0x1e4>
mov    -0x30(%rbp),%rdx
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xccd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
call   10a0 <help_print@plt>
mov    -0x30(%rbp),%rdi
call   1060 <recursedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
mov    %rsp,-0x40(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe25(%rip),%rdi
call   1030 <getenv@plt>
mov    %r14,-0x38(%rbp)
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
lea    0xe0f(%rip),%r12
lea    0xe0b(%rip),%r14
mov    0x2ddc(%rip),%r13
jmp    1235 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
lea    0xe11(%rip),%rsi
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <help_print@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   10c0 <getopt@plt>
cmp    $0x3e,%eax
jle    1260 <main+0xc0>
mov    $0x0,%edi
cmp    $0x68,%eax
je     1230 <main+0x90>
cmp    $0x3f,%eax
je     1210 <main+0x70>
jmp    1235 <main+0x95>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rsi
cmp    $0x3a,%eax
je     1217 <main+0x77>
cmp    $0xffffffff,%eax
jne    1235 <main+0x95>
mov    0x2d64(%rip),%r14
mov    (%r14),%rax
mov    (%r15,%rax,8),%rsi
test   %rsi,%rsi
mov    -0x38(%rbp),%rbx
je     12a0 <main+0x100>
mov    %rbx,%rdi
call   1040 <strcpy@plt>
cmpb   $0x2f,(%rbx)
je     12a0 <main+0x100>
mov    (%r14),%rax
mov    (%r15,%rax,8),%rdi
mov    %rbx,%rsi
call   1090 <dorealpath@plt>
lea    -0x30(%rbp),%rsi
mov    %rbx,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     1302 <main+0x162>
mov    -0x30(%rbp),%edi
call   1050 <S_ISDIR@plt>
test   %eax,%eax
jne    12e5 <main+0x145>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   10a0 <help_print@plt>
mov    %rbx,%rdi
call   1060 <recursedir@plt>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   10b0 <perror@plt>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
call   10a0 <help_print@plt>
jmp    12b1 <main+0x111>

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [5 x i8] c"HOME\00"
@.str.1 = [3 x i8] c":h\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Option %c requires an argument\0A\00"
@optopt = global i32 0
@.str.3 = [20 x i8] c"Illegal option: %c\0A\00"
@optind = global i64 0
@EXIT_FAILURE = global i32 0
@.str.4 = [21 x i8] c"Not a directory: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %8
%13 = alloca i8, i64 %11
store i64 %11, i64* %9
%14 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @strcpy(i8* %13, i8* %14)
br label %16
16: ; preds = %35, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 %19, i32* %6
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %36
21: ; preds = %16
%22 = load i32, i32* %6
switch i32 %22, label %35 [
i32 104, label %23
i32 58, label %25
i32 63, label %30
]
23: ; preds = %21
%24 = call i32 @help_print(i32 0)
br label %35
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i32, i32* @optopt
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = call i32 @help_print(i32 1)
br label %35
30: ; preds = %21
%31 = load i32, i32* @stderr
%32 = load i32, i32* @optopt
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = call i32 @help_print(i32 1)
br label %35
35: ; preds = %21, %30, %25, %23
br label %16
36: ; preds = %16
%37 = load i8**, i8*** %5
%38 = load i64, i64* @optind
%39 = getelementptr inbounds i8*, i8** %37, i64 %38
%40 = load i8*, i8** %39
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %59
42: ; preds = %36
%43 = load i8**, i8*** %5
%44 = load i64, i64* @optind
%45 = getelementptr inbounds i8*, i8** %43, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 @strcpy(i8* %13, i8* %46)
%48 = getelementptr inbounds i8, i8* %13, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 47
br i1 %51, label %52, label %58
52: ; preds = %42
%53 = load i8**, i8*** %5
%54 = load i64, i64* @optind
%55 = getelementptr inbounds i8*, i8** %53, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 @dorealpath(i8* %56, i8* %13)
br label %58
58: ; preds = %52, %42
br label %59
59: ; preds = %58, %36
%60 = call i32 @stat(i8* %13, %struct.stat* %7)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %66
62: ; preds = %59
%63 = call i32 @perror(i8* %13)
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @help_print(i32 %64)
br label %66
66: ; preds = %62, %59
%67 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%68 = load i32, i32* %67
%69 = call i32 @S_ISDIR(i32 %68)
%70 = icmp ne i32 %69, 0
br i1 %70, label %76, label %71
71: ; preds = %66
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @help_print(i32 %74)
br label %76
76: ; preds = %71, %66
%77 = call i32 @recursedir(i8* %13)
store i32 0, i32* %3
%78 = load i8*, i8** %8
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [5 x i8] c"HOME\00"
@.str.1 = [3 x i8] c":h\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Option %c requires an argument\0A\00"
@optopt = global i32 0
@.str.3 = [20 x i8] c"Illegal option: %c\0A\00"
@optind = global i64 0
@EXIT_FAILURE = global i32 0
@.str.4 = [21 x i8] c"Not a directory: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @strcpy(i8* %8, i8* %9)
br label %11
11: ; preds = %22, %2
%12 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
switch i32 %12, label %22 [
i32 -1, label %23
i32 104, label %19
i32 58, label %14
i32 63, label %13
]
13: ; preds = %11
br label %14
14: ; preds = %11, %13
%15 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), %13 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), %11 ]
%16 = load i32, i32* @stderr
%17 = load i32, i32* @optopt
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* %15, i32 %17)
br label %19
19: ; preds = %14, %11
%20 = phi i32 [ 0, %11 ], [ 1, %14 ]
%21 = call i32 @help_print(i32 %20)
br label %22
22: ; preds = %19, %11
br label %11
23: ; preds = %11
%24 = load i64, i64* @optind
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
br i1 %27, label %37, label %28
28: ; preds = %23
%29 = call i32 @strcpy(i8* %8, i8* %26)
%30 = load i8, i8* %8
%31 = icmp eq i8 %30, 47
br i1 %31, label %37, label %32
32: ; preds = %28
%33 = load i64, i64* @optind
%34 = getelementptr inbounds i8*, i8** %1, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @dorealpath(i8* %35, i8* %8)
br label %37
37: ; preds = %28, %32, %23
%38 = call i32 @stat(i8* %8, %struct.stat* %3)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = call i32 @perror(i8* %8)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @help_print(i32 %42)
br label %44
44: ; preds = %40, %37
%45 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @S_ISDIR(i32 %46)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i32, i32* @stderr
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @help_print(i32 %52)
br label %54
54: ; preds = %49, %44
%55 = call i32 @recursedir(i8* %8)
ret i32 0
}