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

/* Variables and functions */
scalar_t__ S_ISDIR(int);
int /*<<< orphan*/ chdir(char const *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char const *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char *, char const *, int /*<<< orphan*/);
int get_name(const char *pre, const char *path, const char *match, int mode) {
  DIR *dir;
  struct dirent *de;
  struct stat info;
  const char *p = (path[0] == '\0' ? "/" : path);
  if (!(dir = opendir(p)))
    return 1;
  chdir(p);
  while ((de = readdir(dir))) {
    if (de->d_name[0] == '.' || strncmp(de->d_name, match, strlen(match)))
      continue;
    stat(de->d_name, &info);
    if (!(info.st_mode & mode))
      continue;
    printf(pre);
    if (mode & 0100000 || pre[0] != '\0')
      printf("%s/", path);
    if (S_ISDIR(info.st_mode))
      printf("%s/\n", de->d_name);
    else
      printf("%s\n", de->d_name);
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<get_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c7 <get_name+0x37>
lea    0xe44(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    11cf <get_name+0x3f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11fa <get_name+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    131f <get_name+0x18f>
mov    -0x48(%rbp),%rdi
call   1060 <chdir@plt>
mov    -0x30(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     130f <get_name+0x17f>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1262 <get_name+0xd2>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1267 <get_name+0xd7>
jmp    1203 <get_name+0x73>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <stat@plt>
mov    -0x40(%rbp),%eax
and    -0x24(%rbp),%eax
cmp    $0x0,%eax
jne    128b <get_name+0xfb>
jmp    1203 <get_name+0x73>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x24(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
jne    12b7 <get_name+0x127>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12c9 <get_name+0x139>
mov    -0x18(%rbp),%rsi
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x40(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12f5 <get_name+0x165>
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
lea    0xd1b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    130a <get_name+0x17a>
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1203 <get_name+0x73>
mov    -0x30(%rbp),%rdi
call   1090 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmpb   $0x0,(%rsi)
mov    %ecx,%r12d
mov    %rdx,%r14
mov    %rdi,0x8(%rsp)
lea    0xe3f(%rip),%rbx
mov    %rsi,0x10(%rsp)
cmovne %rsi,%rbx
mov    %rbx,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     12bc <get_name+0x11c>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1070 <chdir@plt>
mov    %rbp,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
je     12b0 <get_name+0x110>
mov    %rax,%r13
jmp    1224 <get_name+0x84>
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
nopl   0x0(%rax)
mov    %rbp,%rdi
call   10c0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     12b0 <get_name+0x110>
mov    0x0(%r13),%rbx
cmpb   $0x2e,(%rbx)
je     1210 <get_name+0x70>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1210 <get_name+0x70>
mov    0x0(%r13),%rdi
mov    %rsp,%rsi
call   10b0 <stat@plt>
mov    (%rsp),%r15d
test   %r12d,%r15d
je     1210 <get_name+0x70>
mov    0x8(%rsp),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
test   $0x8000,%r12d
jne    127b <get_name+0xdb>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     128e <get_name+0xee>
lea    0xd7e(%rip),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15d,%edi
call   1090 <S_ISDIR@plt>
mov    0x0(%r13),%rsi
test   %rax,%rax
jne    11fe <get_name+0x5e>
mov    %rsi,%rdi
call   1040 <puts@plt>
jmp    1210 <get_name+0x70>
mov    %rbp,%rdi
call   10a0 <closedir@plt>
xor    %eax,%eax
jmp    12c1 <get_name+0x121>
mov    $0x1,%eax
add    $0x18,%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 }
@.str = [2 x i8] c"/\00"
@.str.1 = [4 x i8] c"%s/\00"
@.str.2 = [5 x i8] c"%s/\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @get_name(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca %struct.dirent*
%12 = alloca %struct.stat
%13 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%14 = load i8*, i8** %7
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %4
br label %22
20: ; preds = %4
%21 = load i8*, i8** %7
br label %22
22: ; preds = %20, %19
%23 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %19 ], [ %21, %20 ]
store i8* %23, i8** %13
%24 = load i8*, i8** %13
%25 = call i32* @opendir(i8* %24)
store i32* %25, i32** %10
%26 = icmp ne i32* %25, null
br i1 %26, label %28, label %27
27: ; preds = %22
store i32 1, i32* %5
br label %98
28: ; preds = %22
%29 = load i8*, i8** %13
%30 = call i32 @chdir(i8* %29)
br label %31
31: ; preds = %94, %63, %52, %28
%32 = load i32*, i32** %10
%33 = call %struct.dirent* @readdir(i32* %32)
store %struct.dirent* %33, %struct.dirent** %11
%34 = icmp ne %struct.dirent* %33, null
br i1 %34, label %35, label %95
35: ; preds = %31
%36 = load %struct.dirent*, %struct.dirent** %11
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = getelementptr inbounds i8, i8* %38, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 46
br i1 %42, label %52, label %43
43: ; preds = %35
%44 = load %struct.dirent*, %struct.dirent** %11
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = load i8*, i8** %8
%48 = load i8*, i8** %8
%49 = call i32 @strlen(i8* %48)
%50 = call i64 @strncmp(i8* %46, i8* %47, i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %43, %35
br label %31
53: ; preds = %43
%54 = load %struct.dirent*, %struct.dirent** %11
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = call i32 @stat(i8* %56, %struct.stat* %12)
%58 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%59 = load i32, i32* %58
%60 = load i32, i32* %9
%61 = and i32 %59, %60
%62 = icmp ne i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %53
br label %31
64: ; preds = %53
%65 = load i8*, i8** %6
%66 = call i32 (i8*, ...) @printf(i8* %65)
%67 = load i32, i32* %9
%68 = and i32 %67, 32768
%69 = icmp ne i32 %68, 0
br i1 %69, label %76, label %70
70: ; preds = %64
%71 = load i8*, i8** %6
%72 = getelementptr inbounds i8, i8* %71, i64 0
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %70, %64
%77 = load i8*, i8** %7
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %77)
br label %79
79: ; preds = %76, %70
%80 = getelementptr inbounds %struct.stat, %struct.stat* %12, 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 %89
84: ; preds = %79
%85 = load %struct.dirent*, %struct.dirent** %11
%86 = getelementptr inbounds %struct.dirent, %struct.dirent* %85, i32 0, i32 0
%87 = load i8*, i8** %86
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %87)
br label %94
89: ; preds = %79
%90 = load %struct.dirent*, %struct.dirent** %11
%91 = getelementptr inbounds %struct.dirent, %struct.dirent* %90, i32 0, i32 0
%92 = load i8*, i8** %91
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %92)
br label %94
94: ; preds = %89, %84
br label %31
95: ; preds = %31
%96 = load i32*, i32** %10
%97 = call i32 @closedir(i32* %96)
store i32 0, i32* %5
br label %98
98: ; preds = %95, %27
%99 = load i32, i32* %5
ret i32 %99
}

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