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

/* Variables and functions */
scalar_t__ DT_DIR;
scalar_t__ DT_REG;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int snprintf(char *, size_t, char *, char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
char *strrstr(char *, char *);
void find_c_files(const char *dir_name, size_t cwd_i) {
  static char path_buff[4096];
  size_t space_left = sizeof(path_buff) - cwd_i;
  int chars_added;
  chars_added = snprintf(&path_buff[cwd_i], space_left, "%s/", dir_name);
  if (chars_added >= space_left) {
    fprintf(stderr, "Warning: pathname too long, skipping (%s)\n", path_buff);
    return;
  }
  DIR *dir = opendir(path_buff);
  struct dirent *dent;
  while ((dent = readdir(dir)) != NULL) {
    if (dent->d_type == DT_DIR && strcmp(dent->d_name, ".") &&
        strcmp(dent->d_name, "..")) {
      find_c_files(dent->d_name, cwd_i + chars_added);
    } else if (dent->d_type == DT_REG) {
      const char *ptr = strrstr(dent->d_name, ".c");
      if (ptr != NULL && !strcmp(ptr, ".c")) {
        printf("%s%s\n", path_buff, dent->d_name);
      }
    }
  }
}


x86 assembly (clang, -O0):
<find_c_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1000,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0x2ecc(%rip),%rdi
add    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rcx
lea    0xe49(%rip),%rdx
call   1060 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     11ee <find_c_files+0x6e>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
lea    0x2e8c(%rip),%rdx
call   1080 <fprintf@plt>
jmp    1303 <find_c_files+0x183>
lea    0x2e7b(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1303 <find_c_files+0x183>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    0x2dad(%rip),%rcx
cmp    (%rcx),%rax
jne    1285 <find_c_files+0x105>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1285 <find_c_files+0x105>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd6(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1285 <find_c_files+0x105>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   10a0 <find_c_files@plt>
jmp    12fe <find_c_files+0x17e>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    0x2d4d(%rip),%rcx
cmp    (%rcx),%rax
jne    12f9 <find_c_files+0x179>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd87(%rip),%rsi
call   1040 <strrstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     12f4 <find_c_files+0x174>
mov    -0x38(%rbp),%rdi
lea    0xd68(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12f4 <find_c_files+0x174>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd4d(%rip),%rdi
lea    0x2d81(%rip),%rsi
call   1050 <printf@plt>
jmp    12f9 <find_c_files+0x179>
jmp    12fe <find_c_files+0x17e>
jmp    11fe <find_c_files+0x7e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_c_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rcx
mov    $0x1000,%ebx
sub    %rsi,%rbx
lea    0x2ed0(%rip),%rdi
add    %rsi,%rdi
lea    0xe56(%rip),%rdx
mov    %rbx,%rsi
call   1060 <snprintf@plt>
movslq %eax,%r14
cmp    %r14,%rbx
jbe    12a6 <find_c_files+0x126>
lea    0x2eab(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     12d0 <find_c_files+0x150>
mov    %rax,%rbp
add    %r15,%r14
mov    0x2de5(%rip),%r12
mov    0x2dee(%rip),%r15
lea    0xe39(%rip),%r13
jmp    1224 <find_c_files+0xa4>
mov    0x8(%rbp),%rdi
mov    %r14,%rsi
call   10a0 <find_c_files@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12d0 <find_c_files+0x150>
mov    0x0(%rbp),%rax
cmp    (%r12),%rax
jne    1260 <find_c_files+0xe0>
mov    0x8(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1260 <find_c_files+0xe0>
mov    0x8(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11fb <find_c_files+0x7b>
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%rax
cmp    (%r15),%rax
jne    1210 <find_c_files+0x90>
mov    0x8(%rbp),%rdi
mov    %r13,%rsi
call   1040 <strrstr@plt>
test   %rax,%rax
je     1210 <find_c_files+0x90>
mov    %rax,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1210 <find_c_files+0x90>
mov    0x8(%rbp),%rdx
lea    0xda0(%rip),%rdi
lea    0x2dd4(%rip),%rsi
call   1050 <printf@plt>
jmp    1210 <find_c_files+0x90>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
lea    0x2db3(%rip),%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i64, i8* }
@find_c_files.path_buff = internal global [4096 x i8] zeroinitializer
@.str = [4 x i8] c"%s/\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Warning: pathname too long, skipping (%s)\0A\00"
@DT_DIR = global i64 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@DT_REG = global i64 0
@.str.4 = [3 x i8] c".c\00"
@.str.5 = [6 x i8] c"%s%s\0A\00"
define void @find_c_files(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%10 = load i64, i64* %4
%11 = sub i64 4096, %10
store i64 %11, i64* %5
%12 = load i64, i64* %4
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* @find_c_files.path_buff, i64 0, i64 %12
%14 = load i64, i64* %5
%15 = load i8*, i8** %3
%16 = call i32 @snprintf(i8* %13, i64 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = load i64, i64* %5
%20 = icmp uge i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_c_files.path_buff, i64 0, i64 0))
br label %81
24: ; preds = %2
%25 = call i32* @opendir(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_c_files.path_buff, i64 0, i64 0))
store i32* %25, i32** %7
br label %26
26: ; preds = %80, %24
%27 = load i32*, i32** %7
%28 = call %struct.dirent* @readdir(i32* %27)
store %struct.dirent* %28, %struct.dirent** %8
%29 = icmp ne %struct.dirent* %28, null
br i1 %29, label %30, label %81
30: ; preds = %26
%31 = load %struct.dirent*, %struct.dirent** %8
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i64, i64* %32
%34 = load i64, i64* @DT_DIR
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %56
36: ; preds = %30
%37 = load %struct.dirent*, %struct.dirent** %8
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %37, i32 0, i32 1
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %56
42: ; preds = %36
%43 = load %struct.dirent*, %struct.dirent** %8
%44 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i32 0, i32 1
%45 = load i8*, i8** %44
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %42
%49 = load %struct.dirent*, %struct.dirent** %8
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i32 0, i32 1
%51 = load i8*, i8** %50
%52 = load i64, i64* %4
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = add i64 %52, %54
br label %80
56: ; preds = %42, %36, %30
%57 = load %struct.dirent*, %struct.dirent** %8
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i32 0, i32 0
%59 = load i64, i64* %58
%60 = load i64, i64* @DT_REG
%61 = icmp eq i64 %59, %60
br i1 %61, label %62, label %79
62: ; preds = %56
%63 = load %struct.dirent*, %struct.dirent** %8
%64 = getelementptr inbounds %struct.dirent, %struct.dirent* %63, i32 0, i32 1
%65 = load i8*, i8** %64
%66 = call i8* @strrstr(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i8* %66, i8** %9
%67 = load i8*, i8** %9
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %78
69: ; preds = %62
%70 = load i8*, i8** %9
%71 = call i64 @strcmp(i8* %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%72 = icmp ne i64 %71, 0
br i1 %72, label %78, label %73
73: ; preds = %69
%74 = load %struct.dirent*, %struct.dirent** %8
%75 = getelementptr inbounds %struct.dirent, %struct.dirent* %74, i32 0, i32 1
%76 = load i8*, i8** %75
%77 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_c_files.path_buff, i64 0, i64 0), i8* %76)
br label %78
78: ; preds = %73, %69, %62
br label %79
79: ; preds = %78, %56
br label %80
80: ; preds = %79, %48
br label %26
81: ; preds = %21, %26
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i64, i8* }
@find_c_files.path_buff = internal global [4096 x i8] zeroinitializer
@.str = [4 x i8] c"%s/\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Warning: pathname too long, skipping (%s)\0A\00"
@DT_DIR = global i64 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@DT_REG = global i64 0
@.str.4 = [3 x i8] c".c\00"
@.str.5 = [6 x i8] c"%s%s\0A\00"
define void @find_c_files(i8* %0, i64 %1) {
%3 = sub i64 4096, %1
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* @find_c_files.path_buff, i64 0, i64 %1
%5 = tail call i32 @snprintf(i8* %4, i64 %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = sext i32 %5 to i64
%7 = icmp ugt i64 %3, %6
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_c_files.path_buff, i64 0, i64 0))
br label %52
11: ; preds = %2
%12 = tail call i32* @opendir(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_c_files.path_buff, i64 0, i64 0))
%13 = tail call %struct.dirent* @readdir(i32* %12)
%14 = icmp eq %struct.dirent* %13, null
br i1 %14, label %52, label %15
15: ; preds = %11
%16 = add i64 %6, %1
br label %17
17: ; preds = %15, %49
%18 = phi %struct.dirent* [ %13, %15 ], [ %50, %49 ]
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i64 0, i32 0
%20 = load i64, i64* %19
%21 = load i64, i64* @DT_DIR
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %17
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i64 0, i32 1
%25 = load i8*, i8** %24
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %23
%29 = load i8*, i8** %24
%30 = tail call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = load i8*, i8** %24
tail call void @find_c_files(i8* %33, i64 %16)
br label %49
34: ; preds = %28, %23, %17
%35 = load i64, i64* %19
%36 = load i64, i64* @DT_REG
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %49
38: ; preds = %34
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i64 0, i32 1
%40 = load i8*, i8** %39
%41 = tail call i8* @strrstr(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%42 = icmp eq i8* %41, null
br i1 %42, label %49, label %43
43: ; preds = %38
%44 = tail call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i8*, i8** %39
%48 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @find_c_files.path_buff, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %38, %43, %46, %34, %32
%50 = tail call %struct.dirent* @readdir(i32* %12)
%51 = icmp eq %struct.dirent* %50, null
br i1 %51, label %52, label %17
52: ; preds = %49, %11, %8
ret void
}