#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 collectionFormat {
  int dummy;
};
typedef int /*<<< orphan*/ path_real;

/* Variables and functions */
int /*<<< orphan*/ LocalFilesRecursiveDir(
    struct collectionFormat *,
    int (*)(struct collectionFormat *, struct crawldocumentExistFormat *),
    int (*)(struct collectionFormat *, struct crawldocumentAddFormat *), char *,
    char *, int);
int /*<<< orphan*/ printf(char *, ...);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int crawlLocalFiles(
    struct collectionFormat *collection,
    int (*documentExist)(struct collectionFormat *collection,
                         struct crawldocumentExistFormat *crawldocumentExist),
    int (*documentAdd)(struct collectionFormat *collection,
                       struct crawldocumentAddFormat *crawldocumentAdd),
    char prefix[], char path[]) {
  char path_real[512];
  printf("path %s\n", path);
  strncpy(path_real, path, sizeof(path_real));
  if (path_real[strlen(path_real)] == '/') {
    printf("removed / at end\n");
    path_real[strlen(path_real)] = '\0';
  }
  printf("prefix: %s, path %s\n", prefix, path);
  LocalFilesRecursiveDir(collection, documentExist, documentAdd, prefix, path,
                         00777);
  printf("finished\n");
  return 1;
}


x86 assembly (clang, -O0):
<crawlLocalFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
lea    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
movsbl -0x230(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    11c5 <crawlLocalFiles+0x85>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x230(%rbp),%rdi
call   1040 <strlen@plt>
movb   $0x0,-0x230(%rbp,%rax,1)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    $0x1ff,%r9d
call   1060 <LocalFilesRecursiveDir@plt>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crawlLocalFiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xe95(%rip),%rdi
mov    %r8,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmpb   $0x2f,(%rsp,%rax,1)
jne    11ba <crawlLocalFiles+0x6a>
lea    0xe75(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdi
call   1050 <strlen@plt>
movb   $0x0,(%rsp,%rax,1)
lea    0xe3f(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
mov    $0x1ff,%r9d
call   1070 <LocalFilesRecursiveDir@plt>
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.collectionFormat = type { i32 }
%struct.crawldocumentExistFormat = type opaque
%struct.crawldocumentAddFormat = type opaque
%struct.crawldocumentExistFormat.0 = type opaque
%struct.crawldocumentAddFormat.1 = type opaque
@.str = [9 x i8] c"path %s\0A\00"
@.str.1 = [18 x i8] c"removed / at end\0A\00"
@.str.2 = [21 x i8] c"prefix: %s, path %s\0A\00"
@.str.3 = [10 x i8] c"finished\0A\00"
define i32 @crawlLocalFiles(%struct.collectionFormat* %0, i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat*)* %1, i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat*)* %2, i8* %3, i8* %4) {
%6 = alloca %struct.collectionFormat*
%7 = alloca i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat*)*
%8 = alloca i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat*)*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [512 x i8]
store %struct.collectionFormat* %0, %struct.collectionFormat** %6
store i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat*)* %1, i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat*)** %7
store i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat*)* %2, i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat*)** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%12 = load i8*, i8** %10
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%15 = load i8*, i8** %10
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 512)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%18 = call i64 @strlen(i8* %17)
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %28
23: ; preds = %5
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%26 = call i64 @strlen(i8* %25)
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %23, %5
%29 = load i8*, i8** %9
%30 = load i8*, i8** %10
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %30)
%32 = load %struct.collectionFormat*, %struct.collectionFormat** %6
%33 = load i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat*)*, i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat*)** %7
%34 = bitcast i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat*)* %33 to i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat.0*)*
%35 = load i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat*)*, i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat*)** %8
%36 = bitcast i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat*)* %35 to i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat.1*)*
%37 = load i8*, i8** %9
%38 = load i8*, i8** %10
%39 = call i32 @LocalFilesRecursiveDir(%struct.collectionFormat* %32, i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat.0*)* %34, i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat.1*)* %36, i8* %37, i8* %38, i32 511)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
%struct.collectionFormat = type { i32 }
%struct.crawldocumentExistFormat = type opaque
%struct.crawldocumentAddFormat = type opaque
%struct.crawldocumentExistFormat.0 = type opaque
%struct.crawldocumentAddFormat.1 = type opaque
@.str = [9 x i8] c"path %s\0A\00"
@.str.2 = [21 x i8] c"prefix: %s, path %s\0A\00"
@str = [9 x i8] c"finished\00"
@str.4 = [17 x i8] c"removed / at end\00"
define i32 @crawlLocalFiles(%struct.collectionFormat* %0, i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat*)* %1, i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat*)* %2, i8* %3, i8* %4) {
%6 = alloca [512 x i8]
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %4)
%9 = call i32 @strncpy(i8* %7, i8* %4, i32 512)
%10 = call i64 @strlen(i8* %7)
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %14, label %18
14: ; preds = %5
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
%16 = call i64 @strlen(i8* %7)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %14, %5
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %3, i8* %4)
%20 = bitcast i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat*)* %1 to i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat.0*)*
%21 = bitcast i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat*)* %2 to i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat.1*)*
%22 = call i32 @LocalFilesRecursiveDir(%struct.collectionFormat* %0, i32 (%struct.collectionFormat*, %struct.crawldocumentExistFormat.0*)* %20, i32 (%struct.collectionFormat*, %struct.crawldocumentAddFormat.1*)* %21, i8* %3, i8* %4, i32 511)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret i32 1
}