#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;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ luaglew_get_consts(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ luaglew_get_funcs(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int luaglew_get_lists(char *path, FILE *consts_list, FILE *funcs_name_list,
                      FILE *funcs_prot_list) {
  DIR *dir = opendir(path);
  FILE *f;
  char path_name[200];
  int count = 0;
  if (dir) {
    struct dirent *ent;
    while ((ent = readdir(dir)) != NULL) {
      if (strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0) {
        printf("Opening file ");
        strcpy(path_name, path);
        strcat(path_name, "/");
        strcat(path_name, ent->d_name);
        printf("%s\n", path_name);
        if ((f = fopen(path_name, "r")) == NULL) {
          fprintf(stderr, "\tERROR: cannot open file %s\n", path_name);
          continue;
        }
        count++;
        luaglew_get_consts(f, consts_list);
        fseek(f, 0, SEEK_SET);
        luaglew_get_funcs(f, funcs_prot_list, funcs_name_list);
        fclose(f);
      }
    }
  } else {
    fprintf(stderr, "ERROR: directory %s not found\n", path);
    return 1;
  }
  printf("\n__________________ OK (%d files scanned) ________________\n",
         count);
  fprintf(funcs_prot_list, "\n");
  return 0;
}


x86 assembly (clang, -O0):
<luaglew_get_lists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x104(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1351 <luaglew_get_lists+0x191>
jmp    1202 <luaglew_get_lists+0x42>
mov    -0x30(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x110(%rbp)
cmp    $0x0,%rax
je     134c <luaglew_get_lists+0x18c>
mov    -0x110(%rbp),%rax
mov    (%rax),%rdi
lea    0xdd4(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1347 <luaglew_get_lists+0x187>
mov    -0x110(%rbp),%rax
mov    (%rax),%rdi
lea    0xdb3(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1347 <luaglew_get_lists+0x187>
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x100(%rbp),%rdi
lea    0xd89(%rip),%rsi
call   10e0 <strcat@plt>
lea    -0x100(%rbp),%rdi
mov    -0x110(%rbp),%rax
mov    (%rax),%rsi
call   10e0 <strcat@plt>
lea    -0x100(%rbp),%rsi
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x100(%rbp),%rdi
lea    0xd4d(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    12fd <luaglew_get_lists+0x13d>
mov    0x2d00(%rip),%rax
movslq (%rax),%rdi
lea    -0x100(%rbp),%rdx
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1202 <luaglew_get_lists+0x42>
mov    -0x104(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x104(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <luaglew_get_consts@plt>
mov    -0x38(%rbp),%rdi
mov    0x2cb4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <luaglew_get_funcs@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1202 <luaglew_get_lists+0x42>
jmp    1379 <luaglew_get_lists+0x1b9>
mov    0x2c88(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rdx
lea    0xccc(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a6 <luaglew_get_lists+0x1e6>
mov    -0x104(%rbp),%esi
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xcf3(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<luaglew_get_lists>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %rcx,0x8(%rsp)
mov    %rdx,0x18(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,%r14
call   1060 <opendir@plt>
test   %rax,%rax
je     1365 <luaglew_get_lists+0x185>
mov    %rax,%rbp
mov    %rax,%rdi
call   10c0 <readdir@plt>
movl   $0x0,0x4(%rsp)
test   %rax,%rax
je     1340 <luaglew_get_lists+0x160>
mov    %rax,%r13
lea    0xdca(%rip),%r12
lea    0x20(%rsp),%r15
movl   $0x0,0x4(%rsp)
jmp    127f <luaglew_get_lists+0x9f>
cs nopw 0x0(%rax,%rax,1)
mov    0x2d89(%rip),%rax
movslq (%rax),%rdi
lea    0xdb4(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rbp,%rdi
call   10c0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1340 <luaglew_get_lists+0x160>
mov    0x0(%r13),%rdi
mov    %r12,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     126b <luaglew_get_lists+0x8b>
mov    0x0(%r13),%rdi
lea    0xd65(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     126b <luaglew_get_lists+0x8b>
lea    0xd57(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
lea    0xd49(%rip),%rsi
call   1100 <strcat@plt>
mov    0x0(%r13),%rsi
mov    %r15,%rdi
call   1100 <strcat@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
lea    0xd28(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1250 <luaglew_get_lists+0x70>
mov    %rax,%rbx
addl   $0x1,0x4(%rsp)
mov    %rax,%rdi
mov    0x10(%rsp),%rsi
call   10d0 <luaglew_get_consts@plt>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %rbx,%rdi
mov    0x8(%rsp),%rsi
mov    0x18(%rsp),%rdx
call   1080 <luaglew_get_funcs@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    126b <luaglew_get_lists+0x8b>
lea    0xd0a(%rip),%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%edi
mov    0x8(%rsp),%rsi
call   1090 <fputc@plt>
xor    %eax,%eax
jmp    1385 <luaglew_get_lists+0x1a5>
mov    0x2c74(%rip),%rax
movslq (%rax),%rdi
lea    0xcbc(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [14 x i8] c"Opening file \00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.6 = [29 x i8] c"\09ERROR: cannot open file %s\0A\00"
@SEEK_SET = global i32 0
@.str.7 = [31 x i8] c"ERROR: directory %s not found\0A\00"
@.str.8 = [60 x i8] c"\0A__________________ OK (%d files scanned) ________________\0A\00"
@.str.9 = [2 x i8] c"\0A\00"
define i32 @luaglew_get_lists(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca [200 x i8]
%13 = alloca i32
%14 = alloca %struct.dirent*
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%15 = load i8*, i8** %6
%16 = call i32* @opendir(i8* %15)
store i32* %16, i32** %10
store i32 0, i32* %13
%17 = load i32*, i32** %10
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %76
19: ; preds = %4
br label %20
20: ; preds = %74, %53, %19
%21 = load i32*, i32** %10
%22 = call %struct.dirent* @readdir(i32* %21)
store %struct.dirent* %22, %struct.dirent** %14
%23 = icmp ne %struct.dirent* %22, null
br i1 %23, label %24, label %75
24: ; preds = %20
%25 = load %struct.dirent*, %struct.dirent** %14
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i32 0, i32 0
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %74
30: ; preds = %24
%31 = load %struct.dirent*, %struct.dirent** %14
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %74
36: ; preds = %30
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%38 = getelementptr inbounds [200 x i8], [200 x i8]* %12, i64 0, i64 0
%39 = load i8*, i8** %6
%40 = call i32 @strcpy(i8* %38, i8* %39)
%41 = getelementptr inbounds [200 x i8], [200 x i8]* %12, i64 0, i64 0
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%43 = getelementptr inbounds [200 x i8], [200 x i8]* %12, i64 0, i64 0
%44 = load %struct.dirent*, %struct.dirent** %14
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i32 @strcat(i8* %43, i8* %46)
%48 = getelementptr inbounds [200 x i8], [200 x i8]* %12, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = getelementptr inbounds [200 x i8], [200 x i8]* %12, i64 0, i64 0
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %51, i32** %11
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %59
53: ; preds = %36
%54 = load i32, i32* @stderr
%55 = sext i32 %54 to i64
%56 = inttoptr i64 %55 to i32*
%57 = getelementptr inbounds [200 x i8], [200 x i8]* %12, i64 0, i64 0
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %57)
br label %20
59: ; preds = %36
%60 = load i32, i32* %13
%61 = add nsw i32 %60, 1
store i32 %61, i32* %13
%62 = load i32*, i32** %11
%63 = load i32*, i32** %7
%64 = call i32 @luaglew_get_consts(i32* %62, i32* %63)
%65 = load i32*, i32** %11
%66 = load i32, i32* @SEEK_SET
%67 = call i32 @fseek(i32* %65, i32 0, i32 %66)
%68 = load i32*, i32** %11
%69 = load i32*, i32** %9
%70 = load i32*, i32** %8
%71 = call i32 @luaglew_get_funcs(i32* %68, i32* %69, i32* %70)
%72 = load i32*, i32** %11
%73 = call i32 @fclose(i32* %72)
br label %74
74: ; preds = %59, %30, %24
br label %20
75: ; preds = %20
br label %82
76: ; preds = %4
%77 = load i32, i32* @stderr
%78 = sext i32 %77 to i64
%79 = inttoptr i64 %78 to i32*
%80 = load i8*, i8** %6
%81 = call i32 (i32*, i8*, ...) @fprintf(i32* %79, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %80)
store i32 1, i32* %5
br label %87
82: ; preds = %75
%83 = load i32, i32* %13
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0), i32 %83)
%85 = load i32*, i32** %9
%86 = call i32 (i32*, i8*, ...) @fprintf(i32* %85, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %5
br label %87
87: ; preds = %82, %76
%88 = load i32, i32* %5
ret i32 %88
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [14 x i8] c"Opening file \00"
@.str.3 = [2 x i8] c"/\00"
@.str.5 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.6 = [29 x i8] c"\09ERROR: cannot open file %s\0A\00"
@SEEK_SET = global i32 0
@.str.7 = [31 x i8] c"ERROR: directory %s not found\0A\00"
@.str.8 = [60 x i8] c"\0A__________________ OK (%d files scanned) ________________\0A\00"
define i32 @luaglew_get_lists(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca [200 x i8]
%6 = tail call i32* @opendir(i8* %0)
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%8 = icmp eq i32* %6, null
br i1 %8, label %56, label %9
9: ; preds = %4
%10 = call %struct.dirent* @readdir(i32* %6)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %52, label %12
12: ; preds = %9, %48
%13 = phi %struct.dirent* [ %50, %48 ], [ %10, %9 ]
%14 = phi i32 [ %49, %48 ], [ 0, %9 ]
br label %15
15: ; preds = %12, %34
%16 = phi %struct.dirent* [ %13, %12 ], [ %39, %34 ]
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 0
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %48, label %21
21: ; preds = %15
%22 = load i8*, i8** %17
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %48, label %25
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @strcpy(i8* %7, i8* %0)
%28 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%29 = load i8*, i8** %17
%30 = call i32 @strcat(i8* %7, i8* %29)
%31 = call i32 @puts(i8* %7)
%32 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %41
34: ; preds = %25
%35 = load i32, i32* @stderr
%36 = sext i32 %35 to i64
%37 = inttoptr i64 %36 to i32*
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%39 = call %struct.dirent* @readdir(i32* %6)
%40 = icmp eq %struct.dirent* %39, null
br i1 %40, label %52, label %15
41: ; preds = %25
%42 = add nsw i32 %14, 1
%43 = call i32 @luaglew_get_consts(i32* %32, i32* %1)
%44 = load i32, i32* @SEEK_SET
%45 = call i32 @fseek(i32* %32, i32 0, i32 %44)
%46 = call i32 @luaglew_get_funcs(i32* %32, i32* %3, i32* %2)
%47 = call i32 @fclose(i32* %32)
br label %48
48: ; preds = %21, %15, %41
%49 = phi i32 [ %42, %41 ], [ %14, %15 ], [ %14, %21 ]
%50 = call %struct.dirent* @readdir(i32* %6)
%51 = icmp eq %struct.dirent* %50, null
br i1 %51, label %52, label %12
52: ; preds = %48, %34, %9
%53 = phi i32 [ 0, %9 ], [ %14, %34 ], [ %49, %48 ]
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.8, i64 0, i64 0), i32 %53)
%55 = call i32 @fputc(i32 10, i32* %3)
br label %61
56: ; preds = %4
%57 = load i32, i32* @stderr
%58 = sext i32 %57 to i64
%59 = inttoptr i64 %58 to i32*
%60 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %0)
br label %61
61: ; preds = %52, %56
%62 = phi i32 [ 0, %52 ], [ 1, %56 ]
ret i32 %62
}