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

/* Variables and functions */
int /*<<< orphan*/ abortx(char *, int /*<<< orphan*/, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ stat(int /*<<< orphan*/, struct stat *);
int /*<<< orphan*/ strncmp(int /*<<< orphan*/, char *, int);
scalar_t__ unlink(int /*<<< orphan*/);
void delete_files(void) {
  DIR *dirp;
  struct dirent *entp;
  struct stat stat_buffer;
  dirp = opendir(".");
  for (entp = readdir(dirp); entp; entp = readdir(dirp))
    if (!strncmp(entp->d_name, "apt", 3)) {
      if (stat(entp->d_name, &stat_buffer))
        abortx("stat() failed for \"%s\", errno = %d", entp->d_name, errno);
      if (stat_buffer.st_size != 23)
        abortx("wrong file size for \"%s\"", entp->d_name);
      if (unlink(entp->d_name))
        abortx("unlink failed for \"%s\"", entp->d_name);
    }
}


x86 assembly (clang, -O0):
<delete_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1249 <delete_files+0xe9>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1232 <delete_files+0xd2>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
je     11e6 <delete_files+0x86>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1080 <abortx@plt>
cmpl   $0x17,-0x18(%rbp)
je     1204 <delete_files+0xa4>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1080 <abortx@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     122d <delete_files+0xcd>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1080 <abortx@plt>
jmp    1232 <delete_files+0xd2>
jmp    1237 <delete_files+0xd7>
mov    -0x8(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x10(%rbp)
jmp    1185 <delete_files+0x25>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     122c <delete_files+0xcc>
mov    %rax,%rbp
lea    0xe6d(%rip),%r14
mov    %rsp,%r15
mov    0x2e41(%rip),%r12
lea    0xe60(%rip),%r13
jmp    11c0 <delete_files+0x60>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     122c <delete_files+0xcc>
mov    0x0(%rbp),%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    11b0 <delete_files+0x50>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
call   1060 <stat@plt>
test   %rax,%rax
je     11f5 <delete_files+0x95>
mov    0x0(%rbp),%esi
mov    (%r12),%edx
mov    %r13,%rdi
xor    %eax,%eax
call   1080 <abortx@plt>
cmpl   $0x17,(%rsp)
je     120c <delete_files+0xac>
mov    0x0(%rbp),%esi
lea    0xe24(%rip),%rdi
xor    %eax,%eax
call   1080 <abortx@plt>
mov    0x0(%rbp),%edi
call   1030 <unlink@plt>
test   %rax,%rax
je     11b0 <delete_files+0x50>
mov    0x0(%rbp),%esi
lea    0xe1f(%rip),%rdi
xor    %eax,%eax
call   1080 <abortx@plt>
jmp    11b0 <delete_files+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
%struct.stat = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [4 x i8] c"apt\00"
@.str.2 = [35 x i8] c"stat() failed for \22%s\22, errno = %d\00"
@errno = global i32 0
@.str.3 = [25 x i8] c"wrong file size for \22%s\22\00"
@.str.4 = [23 x i8] c"unlink failed for \22%s\22\00"
define void @delete_files() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = alloca %struct.stat
%4 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = call %struct.dirent* @readdir(i32* %5)
store %struct.dirent* %6, %struct.dirent** %2
br label %7
7: ; preds = %50, %0
%8 = load %struct.dirent*, %struct.dirent** %2
%9 = icmp ne %struct.dirent* %8, null
br i1 %9, label %10, label %53
10: ; preds = %7
%11 = load %struct.dirent*, %struct.dirent** %2
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @strncmp(i32 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%15 = icmp ne i32 %14, 0
br i1 %15, label %49, label %16
16: ; preds = %10
%17 = load %struct.dirent*, %struct.dirent** %2
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @stat(i32 %19, %struct.stat* %3)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load %struct.dirent*, %struct.dirent** %2
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = load i32, i32* @errno
%27 = call i32 (i8*, i32, ...) @abortx(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %26)
br label %28
28: ; preds = %22, %16
%29 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%30 = load i32, i32* %29
%31 = icmp ne i32 %30, 23
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load %struct.dirent*, %struct.dirent** %2
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i32 (i8*, i32, ...) @abortx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %32, %28
%38 = load %struct.dirent*, %struct.dirent** %2
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @unlink(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = load %struct.dirent*, %struct.dirent** %2
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 (i8*, i32, ...) @abortx(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %43, %37
br label %49
49: ; preds = %48, %10
br label %50
50: ; preds = %49
%51 = load i32*, i32** %1
%52 = call %struct.dirent* @readdir(i32* %51)
store %struct.dirent* %52, %struct.dirent** %2
br label %7
53: ; preds = %7
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [4 x i8] c"apt\00"
@.str.2 = [35 x i8] c"stat() failed for \22%s\22, errno = %d\00"
@errno = global i32 0
@.str.3 = [25 x i8] c"wrong file size for \22%s\22\00"
@.str.4 = [23 x i8] c"unlink failed for \22%s\22\00"
define void @delete_files() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call %struct.dirent* @readdir(i32* %3)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %38, label %6
6: ; preds = %0
%7 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
br label %8
8: ; preds = %6, %35
%9 = phi %struct.dirent* [ %4, %6 ], [ %36, %35 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @strncmp(i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %35
14: ; preds = %8
%15 = load i32, i32* %10
%16 = call i64 @stat(i32 %15, %struct.stat* %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i32, i32* %10
%20 = load i32, i32* @errno
%21 = call i32 (i8*, i32, ...) @abortx(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %20)
br label %22
22: ; preds = %18, %14
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 23
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %10
%27 = call i32 (i8*, i32, ...) @abortx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %10
%30 = call i64 @unlink(i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = load i32, i32* %10
%34 = call i32 (i8*, i32, ...) @abortx(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %8, %32, %28
%36 = call %struct.dirent* @readdir(i32* %3)
%37 = icmp eq %struct.dirent* %36, null
br i1 %37, label %38, label %8
38: ; preds = %35, %0
ret void
}