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

/* Variables and functions */
struct dirent *readdir(int /*<<< orphan*/ *const);
int /*<<< orphan*/ strcmp(char *, char const *const);
int strspn(char *, char *);
char *scan_for(DIR *const rcdir, const char *const script, const char type) {
  struct dirent *d;
  char *ret = (char *)0;
  while ((d = readdir(rcdir)) != (struct dirent *)0) {
    char *ptr = d->d_name;
    if (*ptr != type)
      continue;
    ptr++;
    if (strspn(ptr, "0123456789") < 2)
      continue;
    ptr += 2;
    if (!strcmp(ptr, script)) {
      ret = d->d_name;
      break;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<scan_for>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11e8 <scan_for+0xb8>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     1187 <scan_for+0x57>
jmp    114d <scan_for+0x1d>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1030 <strspn@plt>
cmp    $0x2,%eax
jge    11b1 <scan_for+0x81>
jmp    114d <scan_for+0x1d>
mov    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11e3 <scan_for+0xb3>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11e8 <scan_for+0xb8>
jmp    114d <scan_for+0x1d>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_for>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <readdir@plt>
test   %rax,%rax
je     1199 <scan_for+0x69>
lea    0xeae(%rip),%r15
jmp    116d <scan_for+0x3d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     1199 <scan_for+0x69>
mov    (%rax),%rbp
cmp    %r12b,0x0(%rbp)
jne    1160 <scan_for+0x30>
lea    0x1(%rbp),%rdi
mov    %r15,%rsi
call   1030 <strspn@plt>
cmp    $0x2,%eax
jl     1160 <scan_for+0x30>
lea    0x3(%rbp),%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    1160 <scan_for+0x30>
jmp    119b <scan_for+0x6b>
xor    %ebp,%ebp
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [11 x i8] c"0123456789\00"
define i8* @scan_for(i32* %0, i8* %1, i8 signext %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
store i8* null, i8** %8
br label %10
10: ; preds = %43, %31, %24, %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 %44
14: ; preds = %10
%15 = load %struct.dirent*, %struct.dirent** %7
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i32 0, i32 0
%17 = load i8*, i8** %16
store i8* %17, i8** %9
%18 = load i8*, i8** %9
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %14
br label %10
25: ; preds = %14
%26 = load i8*, i8** %9
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %9
%28 = load i8*, i8** %9
%29 = call i32 @strspn(i8* %28, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%30 = icmp slt i32 %29, 2
br i1 %30, label %31, label %32
31: ; preds = %25
br label %10
32: ; preds = %25
%33 = load i8*, i8** %9
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = load i8*, i8** %5
%37 = call i32 @strcmp(i8* %35, i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %32
%40 = load %struct.dirent*, %struct.dirent** %7
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
store i8* %42, i8** %8
br label %44
43: ; preds = %32
br label %10
44: ; preds = %39, %10
%45 = load i8*, i8** %8
ret i8* %45
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [11 x i8] c"0123456789\00"
define i8* @scan_for(i32* %0, i8* nocapture %1, i8 signext %2) {
%4 = tail call %struct.dirent* @readdir(i32* %0)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %23, label %6
6: ; preds = %3, %20
%7 = phi %struct.dirent* [ %21, %20 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, %2
br i1 %11, label %12, label %20
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = tail call i32 @strspn(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = icmp slt i32 %14, 2
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %9, i64 3
%18 = tail call i32 @strcmp(i8* %17, i8* dereferenceable(1) %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16, %12, %6
%21 = tail call %struct.dirent* @readdir(i32* %0)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %23, label %6
23: ; preds = %20, %16, %3
%24 = phi i8* [ null, %3 ], [ null, %20 ], [ %9, %16 ]
ret i8* %24
}