#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 */
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int system(char *);
int delete_oldest_file(void) {
  FILE *ps;
  char buf[32] = {0};
  char del_cmd[64] = {0};
  if ((ps = popen("cd /home/pi/rec/ | find -type f -printf '%T+ %p\n' | sort | "
                  "head -1 | awk '{print $2}'",
                  "r")) == NULL)
    return 1;
  fgets(buf, sizeof(buf), ps);
  pclose(ps);
  sprintf(del_cmd, "rm %s", buf);
  return system(del_cmd);
}


x86 assembly (clang, -O0):
<delete_oldest_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
lea    0xe71(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b5 <delete_oldest_file+0x55>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <delete_oldest_file+0x90>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x20,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
lea    -0x70(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe79(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_oldest_file>:
push   %r14
push   %rbx
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0xe82(%rip),%rdi
lea    0xed1(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11ce <delete_oldest_file+0x7e>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x20,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1040 <pclose@plt>
lea    0xea4(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
jmp    11d3 <delete_oldest_file+0x83>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [86 x i8] c"cd /home/pi/rec/ | find -type f -printf '%T+ %p\0A' | sort | head -1 | awk '{print $2}'\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"rm %s\00"
define i32 @delete_oldest_file() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [32 x i8]
%4 = alloca [64 x i8]
%5 = bitcast [32 x i8]* %3 to i8*
%6 = bitcast [64 x i8]* %4 to i8*
%7 = call i32* @popen(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 1, i32* %1
br label %21
10: ; preds = %0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %2
%13 = call i32 @fgets(i8* %11, i32 32, i32* %12)
%14 = load i32*, i32** %2
%15 = call i32 @pclose(i32* %14)
%16 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%20 = call i32 @system(i8* %19)
store i32 %20, i32* %1
br label %21
21: ; preds = %10, %9
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [86 x i8] c"cd /home/pi/rec/ | find -type f -printf '%T+ %p\0A' | sort | head -1 | awk '{print $2}'\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"rm %s\00"
define i32 @delete_oldest_file() {
%1 = alloca [32 x i8]
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @popen(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %12, label %7
7: ; preds = %0
%8 = call i32 @fgets(i8* %3, i32 32, i32* %5)
%9 = call i32 @pclose(i32* %5)
%10 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%11 = call i32 @system(i8* %4)
br label %12
12: ; preds = %0, %7
%13 = phi i32 [ %11, %7 ], [ 1, %0 ]
ret i32 %13
}