#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 {
  scalar_t__ st_size;
  int /*<<< orphan*/ st_mtime;
};
struct FTW {
  int dummy;
};

/* Variables and functions */
int FTW_D;
int FTW_F;
int /*<<< orphan*/ gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int snprintf(char *, int, char *, char *, int, char *, char const *);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int handle_nftw(const char *fpath, const struct stat *sb, int tflag,
                struct FTW *ftwbuf) {
  char mtime[128], sent[1024];
  int sentLen;
  extern int nent;
  extern int ansind;
  extern char *ans;
  strftime(mtime, 128, "%FT%T", gmtime(&sb->st_mtime));
  sentLen = snprintf(sent, 1024, "%-3s %7d %s %s\n",
                     (tflag == FTW_D)   ? "d"
                     : (tflag == FTW_F) ? "f"
                                        : "???",
                     (int)sb->st_size, mtime, fpath);
  memcpy(ans + ansind, sent, sentLen);
  ansind += sentLen;
  nent++;
  return (0);
}


x86 assembly (clang, -O0):
<handle_nftw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x4b8(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1060 <gmtime@plt>
mov    -0x4b8(%rbp),%rdi
mov    %eax,%ecx
mov    $0x80,%esi
lea    0xe76(%rip),%rdx
call   1050 <strftime@plt>
lea    -0x4a0(%rbp),%rax
mov    %rax,-0x4b0(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%eax
jne    11c2 <handle_nftw+0x82>
lea    0xe60(%rip),%rax
mov    %rax,-0x4c0(%rbp)
jmp    11e9 <handle_nftw+0xa9>
mov    -0x14(%rbp),%edx
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rax
lea    0xe3c(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x4c0(%rbp)
mov    -0x4b0(%rbp),%rdi
mov    -0x4c0(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%r8d
lea    -0xa0(%rbp),%r9
mov    -0x8(%rbp),%rax
mov    $0x400,%esi
lea    0xdee(%rip),%rdx
mov    %rax,(%rsp)
call   1030 <snprintf@plt>
mov    %eax,-0x4a4(%rbp)
mov    0x2db2(%rip),%rax
mov    (%rax),%rdi
mov    0x2db0(%rip),%rax
movslq (%rax),%rax
add    %rax,%rdi
lea    -0x4a0(%rbp),%rsi
mov    -0x4a4(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x4a4(%rbp),%ecx
mov    0x2d8b(%rip),%rax
add    (%rax),%ecx
mov    0x2d82(%rip),%rax
mov    %ecx,(%rax)
mov    0x2d61(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    0x2d55(%rip),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x4d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_nftw>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x498,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x8(%rsi),%rdi
call   1060 <gmtime@plt>
lea    0xe9b(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x80,%esi
mov    %eax,%ecx
call   1050 <strftime@plt>
mov    0x2e58(%rip),%rax
mov    0x2e41(%rip),%rcx
cmp    %ebp,(%rcx)
lea    0xe88(%rip),%rcx
lea    0xe83(%rip),%rdx
cmove  %rcx,%rdx
cmp    %ebp,(%rax)
lea    0xe72(%rip),%rcx
cmovne %rdx,%rcx
mov    (%rbx),%r8d
mov    %r15,(%rsp)
lea    0xe50(%rip),%rdx
lea    0x90(%rsp),%r15
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%r9
call   1030 <snprintf@plt>
mov    %eax,%ebp
mov    0x2e09(%rip),%rax
mov    0x2e0a(%rip),%rbx
movslq (%rbx),%rdi
add    (%rax),%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
add    %ebp,(%rbx)
mov    0x2dd9(%rip),%rax
addl   $0x1,(%rax)
xor    %eax,%eax
add    $0x498,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64, i32 }
%struct.FTW = type { i32 }
@.str = [6 x i8] c"%FT%T\00"
@.str.1 = [16 x i8] c"%-3s %7d %s %s\0A\00"
@FTW_D = global i32 0
@.str.2 = [2 x i8] c"d\00"
@FTW_F = global i32 0
@.str.3 = [2 x i8] c"f\00"
@.str.4 = [4 x i8] c"???\00"
@ans = external global i8*
@ansind = external global i32
@nent = external global i32
define i32 @handle_nftw(i8* %0, %struct.stat* %1, i32 %2, %struct.FTW* %3) {
%5 = alloca i8*
%6 = alloca %struct.stat*
%7 = alloca i32
%8 = alloca %struct.FTW*
%9 = alloca [128 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i32
store i8* %0, i8** %5
store %struct.stat* %1, %struct.stat** %6
store i32 %2, i32* %7
store %struct.FTW* %3, %struct.FTW** %8
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%13 = load %struct.stat*, %struct.stat** %6
%14 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%15 = call i32 @gmtime(i32* %14)
%16 = call i32 @strftime(i8* %12, i32 128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%18 = load i32, i32* %7
%19 = load i32, i32* @FTW_D
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %4
br label %28
22: ; preds = %4
%23 = load i32, i32* %7
%24 = load i32, i32* @FTW_F
%25 = icmp eq i32 %23, %24
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
br label %28
28: ; preds = %22, %21
%29 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %21 ], [ %27, %22 ]
%30 = load %struct.stat*, %struct.stat** %6
%31 = getelementptr inbounds %struct.stat, %struct.stat* %30, i32 0, i32 0
%32 = load i64, i64* %31
%33 = trunc i64 %32 to i32
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%35 = load i8*, i8** %5
%36 = call i32 @snprintf(i8* %17, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 %33, i8* %34, i8* %35)
store i32 %36, i32* %11
%37 = load i8*, i8** @ans
%38 = load i32, i32* @ansind
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%42 = load i32, i32* %11
%43 = call i32 @memcpy(i8* %40, i8* %41, i32 %42)
%44 = load i32, i32* %11
%45 = load i32, i32* @ansind
%46 = add nsw i32 %45, %44
store i32 %46, i32* @ansind
%47 = load i32, i32* @nent
%48 = add nsw i32 %47, 1
store i32 %48, i32* @nent
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
%struct.FTW = type { i32 }
@.str = [6 x i8] c"%FT%T\00"
@.str.1 = [16 x i8] c"%-3s %7d %s %s\0A\00"
@FTW_D = global i32 0
@.str.2 = [2 x i8] c"d\00"
@FTW_F = global i32 0
@.str.3 = [2 x i8] c"f\00"
@.str.4 = [4 x i8] c"???\00"
@ans = external global i8*
@ansind = external global i32
@nent = external global i32
define i32 @handle_nftw(i8* %0, %struct.stat* %1, i32 %2, %struct.FTW* nocapture readnone %3) {
%5 = alloca [128 x i8]
%6 = alloca [1024 x i8]
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%10 = tail call i32 @gmtime(i32* %9)
%11 = call i32 @strftime(i8* %7, i32 128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @FTW_D
%13 = icmp eq i32 %12, %2
%14 = load i32, i32* @FTW_F
%15 = icmp eq i32 %14, %2
%16 = select i1 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%17 = select i1 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %16
%18 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
%21 = call i32 @snprintf(i8* %8, i32 1024, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %17, i32 %20, i8* %7, i8* %0)
%22 = load i8*, i8** @ans
%23 = load i32, i32* @ansind
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = call i32 @memcpy(i8* %25, i8* %8, i32 %21)
%27 = load i32, i32* @ansind
%28 = add nsw i32 %27, %21
store i32 %28, i32* @ansind
%29 = load i32, i32* @nent
%30 = add nsw i32 %29, 1
store i32 %30, i32* @nent
ret i32 0
}