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

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(struct stat *);
scalar_t__ malloc(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ sidparse(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int recurs(char *dir) {
  struct dirent *dir_entry;
  DIR *directory;
  struct stat *file_stat;
  char current_file[256];
  int number_of_files = 0;
  if (!(file_stat = (struct stat *)malloc(sizeof(struct stat)))) {
    fprintf(stderr, "Can't allocate memory!\n");
    exit(1);
  }
  if ((directory = opendir(dir)) == NULL)
    return -1;
  while ((dir_entry = readdir(directory)) != NULL) {
    if (dir_entry->d_name[0] != '.') {
      strcpy(current_file, dir);
      if (current_file[strlen(current_file) - 1] != '/')
        strncat(current_file, "/", 255 - strlen(current_file));
      strncat(current_file, dir_entry->d_name, 255 - strlen(current_file));
      stat(current_file, file_stat);
      if (S_ISDIR(file_stat->st_mode)) {
        printf("Moving into %s\n", current_file);
        number_of_files += recurs(current_file);
      } else if (S_ISREG(file_stat->st_mode) &&
                 (strcmp(".sid", current_file + strlen(current_file) - 4) ==
                  0)) {
        ++number_of_files;
        if (sidparse(current_file, file_stat->st_size))
          --number_of_files;
      }
    }
  }
  free(file_stat);
  closedir(directory);
  return number_of_files;
}


x86 assembly (clang, -O0):
<recurs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x134(%rbp)
mov    $0x8,%edi
call   1120 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1260 <recurs+0x50>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1283 <recurs+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    146f <recurs+0x25f>
jmp    1288 <recurs+0x78>
mov    -0x20(%rbp),%rdi
call   1100 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1454 <recurs+0x244>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     144f <recurs+0x23f>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x130(%rbp),%rdi
call   1070 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x130(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
je     1318 <recurs+0x108>
lea    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x130(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x140(%rbp),%rdi
mov    $0xff,%edx
sub    %eax,%edx
lea    0xd05(%rip),%rsi
call   10a0 <strncat@plt>
lea    -0x130(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x148(%rbp)
lea    -0x130(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x150(%rbp),%rdi
mov    -0x148(%rbp),%rsi
mov    $0xff,%edx
sub    %eax,%edx
call   10a0 <strncat@plt>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10e0 <stat@plt>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
call   1090 <S_ISDIR@plt>
cmp    $0x0,%rax
je     13b0 <recurs+0x1a0>
lea    -0x130(%rbp),%rsi
lea    0xc8c(%rip),%rdi
call   1080 <printf@plt>
lea    -0x130(%rbp),%rdi
call   1050 <recurs@plt>
add    -0x134(%rbp),%eax
mov    %eax,-0x134(%rbp)
jmp    144a <recurs+0x23a>
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
call   10f0 <S_ISREG@plt>
cmp    $0x0,%rax
je     1445 <recurs+0x235>
lea    -0x130(%rbp),%rax
mov    %rax,-0x158(%rbp)
lea    -0x130(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x158(%rbp),%rsi
cltq
add    %rax,%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xc33(%rip),%rdi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1445 <recurs+0x235>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1110 <sidparse@plt>
cmp    $0x0,%rax
je     1440 <recurs+0x230>
mov    -0x134(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x134(%rbp)
jmp    1445 <recurs+0x235>
jmp    144a <recurs+0x23a>
jmp    144f <recurs+0x23f>
jmp    1288 <recurs+0x78>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <closedir@plt>
mov    -0x134(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recurs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rbx
mov    $0x8,%edi
call   1120 <malloc@plt>
test   %rax,%rax
je     13c2 <recurs+0x1b2>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     138d <recurs+0x17d>
mov    %rax,%r15
mov    %rax,%rdi
call   1100 <readdir@plt>
test   %rax,%rax
je     1394 <recurs+0x184>
mov    %rax,%r13
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rbp
jmp    12ed <recurs+0xdd>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%rbx
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    $0xff,%edx
sub    %eax,%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <strncat@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10e0 <stat@plt>
mov    0x4(%r14),%edi
call   1090 <S_ISDIR@plt>
test   %rax,%rax
je     133c <recurs+0x12c>
lea    0xd58(%rip),%rdi
mov    %rbp,%rsi
call   1080 <printf@plt>
mov    %rbp,%rdi
call   1050 <recurs@plt>
add    %eax,0xc(%rsp)
mov    %r12,%rbx
mov    %r15,%rdi
call   1100 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     139c <recurs+0x18c>
mov    0x0(%r13),%rax
cmpb   $0x2e,(%rax)
je     12d9 <recurs+0xc9>
mov    %rbp,%rdi
mov    %rbx,%r12
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbp,1)
je     1280 <recurs+0x70>
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    $0xff,%edx
sub    %eax,%edx
mov    %rbp,%rdi
lea    0xce6(%rip),%rsi
call   10a0 <strncat@plt>
jmp    1280 <recurs+0x70>
mov    0x4(%r14),%edi
call   10f0 <S_ISREG@plt>
test   %rax,%rax
je     12d6 <recurs+0xc6>
mov    %rbp,%rdi
call   1070 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rsi
add    $0xc,%rsi
lea    0xcc7(%rip),%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
mov    %r12,%rbx
jne    12d9 <recurs+0xc9>
mov    (%r14),%esi
mov    %rbp,%rdi
call   1110 <sidparse@plt>
cmp    $0x1,%rax
adcl   $0x0,0xc(%rsp)
jmp    12d9 <recurs+0xc9>
mov    $0xffffffff,%eax
jmp    13b0 <recurs+0x1a0>
movl   $0x0,0xc(%rsp)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   10b0 <closedir@plt>
mov    0xc(%rsp),%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c17(%rip),%rax
mov    (%rax),%edi
lea    0xc2e(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32, i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Can't allocate memory!\0A\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [16 x i8] c"Moving into %s\0A\00"
@.str.3 = [5 x i8] c".sid\00"
define i32 @recurs(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.dirent*
%5 = alloca i32*
%6 = alloca %struct.stat*
%7 = alloca [256 x i8]
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %8
%9 = call i64 @malloc(i32 8)
%10 = inttoptr i64 %9 to %struct.stat*
store %struct.stat* %10, %struct.stat** %6
%11 = icmp ne %struct.stat* %10, null
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i32* @opendir(i8* %17)
store i32* %18, i32** %5
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 -1, i32* %2
br label %113
21: ; preds = %16
br label %22
22: ; preds = %106, %21
%23 = load i32*, i32** %5
%24 = call %struct.dirent* @readdir(i32* %23)
store %struct.dirent* %24, %struct.dirent** %4
%25 = icmp ne %struct.dirent* %24, null
br i1 %25, label %26, label %107
26: ; preds = %22
%27 = load %struct.dirent*, %struct.dirent** %4
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 46
br i1 %33, label %34, label %106
34: ; preds = %26
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%36 = load i8*, i8** %3
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 47
br i1 %45, label %46, label %52
46: ; preds = %34
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = sub nsw i32 255, %49
%51 = call i32 @strncat(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %46, %34
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%54 = load %struct.dirent*, %struct.dirent** %4
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%58 = call i32 @strlen(i8* %57)
%59 = sub nsw i32 255, %58
%60 = call i32 @strncat(i8* %53, i8* %56, i32 %59)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%62 = load %struct.stat*, %struct.stat** %6
%63 = call i32 @stat(i8* %61, %struct.stat* %62)
%64 = load %struct.stat*, %struct.stat** %6
%65 = getelementptr inbounds %struct.stat, %struct.stat* %64, i32 0, i32 1
%66 = load i32, i32* %65
%67 = call i64 @S_ISDIR(i32 %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %52
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%71 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %70)
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%73 = call i32 @recurs(i8* %72)
%74 = load i32, i32* %8
%75 = add nsw i32 %74, %73
store i32 %75, i32* %8
br label %105
76: ; preds = %52
%77 = load %struct.stat*, %struct.stat** %6
%78 = getelementptr inbounds %struct.stat, %struct.stat* %77, i32 0, i32 1
%79 = load i32, i32* %78
%80 = call i64 @S_ISREG(i32 %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %104
82: ; preds = %76
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%84 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%85 = call i32 @strlen(i8* %84)
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %83, i64 %86
%88 = getelementptr inbounds i8, i8* %87, i64 -4
%89 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %88)
%90 = icmp eq i64 %89, 0
br i1 %90, label %91, label %104
91: ; preds = %82
%92 = load i32, i32* %8
%93 = add nsw i32 %92, 1
store i32 %93, i32* %8
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%95 = load %struct.stat*, %struct.stat** %6
%96 = getelementptr inbounds %struct.stat, %struct.stat* %95, i32 0, i32 0
%97 = load i32, i32* %96
%98 = call i64 @sidparse(i8* %94, i32 %97)
%99 = icmp ne i64 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %91
%101 = load i32, i32* %8
%102 = add nsw i32 %101, -1
store i32 %102, i32* %8
br label %103
103: ; preds = %100, %91
br label %104
104: ; preds = %103, %82, %76
br label %105
105: ; preds = %104, %69
br label %106
106: ; preds = %105, %26
br label %22
107: ; preds = %22
%108 = load %struct.stat*, %struct.stat** %6
%109 = call i32 @free(%struct.stat* %108)
%110 = load i32*, i32** %5
%111 = call i32 @closedir(i32* %110)
%112 = load i32, i32* %8
store i32 %112, i32* %2
br label %113
113: ; preds = %107, %20
%114 = load i32, i32* %2
ret i32 %114
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [24 x i8] c"Can't allocate memory!\0A\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [16 x i8] c"Moving into %s\0A\00"
@.str.3 = [5 x i8] c".sid\00"
define i32 @recurs(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @malloc(i32 8)
%5 = inttoptr i64 %4 to %struct.stat*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = tail call i32* @opendir(i8* %0)
%13 = icmp eq i32* %12, null
br i1 %13, label %77, label %14
14: ; preds = %11
%15 = call %struct.dirent* @readdir(i32* %12)
%16 = icmp eq %struct.dirent* %15, null
br i1 %16, label %73, label %17
17: ; preds = %14
%18 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 1
%19 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
br label %20
20: ; preds = %17, %69
%21 = phi %struct.dirent* [ %15, %17 ], [ %71, %69 ]
%22 = phi i32 [ 0, %17 ], [ %70, %69 ]
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 46
br i1 %26, label %69, label %27
27: ; preds = %20
%28 = call i32 @strcpy(i8* %3, i8* %0)
%29 = call i32 @strlen(i8* %3)
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 47
br i1 %34, label %39, label %35
35: ; preds = %27
%36 = call i32 @strlen(i8* %3)
%37 = sub nsw i32 255, %36
%38 = call i32 @strncat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %35, %27
%40 = load i8*, i8** %23
%41 = call i32 @strlen(i8* %3)
%42 = sub nsw i32 255, %41
%43 = call i32 @strncat(i8* %3, i8* %40, i32 %42)
%44 = call i32 @stat(i8* %3, %struct.stat* %5)
%45 = load i32, i32* %18
%46 = call i64 @S_ISDIR(i32 %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %39
%49 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%50 = call i32 @recurs(i8* %3)
%51 = add nsw i32 %50, %22
br label %69
52: ; preds = %39
%53 = load i32, i32* %18
%54 = call i64 @S_ISREG(i32 %53)
%55 = icmp eq i64 %54, 0
br i1 %55, label %69, label %56
56: ; preds = %52
%57 = call i32 @strlen(i8* %3)
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %58
%60 = getelementptr inbounds i8, i8* %59, i64 -4
%61 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %60)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %56
%64 = load i32, i32* %19
%65 = call i64 @sidparse(i8* %3, i32 %64)
%66 = icmp eq i64 %65, 0
%67 = zext i1 %66 to i32
%68 = add nsw i32 %22, %67
br label %69
69: ; preds = %63, %48, %56, %52, %20
%70 = phi i32 [ %51, %48 ], [ %22, %56 ], [ %22, %52 ], [ %22, %20 ], [ %68, %63 ]
%71 = call %struct.dirent* @readdir(i32* %12)
%72 = icmp eq %struct.dirent* %71, null
br i1 %72, label %73, label %20
73: ; preds = %69, %14
%74 = phi i32 [ 0, %14 ], [ %70, %69 ]
%75 = call i32 @free(%struct.stat* %5)
%76 = call i32 @closedir(i32* %12)
br label %77
77: ; preds = %11, %73
%78 = phi i32 [ %74, %73 ], [ -1, %11 ]
ret i32 %78
}