#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 st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, int);
int strlen(char const *);
char const *strstr(char const *, char *);
int ftw_callback(const char *fpath, const struct stat *sb, int typeflag) {
  int mode = sb->st_mode;
  if (strstr(fpath, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/CodethinkLabs/"
                    "endian-tests/refs/heads/master/test-src/callback.c") ==
      fpath + strlen(fpath) -
          strlen("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/CodethinkLabs/endian-tests/"
                 "refs/heads/master/test-src/callback.c")) {
    printf("ftw_callback: path = %s mode=%o\n",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/CodethinkLabs/endian-tests/refs/heads/"
           "master/test-src/callback.c",
           mode);
  }
  return 0;
}


x86 assembly (clang, -O0):
<ftw_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
lea    0xe78(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rcx
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq %edx,%rsi
xor    %edx,%edx
sub    %rsi,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jne    11c1 <ftw_callback+0x91>
mov    -0x18(%rbp),%edx
lea    0xee6(%rip),%rdi
lea    0xe44(%rip),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftw_callback>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    (%rsi),%r14d
lea    0xebb(%rip),%r15
mov    %r15,%rsi
call   1050 <strstr@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbp
add    %rbx,%rbp
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
sub    %rax,%rbp
cmp    %rbp,%r12
jne    1186 <ftw_callback+0x56>
lea    0xf24(%rip),%rdi
lea    0xe82(%rip),%rsi
mov    %r14d,%edx
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [155 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/CodethinkLabs/endian-tests/refs/heads/master/test-src/callback.c\00"
@.str.1 = [33 x i8] c"ftw_callback: path = %s mode=%o\0A\00"
define i32 @ftw_callback(i8* %0, %struct.stat* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca %struct.stat*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store %struct.stat* %1, %struct.stat** %5
store i32 %2, i32* %6
%8 = load %struct.stat*, %struct.stat** %5
%9 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%10 = load i32, i32* %9
store i32 %10, i32* %7
%11 = load i8*, i8** %4
%12 = call i8* @strstr(i8* %11, i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %4
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = call i32 @strlen(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0))
%19 = sext i32 %18 to i64
%20 = sub i64 0, %19
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = icmp eq i8* %12, %21
br i1 %22, label %23, label %26
23: ; preds = %3
%24 = load i32, i32* %7
%25 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23, %3
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [155 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/CodethinkLabs/endian-tests/refs/heads/master/test-src/callback.c\00"
@.str.1 = [33 x i8] c"ftw_callback: path = %s mode=%o\0A\00"
define i32 @ftw_callback(i8* %0, %struct.stat* nocapture %1, i32 %2) {
%4 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @strlen(i8* %0)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0))
%11 = sext i32 %10 to i64
%12 = sub nsw i64 0, %11
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = icmp eq i8* %6, %13
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %17
17: ; preds = %15, %3
ret i32 0
}