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

/* Variables and functions */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
void directory_buster(char *host, char **db_paths) {
  FILE *cur_fh = NULL;
  char *cur_url = NULL, *tmp = NULL;
  int idx = 0;
  cur_url = (char *)calloc(sizeof(char), 2048);
  while (db_paths[idx] != NULL) {
    cur_fh = fopen(db_paths[idx], "r");
    if (!cur_fh) {
      printf("[!] could not open database path: %s\n", db_paths[idx]);
      continue;
    }
    while (1) {
      tmp = fgets(cur_url, 2048, cur_fh);
      if (!tmp || feof(cur_fh)) {
        break;
      }
    }
    fclose(cur_fh);
    idx++;
  }
  free(cur_url);
}


x86 assembly (clang, -O0):
<directory_buster>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x1,%edi
mov    $0x800,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1263 <directory_buster+0xf3>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe28(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1209 <directory_buster+0x99>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
jmp    11b2 <directory_buster+0x42>
jmp    120e <directory_buster+0x9e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1242 <directory_buster+0xd2>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     1247 <directory_buster+0xd7>
jmp    124c <directory_buster+0xdc>
jmp    120e <directory_buster+0x9e>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b2 <directory_buster+0x42>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<directory_buster>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    $0x1,%edi
mov    $0x800,%esi
call   1070 <calloc@plt>
mov    %rax,%r13
mov    %rbx,(%rsp)
mov    (%rbx),%rdi
test   %rdi,%rdi
je     1234 <directory_buster+0xc4>
xor    %ebp,%ebp
lea    0xe57(%rip),%r15
lea    0xe52(%rip),%r12
mov    (%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    11e2 <directory_buster+0x72>
mov    (%r14),%rsi
mov    %r12,%rdi
call   1050 <printf@plt>
mov    (%r14),%rdi
test   %rdi,%rdi
jne    11c0 <directory_buster+0x50>
jmp    1234 <directory_buster+0xc4>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    $0x800,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1212 <directory_buster+0xa2>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
je     11f0 <directory_buster+0x80>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rax
lea    (%rax,%rbp,8),%r14
add    $0x8,%r14
mov    0x8(%rax,%rbp,8),%rdi
add    $0x1,%rbp
test   %rdi,%rdi
jne    11c0 <directory_buster+0x50>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [38 x i8] c"[!] could not open database path: %s\0A\00"
define void @directory_buster(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32* null, i32** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i32 0, i32* %8
%9 = call i64 @calloc(i32 1, i32 2048)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
br label %11
11: ; preds = %47, %27, %2
%12 = load i8**, i8*** %4
%13 = load i32, i32* %8
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %12, i64 %14
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %52
18: ; preds = %11
%19 = load i8**, i8*** %4
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %5
%25 = load i32*, i32** %5
%26 = icmp ne i32* %25, null
br i1 %26, label %34, label %27
27: ; preds = %18
%28 = load i8**, i8*** %4
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %11
34: ; preds = %18
br label %35
35: ; preds = %34, %46
%36 = load i8*, i8** %6
%37 = load i32*, i32** %5
%38 = call i8* @fgets(i8* %36, i32 2048, i32* %37)
store i8* %38, i8** %7
%39 = load i8*, i8** %7
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = load i32*, i32** %5
%43 = call i64 @feof(i32* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41, %35
br label %47
46: ; preds = %41
br label %35
47: ; preds = %45
%48 = load i32*, i32** %5
%49 = call i32 @fclose(i32* %48)
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %11
52: ; preds = %11
%53 = load i8*, i8** %6
%54 = call i32 @free(i8* %53)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [38 x i8] c"[!] could not open database path: %s\0A\00"
define void @directory_buster(i8* nocapture readnone %0, i8** nocapture %1) {
%3 = tail call i64 @calloc(i32 1, i32 2048)
%4 = inttoptr i64 %3 to i8*
%5 = load i8*, i8** %1
%6 = icmp eq i8* %5, null
br i1 %6, label %32, label %7
7: ; preds = %2, %26
%8 = phi i64 [ %28, %26 ], [ 0, %2 ]
%9 = phi i8* [ %30, %26 ], [ %5, %2 ]
%10 = phi i8** [ %29, %26 ], [ %1, %2 ]
br label %11
11: ; preds = %7, %15
%12 = phi i8* [ %9, %7 ], [ %18, %15 ]
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8*, i8** %10
%17 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %10
%19 = icmp eq i8* %18, null
br i1 %19, label %32, label %11
20: ; preds = %11, %23
%21 = tail call i8* @fgets(i8* %4, i32 2048, i32* %13)
%22 = icmp eq i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i64 @feof(i32* %13)
%25 = icmp eq i64 %24, 0
br i1 %25, label %20, label %26
26: ; preds = %20, %23
%27 = tail call i32 @fclose(i32* %13)
%28 = add nuw i64 %8, 1
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %7
32: ; preds = %26, %15, %2
%33 = tail call i32 @free(i8* %4)
ret void
}