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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ fill_tac_pool_from_file(char **, char *, char *,
                                   int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
char **malloc(int);
int /*<<< orphan*/ memset(char **, char, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
char *strstr(int /*<<< orphan*/, char *);
unsigned int fill_tac_pool(char ***pool, char *vendor, char *model) {
  if (vendor == NULL && model == NULL)
    return 0;
  *pool = malloc(100 * sizeof(char *));
  memset(*pool, '\xa5', 100 * sizeof(char *));
  (*pool)[100 - 1] = (char *)-1;
  unsigned int ret = 0;
  DIR *d;
  struct dirent *dir;
  d = opendir(".");
  if (d) {
    while ((dir = readdir(d)) != NULL) {
      char *needleptr = NULL;
      if ((needleptr = strstr(dir->d_name, ".tac.csv")) == NULL) {
        continue;
      }
      if (*(needleptr + sizeof(".tac.csv") - 1) != '\0') {
        continue;
      }
      FILE *tacfile = fopen(dir->d_name, "r");
      if (tacfile == NULL) {
        perror("fopen");
        continue;
      }
      ret += fill_tac_pool_from_file(*pool + ret, vendor, model, tacfile);
      if (ret == 100)
        break;
    }
    closedir(d);
  }
  return ret;
}


x86 assembly (clang, -O0):
<fill_tac_pool>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <fill_tac_pool+0x36>
cmpq   $0x0,-0x20(%rbp)
jne    11c6 <fill_tac_pool+0x36>
movl   $0x0,-0x4(%rbp)
jmp    1309 <fill_tac_pool+0x179>
mov    $0x320,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0xffffffa5,%esi
mov    $0x320,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    $0xffffffffffffffff,%rcx
mov    %rcx,0x318(%rax)
movl   $0x0,-0x24(%rbp)
lea    0xded(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1303 <fill_tac_pool+0x173>
jmp    122c <fill_tac_pool+0x9c>
mov    -0x30(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     12fa <fill_tac_pool+0x16a>
movq   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1270 <fill_tac_pool+0xe0>
jmp    122c <fill_tac_pool+0x9c>
mov    -0x40(%rbp),%rax
movsbl 0x8(%rax),%eax
cmp    $0x0,%eax
je     1286 <fill_tac_pool+0xf6>
jmp    122c <fill_tac_pool+0x9c>
mov    -0x38(%rbp),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12b8 <fill_tac_pool+0x128>
lea    0xd5f(%rip),%rdi
call   10a0 <perror@plt>
jmp    122c <fill_tac_pool+0x9c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x24(%rbp),%eax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x48(%rbp),%rcx
call   1060 <fill_tac_pool_from_file@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jne    12f5 <fill_tac_pool+0x165>
jmp    12fa <fill_tac_pool+0x16a>
jmp    122c <fill_tac_pool+0x9c>
mov    -0x30(%rbp),%rdi
call   1050 <closedir@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_tac_pool>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
mov    %rsi,%rax
or     %rdx,%rax
je     1299 <fill_tac_pool+0x109>
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x320,%edi
call   1080 <malloc@plt>
mov    %rax,(%r12)
mov    %rax,%rdi
mov    $0xffffffa5,%esi
mov    $0x320,%edx
call   1040 <memset@plt>
mov    (%r12),%rax
movq   $0xffffffffffffffff,0x318(%rax)
ff ff ff ff
lea    0xe18(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1299 <fill_tac_pool+0x109>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1218 <fill_tac_pool+0x88>
mov    %rax,%r14
mov    %rbp,(%rsp)
xor    %ebx,%ebx
lea    0xdec(%rip),%rbp
jmp    1240 <fill_tac_pool+0xb0>
xor    %ebx,%ebx
jmp    1291 <fill_tac_pool+0x101>
lea    0xdea(%rip),%rdi
call   10a0 <perror@plt>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1070 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     1291 <fill_tac_pool+0x101>
mov    (%r14),%edi
mov    %rbp,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     1230 <fill_tac_pool+0xa0>
cmpb   $0x0,0x8(%rax)
jne    1230 <fill_tac_pool+0xa0>
mov    (%r14),%edi
lea    0xdab(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     121c <fill_tac_pool+0x8c>
mov    %ebx,%edi
shl    $0x3,%rdi
add    (%r12),%rdi
mov    %r15,%rsi
mov    (%rsp),%rdx
mov    %rax,%rcx
call   1060 <fill_tac_pool_from_file@plt>
add    %ebx,%eax
mov    %eax,%ebx
cmp    $0x64,%eax
jne    1230 <fill_tac_pool+0xa0>
mov    $0x64,%ebx
mov    %r13,%rdi
call   1050 <closedir@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [9 x i8] c".tac.csv\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"fopen\00"
define i32 @fill_tac_pool(i8*** %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8***
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca %struct.dirent*
%11 = alloca i8*
%12 = alloca i32*
store i8*** %0, i8**** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i8*, i8** %7
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 0, i32* %4
br label %83
19: ; preds = %15, %3
%20 = call i8** @malloc(i32 800)
%21 = load i8***, i8**** %5
store i8** %20, i8*** %21
%22 = load i8***, i8**** %5
%23 = load i8**, i8*** %22
%24 = call i32 @memset(i8** %23, i8 signext -91, i32 800)
%25 = load i8***, i8**** %5
%26 = load i8**, i8*** %25
%27 = getelementptr inbounds i8*, i8** %26, i64 99
store i8* inttoptr (i64 -1 to i8*), i8** %27
store i32 0, i32* %8
%28 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %28, i32** %9
%29 = load i32*, i32** %9
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %81
31: ; preds = %19
br label %32
32: ; preds = %77, %58, %50, %42, %31
%33 = load i32*, i32** %9
%34 = call %struct.dirent* @readdir(i32* %33)
store %struct.dirent* %34, %struct.dirent** %10
%35 = icmp ne %struct.dirent* %34, null
br i1 %35, label %36, label %78
36: ; preds = %32
store i8* null, i8** %11
%37 = load %struct.dirent*, %struct.dirent** %10
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i8* @strstr(i32 %39, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i8* %40, i8** %11
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %43
42: ; preds = %36
br label %32
43: ; preds = %36
%44 = load i8*, i8** %11
%45 = getelementptr inbounds i8, i8* %44, i64 9
%46 = getelementptr inbounds i8, i8* %45, i64 -1
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %43
br label %32
51: ; preds = %43
%52 = load %struct.dirent*, %struct.dirent** %10
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i32* @fopen(i32 %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %55, i32** %12
%56 = load i32*, i32** %12
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %60
58: ; preds = %51
%59 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %32
60: ; preds = %51
%61 = load i8***, i8**** %5
%62 = load i8**, i8*** %61
%63 = load i32, i32* %8
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
%66 = load i8*, i8** %6
%67 = load i8*, i8** %7
%68 = load i32*, i32** %12
%69 = call i64 @fill_tac_pool_from_file(i8** %65, i8* %66, i8* %67, i32* %68)
%70 = load i32, i32* %8
%71 = zext i32 %70 to i64
%72 = add nsw i64 %71, %69
%73 = trunc i64 %72 to i32
store i32 %73, i32* %8
%74 = load i32, i32* %8
%75 = icmp eq i32 %74, 100
br i1 %75, label %76, label %77
76: ; preds = %60
br label %78
77: ; preds = %60
br label %32
78: ; preds = %76, %32
%79 = load i32*, i32** %9
%80 = call i32 @closedir(i32* %79)
br label %81
81: ; preds = %78, %19
%82 = load i32, i32* %8
store i32 %82, i32* %4
br label %83
83: ; preds = %81, %18
%84 = load i32, i32* %4
ret i32 %84
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [9 x i8] c".tac.csv\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"fopen\00"
define i32 @fill_tac_pool(i8*** nocapture %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %1, null
%5 = icmp eq i8* %2, null
%6 = and i1 %4, %5
br i1 %6, label %49, label %7
7: ; preds = %3
%8 = tail call i8** @malloc(i32 800)
store i8** %8, i8*** %0
%9 = tail call i32 @memset(i8** %8, i8 signext -91, i32 800)
%10 = load i8**, i8*** %0
%11 = getelementptr inbounds i8*, i8** %10, i64 99
store i8* inttoptr (i64 -1 to i8*), i8** %11
%12 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %49, label %14
14: ; preds = %7
%15 = tail call %struct.dirent* @readdir(i32* %12)
%16 = icmp eq %struct.dirent* %15, null
br i1 %16, label %46, label %17
17: ; preds = %14, %42
%18 = phi %struct.dirent* [ %44, %42 ], [ %15, %14 ]
%19 = phi i32 [ %43, %42 ], [ 0, %14 ]
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i64 0, i32 0
%21 = load i32, i32* %20
%22 = tail call i8* @strstr(i32 %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %42, label %24
24: ; preds = %17
%25 = getelementptr inbounds i8, i8* %22, i64 8
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %42
28: ; preds = %24
%29 = load i32, i32* %20
%30 = tail call i32* @fopen(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %42
34: ; preds = %28
%35 = load i8**, i8*** %0
%36 = zext i32 %19 to i64
%37 = getelementptr inbounds i8*, i8** %35, i64 %36
%38 = tail call i64 @fill_tac_pool_from_file(i8** %37, i8* %1, i8* %2, i32* %30)
%39 = trunc i64 %38 to i32
%40 = add i32 %19, %39
%41 = icmp eq i32 %40, 100
br i1 %41, label %46, label %42
42: ; preds = %34, %32, %24, %17
%43 = phi i32 [ %19, %17 ], [ %19, %24 ], [ %19, %32 ], [ %40, %34 ]
%44 = tail call %struct.dirent* @readdir(i32* %12)
%45 = icmp eq %struct.dirent* %44, null
br i1 %45, label %46, label %17
46: ; preds = %42, %34, %14
%47 = phi i32 [ 0, %14 ], [ %43, %42 ], [ 100, %34 ]
%48 = tail call i32 @closedir(i32* %12)
br label %49
49: ; preds = %7, %46, %3
%50 = phi i32 [ 0, %3 ], [ %47, %46 ], [ 0, %7 ]
ret i32 %50
}