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

/* Variables and functions */
int /*<<< orphan*/ add_function(char *, char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ is_c_file(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *str_coupler(char *, char *);
int get_c_files(char *path, char *hpath) {
  DIR *dir;
  struct dirent *dp;
  char *tmp;
  char *tmp2;
  if ((dir = opendir(path)) == NULL) {
    fprintf(stderr, "Can't open %s\n", path);
    return (-1);
  }
  while (dir) {
    if ((dp = readdir(dir)) != NULL && is_c_file(dp->d_type, dp->d_name)) {
      tmp = str_coupler(path, "/");
      tmp2 = str_coupler(tmp, dp->d_name);
      printf("/* In %s */\n", tmp2);
      free(tmp2);
      add_function(str_coupler(tmp, dp->d_name), hpath);
      free(tmp);
    } else if (dp == NULL) {
      closedir(dir);
      dir = NULL;
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<get_c_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11dc <get_c_files+0x4c>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe35(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b8 <get_c_files+0x128>
jmp    11e1 <get_c_files+0x51>
cmpq   $0x0,-0x20(%rbp)
je     12b1 <get_c_files+0x121>
mov    -0x20(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     128b <get_c_files+0xfb>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
call   10b0 <is_c_file@plt>
cmp    $0x0,%rax
je     128b <get_c_files+0xfb>
mov    -0x10(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   10a0 <str_coupler@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
call   10a0 <str_coupler@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xdbe(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
call   10a0 <str_coupler@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1070 <add_function@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12ac <get_c_files+0x11c>
cmpq   $0x0,-0x28(%rbp)
jne    12a7 <get_c_files+0x117>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
movq   $0x0,-0x20(%rbp)
jmp    12ac <get_c_files+0x11c>
jmp    11e1 <get_c_files+0x51>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_c_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <opendir@plt>
test   %rax,%rax
je     1256 <get_c_files+0xc6>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     124a <get_c_files+0xba>
mov    %rax,%rbp
jmp    11e0 <get_c_files+0x50>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     124a <get_c_files+0xba>
mov    0x8(%rbp),%edi
mov    0x0(%rbp),%rsi
call   10b0 <is_c_file@plt>
test   %rax,%rax
je     11d0 <get_c_files+0x40>
mov    %r15,%rdi
lea    0xe14(%rip),%rsi
call   10a0 <str_coupler@plt>
mov    %rax,%r12
mov    0x0(%rbp),%rsi
mov    %rax,%rdi
call   10a0 <str_coupler@plt>
mov    %rax,%r13
lea    0xdf8(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    0x0(%rbp),%rsi
mov    %r12,%rdi
call   10a0 <str_coupler@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <add_function@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    11d0 <get_c_files+0x40>
mov    %rbx,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
jmp    1273 <get_c_files+0xe3>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
mov    %r15,%rdx
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8*, i32 }
@stderr = global i32 0
@.str = [15 x i8] c"Can't open %s\0A\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [13 x i8] c"/* In %s */\0A\00"
define i32 @get_c_files(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i32* @opendir(i8* %10)
store i32* %11, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %4
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
br label %64
17: ; preds = %2
br label %18
18: ; preds = %62, %17
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %63
21: ; preds = %18
%22 = load i32*, i32** %6
%23 = call %struct.dirent* @readdir(i32* %22)
store %struct.dirent* %23, %struct.dirent** %7
%24 = icmp ne %struct.dirent* %23, null
br i1 %24, label %25, label %55
25: ; preds = %21
%26 = load %struct.dirent*, %struct.dirent** %7
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 1
%28 = load i32, i32* %27
%29 = load %struct.dirent*, %struct.dirent** %7
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i64 @is_c_file(i32 %28, i8* %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %55
34: ; preds = %25
%35 = load i8*, i8** %4
%36 = call i8* @str_coupler(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %36, i8** %8
%37 = load i8*, i8** %8
%38 = load %struct.dirent*, %struct.dirent** %7
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i8* @str_coupler(i8* %37, i8* %40)
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %9
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %8
%47 = load %struct.dirent*, %struct.dirent** %7
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 0
%49 = load i8*, i8** %48
%50 = call i8* @str_coupler(i8* %46, i8* %49)
%51 = load i8*, i8** %5
%52 = call i32 @add_function(i8* %50, i8* %51)
%53 = load i8*, i8** %8
%54 = call i32 @free(i8* %53)
br label %62
55: ; preds = %25, %21
%56 = load %struct.dirent*, %struct.dirent** %7
%57 = icmp eq %struct.dirent* %56, null
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32*, i32** %6
%60 = call i32 @closedir(i32* %59)
store i32* null, i32** %6
br label %61
61: ; preds = %58, %55
br label %62
62: ; preds = %61, %34
br label %18
63: ; preds = %18
store i32 0, i32* %3
br label %64
64: ; preds = %63, %13
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i32 }
@stderr = global i32 0
@.str = [15 x i8] c"Can't open %s\0A\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [13 x i8] c"/* In %s */\0A\00"
define i32 @get_c_files(i8* %0, i8* %1) {
%3 = tail call i32* @opendir(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %32, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %34
11: ; preds = %5, %29
%12 = phi %struct.dirent* [ %30, %29 ], [ %6, %5 ]
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = tail call i64 @is_c_file(i32 %14, i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %29, label %19
19: ; preds = %11
%20 = tail call i8* @str_coupler(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = load i8*, i8** %15
%22 = tail call i8* @str_coupler(i8* %20, i8* %21)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = tail call i32 @free(i8* %22)
%25 = load i8*, i8** %15
%26 = tail call i8* @str_coupler(i8* %20, i8* %25)
%27 = tail call i32 @add_function(i8* %26, i8* %1)
%28 = tail call i32 @free(i8* %20)
br label %29
29: ; preds = %11, %19
%30 = tail call %struct.dirent* @readdir(i32* %3)
%31 = icmp eq %struct.dirent* %30, null
br i1 %31, label %32, label %11
32: ; preds = %29, %5
%33 = tail call i32 @closedir(i32* %3)
br label %34
34: ; preds = %32, %8
%35 = phi i32 [ -1, %8 ], [ 0, %32 ]
ret i32 %35
}