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

/* Variables and functions */
scalar_t__ get_line(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ system(char *);
void remove_files_maybe(char *path_filename, int number_to_queue) {
  FILE *p;
  char buffer[1024];
  char filename[1024];
  sprintf(buffer,
          "ls -dt %s* | egrep \"#[0-9][0-9]*\" | sed '1,%dd' 2>/dev/null",
          path_filename, number_to_queue);
  p = popen(buffer, "r");
  while (get_line(filename, p)) {
    sprintf(buffer, "rm -f %s 2>/dev/null", filename);
    system(buffer);
  }
  pclose(p);
}


x86 assembly (clang, -O0):
<remove_files_maybe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     11dc <remove_files_maybe+0x8c>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <system@plt>
jmp    1195 <remove_files_maybe+0x45>
mov    -0x18(%rbp),%rdi
call   1050 <pclose@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_files_maybe>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %esi,%ecx
mov    %rdi,%rdx
lea    0xe96(%rip),%rsi
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <sprintf@plt>
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdi
call   1060 <popen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    %rax,%rsi
call   1030 <get_line@plt>
test   %rax,%rax
je     11d8 <remove_files_maybe+0x88>
lea    0xe99(%rip),%r14
lea    0x400(%rsp),%r12
mov    %rsp,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %r12,%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <get_line@plt>
test   %rax,%rax
jne    11b0 <remove_files_maybe+0x60>
mov    %r15,%rdi
call   1050 <pclose@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [60 x i8] c"ls -dt %s* | egrep \22#[0-9][0-9]*\22 | sed '1,%dd' 2>/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"rm -f %s 2>/dev/null\00"
define void @remove_files_maybe(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = load i32, i32* %4
%11 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %8, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = call i32* @popen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %5
br label %14
14: ; preds = %19, %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i64 @get_line(i8* %15, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = call i32 @system(i8* %23)
br label %14
25: ; preds = %14
%26 = load i32*, i32** %5
%27 = call i32 @pclose(i32* %26)
ret void
}

LLVM IR (-O2):
@.str = [60 x i8] c"ls -dt %s* | egrep \22#[0-9][0-9]*\22 | sed '1,%dd' 2>/dev/null\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"rm -f %s 2>/dev/null\00"
define void @remove_files_maybe(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%8 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i64 @get_line(i8* %6, i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %2, %11
%12 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%13 = call i32 @system(i8* %5)
%14 = call i64 @get_line(i8* %6, i32* %8)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %11
16: ; preds = %11, %2
%17 = call i32 @pclose(i32* %8)
ret void
}