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

/* Variables and functions */
int /*<<< orphan*/ mbstowcs(int /*<<< orphan*/ const *, int /*<<< orphan*/,
                            int);
struct dirent *readdir(int /*<<< orphan*/ *);
const wchar_t *osal_search_dir_read_next(void *dir_handle) {
  static wchar_t last_filename[260];
  DIR *dir = (DIR *)dir_handle;
  struct dirent *entry;
  entry = readdir(dir);
  if (entry == NULL)
    return NULL;
  mbstowcs(last_filename, entry->d_name, 260);
  return last_filename;
}


x86 assembly (clang, -O0):
<osal_search_dir_read_next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1159 <osal_search_dir_read_next+0x39>
movq   $0x0,-0x8(%rbp)
jmp    117b <osal_search_dir_read_next+0x5b>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
mov    $0x104,%edx
call   1030 <mbstowcs@plt>
lea    0xe89(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<osal_search_dir_read_next>:
push   %rbx
call   1040 <readdir@plt>
test   %rax,%rax
je     1143 <osal_search_dir_read_next+0x23>
mov    (%rax),%esi
lea    0xecc(%rip),%rbx
mov    %rbx,%rdi
mov    $0x104,%edx
call   1030 <mbstowcs@plt>
jmp    1145 <osal_search_dir_read_next+0x25>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@osal_search_dir_read_next.last_filename = internal constant [260 x i32] zeroinitializer
define i32* @osal_search_dir_read_next(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = bitcast i8* %6 to i32*
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = call %struct.dirent* @readdir(i32* %8)
store %struct.dirent* %9, %struct.dirent** %5
%10 = load %struct.dirent*, %struct.dirent** %5
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32* null, i32** %2
br label %18
13: ; preds = %1
%14 = load %struct.dirent*, %struct.dirent** %5
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @mbstowcs(i32* getelementptr inbounds ([260 x i32], [260 x i32]* @osal_search_dir_read_next.last_filename, i64 0, i64 0), i32 %16, i32 260)
store i32* getelementptr inbounds ([260 x i32], [260 x i32]* @osal_search_dir_read_next.last_filename, i64 0, i64 0), i32** %2
br label %18
18: ; preds = %13, %12
%19 = load i32*, i32** %2
ret i32* %19
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@osal_search_dir_read_next.last_filename = internal constant [260 x i32] zeroinitializer
define i32* @osal_search_dir_read_next(i8* %0) {
%2 = bitcast i8* %0 to i32*
%3 = tail call %struct.dirent* @readdir(i32* %2)
%4 = icmp eq %struct.dirent* %3, null
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = getelementptr inbounds %struct.dirent, %struct.dirent* %3, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 @mbstowcs(i32* getelementptr inbounds ([260 x i32], [260 x i32]* @osal_search_dir_read_next.last_filename, i64 0, i64 0), i32 %7, i32 260)
br label %9
9: ; preds = %1, %5
%10 = phi i32* [ getelementptr inbounds ([260 x i32], [260 x i32]* @osal_search_dir_read_next.last_filename, i64 0, i64 0), %5 ], [ null, %1 ]
ret i32* %10
}