#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*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ copyFile(char *, char *);
char *getFullFileName(char *, int /*<<< orphan*/);
scalar_t__ isValidFile(int /*<<< orphan*/);
struct dirent *readdir(int /*<<< orphan*/ *);
char *strcat(char *, char *);
int /*<<< orphan*/ updateBackupTimes(char *, char *);
void processDirectory(DIR *sourceDir, char *source, char *dest) {
  struct dirent *pDirent;
  while ((pDirent = readdir(sourceDir)) != NULL) {
    char *sourceFile = getFullFileName(source, pDirent->d_name);
    char *destFile = strcat(getFullFileName(dest, pDirent->d_name), ".bak");
    if (isValidFile(pDirent->d_name)) {
      copyFile(sourceFile, destFile);
      updateBackupTimes(sourceFile, destFile);
    }
  }
}


x86 assembly (clang, -O0):
<processDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f4 <processDirectory+0x94>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1080 <getFullFileName@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1080 <getFullFileName@plt>
mov    %rax,%rdi
lea    0xe49(%rip),%rsi
call   1070 <strcat@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1030 <isValidFile@plt>
cmp    $0x0,%rax
je     11ef <processDirectory+0x8f>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <copyFile@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1050 <updateBackupTimes@plt>
jmp    1174 <processDirectory+0x14>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processDirectory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1050 <readdir@plt>
test   %rax,%rax
je     11f3 <processDirectory+0x93>
mov    %rax,%rbx
jmp    11a0 <processDirectory+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   1050 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11f3 <processDirectory+0x93>
mov    (%rbx),%esi
mov    %r15,%rdi
call   1080 <getFullFileName@plt>
mov    %rax,%r13
mov    (%rbx),%esi
mov    %r14,%rdi
call   1080 <getFullFileName@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <strlen@plt>
movl   $0x6b61622e,0x0(%rbp,%rax,1)
6b
movb   $0x0,0x4(%rbp,%rax,1)
mov    (%rbx),%edi
call   1030 <isValidFile@plt>
test   %rax,%rax
je     1190 <processDirectory+0x30>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <copyFile@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <updateBackupTimes@plt>
jmp    1190 <processDirectory+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [5 x i8] c".bak\00"
define void @processDirectory(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.dirent*
%8 = alloca i8*
%9 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
br label %10
10: ; preds = %38, %3
%11 = load i32*, i32** %4
%12 = call %struct.dirent* @readdir(i32* %11)
store %struct.dirent* %12, %struct.dirent** %7
%13 = icmp ne %struct.dirent* %12, null
br i1 %13, label %14, label %39
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = load %struct.dirent*, %struct.dirent** %7
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i8* @getFullFileName(i8* %15, i32 %18)
store i8* %19, i8** %8
%20 = load i8*, i8** %6
%21 = load %struct.dirent*, %struct.dirent** %7
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i8* @getFullFileName(i8* %20, i32 %23)
%25 = call i8* @strcat(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %9
%26 = load %struct.dirent*, %struct.dirent** %7
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i64 @isValidFile(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %14
%32 = load i8*, i8** %8
%33 = load i8*, i8** %9
%34 = call i32 @copyFile(i8* %32, i8* %33)
%35 = load i8*, i8** %8
%36 = load i8*, i8** %9
%37 = call i32 @updateBackupTimes(i8* %35, i8* %36)
br label %38
38: ; preds = %31, %14
br label %10
39: ; preds = %10
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [5 x i8] c".bak\00"
define void @processDirectory(i32* %0, i8* %1, i8* %2) {
%4 = tail call %struct.dirent* @readdir(i32* %0)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %24, label %6
6: ; preds = %3, %21
%7 = phi %struct.dirent* [ %22, %21 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i8* @getFullFileName(i8* %1, i32 %9)
%11 = load i32, i32* %8
%12 = tail call i8* @getFullFileName(i8* %2, i32 %11)
%13 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%14 = getelementptr i8, i8* %12, i64 %13
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %14, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5, i1 false)
%15 = load i32, i32* %8
%16 = tail call i64 @isValidFile(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %6
%19 = tail call i32 @copyFile(i8* %10, i8* %12)
%20 = tail call i32 @updateBackupTimes(i8* %10, i8* %12)
br label %21
21: ; preds = %18, %6
%22 = tail call %struct.dirent* @readdir(i32* %0)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %24, label %6
24: ; preds = %21, %3
ret void
}