#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;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ fnmatch(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewinddir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stdout;
int maketree(char *path, char *patn) {
  struct dirent *direntp = NULL;
  DIR *dirp;
  int s;
  int flg = 0;
  struct stat dstat;
  char spath[4096];
  fprintf(stdout, "%s\n", path);
  dirp = opendir(path);
  if (dirp == NULL)
    return 0;
  while ((direntp = readdir(dirp)) != NULL) {
    if (direntp->d_name[0] == '.')
      continue;
    flg = (fnmatch(patn, direntp->d_name, 0) == 0);
    if (flg == 1)
      break;
  }
  if (flg == 1) {
    closedir(dirp);
    return 0;
  }
  rewinddir(dirp);
  while ((direntp = readdir(dirp)) != NULL) {
    if (direntp->d_name[0] == '.')
      continue;
    sprintf(spath, "%s/%s", path, direntp->d_name);
    s = stat(spath, &dstat);
    if ((s == 0) && (S_ISDIR(dstat.st_mode))) {
      maketree(spath, patn);
    }
  }
  closedir(dirp);
  return 0;
}


x86 assembly (clang, -O0):
<maketree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe2a(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ff <maketree+0x5f>
movl   $0x0,-0x4(%rbp)
jmp    1331 <maketree+0x191>
jmp    1204 <maketree+0x64>
mov    -0x28(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1268 <maketree+0xc8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1233 <maketree+0x93>
jmp    1204 <maketree+0x64>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
xor    %edx,%edx
call   1060 <fnmatch@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x1,-0x30(%rbp)
jne    1263 <maketree+0xc3>
jmp    1268 <maketree+0xc8>
jmp    1204 <maketree+0x64>
cmpl   $0x1,-0x30(%rbp)
jne    1287 <maketree+0xe7>
mov    -0x28(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x0,-0x4(%rbp)
jmp    1331 <maketree+0x191>
mov    -0x28(%rbp),%rdi
call   1070 <rewinddir@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1321 <maketree+0x181>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    12bf <maketree+0x11f>
jmp    1290 <maketree+0xf0>
lea    -0x1040(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
lea    0xd2c(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x1040(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10a0 <stat@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    131c <maketree+0x17c>
mov    -0x38(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     131c <maketree+0x17c>
lea    -0x1040(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <maketree@plt>
jmp    1290 <maketree+0xf0>
mov    -0x28(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<maketree>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
mov    %r15,%rdx
call   1090 <fprintf@plt>
mov    %r15,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1295 <maketree+0xf5>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     1216 <maketree+0x76>
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
je     11f0 <maketree+0x50>
mov    %r14,%rdi
xor    %edx,%edx
call   1060 <fnmatch@plt>
test   %rax,%rax
jne    11f0 <maketree+0x50>
jmp    128d <maketree+0xed>
mov    %rbx,%rdi
call   1070 <rewinddir@plt>
mov    %rbx,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     128d <maketree+0xed>
lea    0xdd2(%rip),%r12
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%rbp
jmp    124d <maketree+0xad>
xchg   %ax,%ax
mov    %rbx,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     128d <maketree+0xed>
mov    (%rax),%rcx
cmpb   $0x2e,(%rcx)
je     1240 <maketree+0xa0>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   10c0 <sprintf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   10a0 <stat@plt>
test   %eax,%eax
jne    1240 <maketree+0xa0>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     1240 <maketree+0xa0>
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <maketree@plt>
jmp    1240 <maketree+0xa0>
mov    %rbx,%rdi
call   1080 <closedir@plt>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@stdout = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i32 @maketree(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.dirent*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.stat
%11 = alloca [4096 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store %struct.dirent* null, %struct.dirent** %6
store i32 0, i32* %9
%12 = load i32, i32* @stdout
%13 = load i8*, i8** %4
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %4
%16 = call i32* @opendir(i8* %15)
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 0, i32* %3
br label %92
20: ; preds = %2
br label %21
21: ; preds = %45, %33, %20
%22 = load i32*, i32** %7
%23 = call %struct.dirent* @readdir(i32* %22)
store %struct.dirent* %23, %struct.dirent** %6
%24 = icmp ne %struct.dirent* %23, null
br i1 %24, label %25, label %46
25: ; preds = %21
%26 = load %struct.dirent*, %struct.dirent** %6
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 46
br i1 %32, label %33, label %34
33: ; preds = %25
br label %21
34: ; preds = %25
%35 = load i8*, i8** %5
%36 = load %struct.dirent*, %struct.dirent** %6
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i64 @fnmatch(i8* %35, i8* %38, i32 0)
%40 = icmp eq i64 %39, 0
%41 = zext i1 %40 to i32
store i32 %41, i32* %9
%42 = load i32, i32* %9
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %45
44: ; preds = %34
br label %46
45: ; preds = %34
br label %21
46: ; preds = %44, %21
%47 = load i32, i32* %9
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = load i32*, i32** %7
%51 = call i32 @closedir(i32* %50)
store i32 0, i32* %3
br label %92
52: ; preds = %46
%53 = load i32*, i32** %7
%54 = call i32 @rewinddir(i32* %53)
br label %55
55: ; preds = %88, %67, %52
%56 = load i32*, i32** %7
%57 = call %struct.dirent* @readdir(i32* %56)
store %struct.dirent* %57, %struct.dirent** %6
%58 = icmp ne %struct.dirent* %57, null
br i1 %58, label %59, label %89
59: ; preds = %55
%60 = load %struct.dirent*, %struct.dirent** %6
%61 = getelementptr inbounds %struct.dirent, %struct.dirent* %60, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = getelementptr inbounds i8, i8* %62, i64 0
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 46
br i1 %66, label %67, label %68
67: ; preds = %59
br label %55
68: ; preds = %59
%69 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%70 = load i8*, i8** %4
%71 = load %struct.dirent*, %struct.dirent** %6
%72 = getelementptr inbounds %struct.dirent, %struct.dirent* %71, i32 0, i32 0
%73 = load i8*, i8** %72
%74 = call i32 @sprintf(i8* %69, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %70, i8* %73)
%75 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%76 = call i32 @stat(i8* %75, %struct.stat* %10)
store i32 %76, i32* %8
%77 = load i32, i32* %8
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %88
79: ; preds = %68
%80 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%81 = load i32, i32* %80
%82 = call i64 @S_ISDIR(i32 %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %79
%85 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%86 = load i8*, i8** %5
%87 = call i32 @maketree(i8* %85, i8* %86)
br label %88
88: ; preds = %84, %79, %68
br label %55
89: ; preds = %55
%90 = load i32*, i32** %7
%91 = call i32 @closedir(i32* %90)
store i32 0, i32* %3
br label %92
92: ; preds = %89, %49, %19
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@stdout = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i32 @maketree(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca [4096 x i8]
%5 = bitcast %struct.stat* %3 to i8*
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @stdout
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32* @opendir(i8* %0)
%10 = icmp eq i32* %9, null
br i1 %10, label %55, label %11
11: ; preds = %2
%12 = tail call %struct.dirent* @readdir(i32* %9)
%13 = icmp eq %struct.dirent* %12, null
br i1 %13, label %28, label %14
14: ; preds = %11, %20
%15 = phi %struct.dirent* [ %21, %20 ], [ %12, %11 ]
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 46
br i1 %19, label %20, label %23
20: ; preds = %14, %23
%21 = tail call %struct.dirent* @readdir(i32* %9)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %28, label %14
23: ; preds = %14
%24 = tail call i64 @fnmatch(i8* %1, i8* %17, i32 0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %20
26: ; preds = %23
%27 = tail call i32 @closedir(i32* %9)
br label %55
28: ; preds = %20, %11
%29 = tail call i32 @rewinddir(i32* %9)
%30 = call %struct.dirent* @readdir(i32* %9)
%31 = icmp eq %struct.dirent* %30, null
br i1 %31, label %53, label %32
32: ; preds = %28
%33 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %34
34: ; preds = %32, %50
%35 = phi %struct.dirent* [ %30, %32 ], [ %51, %50 ]
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i64 0, i32 0
%37 = load i8*, i8** %36
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 46
br i1 %39, label %50, label %40
40: ; preds = %34
%41 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %37)
%42 = call i32 @stat(i8* %6, %struct.stat* %3)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %40
%45 = load i32, i32* %33
%46 = call i64 @S_ISDIR(i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %50, label %48
48: ; preds = %44
%49 = call i32 @maketree(i8* %6, i8* %1)
br label %50
50: ; preds = %40, %44, %48, %34
%51 = call %struct.dirent* @readdir(i32* %9)
%52 = icmp eq %struct.dirent* %51, null
br i1 %52, label %53, label %34
53: ; preds = %50, %28
%54 = call i32 @closedir(i32* %9)
br label %55
55: ; preds = %2, %53, %26
ret i32 0
}