#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;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
void dir_motion_files_move(char *path_trg) {
  struct dirent *entry;
  DIR *dir;
  char *path_src = "/home/pi/motion/";
  char fullpath[80];
  char buf[160];
  struct stat sb;
  if (strlen(path_trg) < 5)
    return;
  dir = opendir(path_src);
  while ((entry = readdir(dir)) != NULL) {
    if (strlen(entry->d_name) > 5) {
      strcpy(fullpath, path_src);
      strcat(fullpath, entry->d_name);
      stat(fullpath, &sb);
      if ((int)sb.st_size > 0) {
        sprintf(buf, "mv %s %s", fullpath, path_trg);
        system(buf);
      };
    }
  }
  closedir(dir);
}


x86 assembly (clang, -O0):
<dir_motion_files_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe5a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x5,%eax
jge    11c1 <dir_motion_files_move+0x31>
jmp    1271 <dir_motion_files_move+0xe1>
mov    -0x20(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1268 <dir_motion_files_move+0xd8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x5,%eax
jle    1263 <dir_motion_files_move+0xd3>
lea    -0x70(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   10a0 <strcat@plt>
lea    -0x70(%rbp),%rdi
lea    -0x118(%rbp),%rsi
call   1080 <stat@plt>
mov    -0x118(%rbp),%rax
cmp    $0x0,%eax
jle    125e <dir_motion_files_move+0xce>
lea    -0x110(%rbp),%rdi
lea    -0x70(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xdc4(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1060 <system@plt>
jmp    1263 <dir_motion_files_move+0xd3>
jmp    11ce <dir_motion_files_move+0x3e>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_motion_files_move>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
call   1050 <strlen@plt>
cmp    $0x5,%eax
jl     1260 <dir_motion_files_move+0xd0>
lea    0xe47(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     1258 <dir_motion_files_move+0xc8>
mov    %rax,%r15
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0x60(%rsp),%rbp
jmp    1200 <dir_motion_files_move+0x70>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     1258 <dir_motion_files_move+0xc8>
mov    (%r15),%rdi
call   1050 <strlen@plt>
cmp    $0x6,%eax
jl     11f0 <dir_motion_files_move+0x60>
mov    %r12,%rdi
lea    0xde9(%rip),%rsi
call   1030 <strcpy@plt>
mov    (%r15),%rsi
mov    %r12,%rdi
call   10a0 <strcat@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <stat@plt>
cmpl   $0x0,0x8(%rsp)
jle    11f0 <dir_motion_files_move+0x60>
mov    %rbp,%rdi
lea    0xdce(%rip),%rsi
mov    %r12,%rdx
mov    %r14,%rcx
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <system@plt>
jmp    11f0 <dir_motion_files_move+0x60>
mov    %rbx,%rdi
call   1070 <closedir@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i64 }
@.str = [17 x i8] c"/home/pi/motion/\00"
@.str.1 = [9 x i8] c"mv %s %s\00"
define void @dir_motion_files_move(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.dirent*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [80 x i8]
%7 = alloca [160 x i8]
%8 = alloca %struct.stat
store i8* %0, i8** %2
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %5
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %10, 5
br i1 %11, label %12, label %13
12: ; preds = %1
br label %53
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = call i32* @opendir(i8* %14)
store i32* %15, i32** %4
br label %16
16: ; preds = %49, %13
%17 = load i32*, i32** %4
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %3
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %50
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %3
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = icmp sgt i32 %24, 5
br i1 %25, label %26, label %49
26: ; preds = %20
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%28 = load i8*, i8** %5
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%31 = load %struct.dirent*, %struct.dirent** %3
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @strcat(i8* %30, i8* %33)
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%36 = call i32 @stat(i8* %35, %struct.stat* %8)
%37 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%38 = load i64, i64* %37
%39 = trunc i64 %38 to i32
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %26
%42 = getelementptr inbounds [160 x i8], [160 x i8]* %7, i64 0, i64 0
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%44 = load i8*, i8** %2
%45 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %43, i8* %44)
%46 = getelementptr inbounds [160 x i8], [160 x i8]* %7, i64 0, i64 0
%47 = call i32 @system(i8* %46)
br label %48
48: ; preds = %41, %26
br label %49
49: ; preds = %48, %20
br label %16
50: ; preds = %16
%51 = load i32*, i32** %4
%52 = call i32 @closedir(i32* %51)
br label %53
53: ; preds = %50, %12
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.dirent = type { i8* }
@.str = [17 x i8] c"/home/pi/motion/\00"
@.str.1 = [9 x i8] c"mv %s %s\00"
define void @dir_motion_files_move(i8* %0) {
%2 = alloca [80 x i8]
%3 = alloca [160 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [160 x i8], [160 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.stat* %4 to i8*
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp slt i32 %8, 5
br i1 %9, label %38, label %10
10: ; preds = %1
%11 = tail call i32* @opendir(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%12 = call %struct.dirent* @readdir(i32* %11)
%13 = icmp eq %struct.dirent* %12, null
br i1 %13, label %36, label %14
14: ; preds = %10
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %16
16: ; preds = %14, %33
%17 = phi %struct.dirent* [ %12, %14 ], [ %34, %33 ]
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
%21 = icmp sgt i32 %20, 5
br i1 %21, label %22, label %33
22: ; preds = %16
%23 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%24 = load i8*, i8** %18
%25 = call i32 @strcat(i8* %5, i8* %24)
%26 = call i32 @stat(i8* %5, %struct.stat* %4)
%27 = load i64, i64* %15
%28 = trunc i64 %27 to i32
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %0)
%32 = call i32 @system(i8* %6)
br label %33
33: ; preds = %22, %30, %16
%34 = call %struct.dirent* @readdir(i32* %11)
%35 = icmp eq %struct.dirent* %34, null
br i1 %35, label %36, label %16
36: ; preds = %33, %10
%37 = call i32 @closedir(i32* %11)
br label %38
38: ; preds = %1, %36
ret void
}