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

/* Variables and functions */
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char const *, char *);
const char *_readdir(void *vp) {
  DIR *dp = (DIR *)vp;
  struct dirent *pdirent;
  while ((pdirent = readdir(dp)) != NULL) {
    if (strcmp(pdirent->d_name, ".") != 0 && strcmp(pdirent->d_name, "..") != 0)
      return pdirent->d_name;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<_readdir>:
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)
cmp    $0x0,%rax
je     119a <_readdir+0x7a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xea8(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     1195 <_readdir+0x75>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe8a(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     1195 <_readdir+0x75>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11a2 <_readdir+0x82>
jmp    1134 <_readdir+0x14>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_readdir>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
call   1040 <readdir@plt>
test   %rax,%rax
je     1185 <_readdir+0x65>
mov    %rax,%rbx
lea    0xec1(%rip),%r12
xor    %r14d,%r14d
lea    0xeb6(%rip),%r13
jmp    1160 <_readdir+0x40>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1188 <_readdir+0x68>
mov    (%rbx),%rdi
mov    %r12,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1150 <_readdir+0x30>
mov    (%rbx),%rdi
mov    %r13,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1150 <_readdir+0x30>
mov    (%rbx),%r14
jmp    1188 <_readdir+0x68>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i8* @_readdir(i8* %0) {
%2 = alloca i8*
%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
br label %8
8: ; preds = %28, %1
%9 = load i32*, i32** %4
%10 = call %struct.dirent* @readdir(i32* %9)
store %struct.dirent* %10, %struct.dirent** %5
%11 = icmp ne %struct.dirent* %10, null
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = load %struct.dirent*, %struct.dirent** %5
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %12
%19 = load %struct.dirent*, %struct.dirent** %5
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load %struct.dirent*, %struct.dirent** %5
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i32 0, i32 0
%27 = load i8*, i8** %26
store i8* %27, i8** %2
br label %30
28: ; preds = %18, %12
br label %8
29: ; preds = %8
store i8* null, i8** %2
br label %30
30: ; preds = %29, %24
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i8* @_readdir(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 %20, label %5
5: ; preds = %1, %17
%6 = phi %struct.dirent* [ %18, %17 ], [ %3, %1 ]
%7 = getelementptr inbounds %struct.dirent, %struct.dirent* %6, i64 0, i32 0
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %5
%12 = load i8*, i8** %7
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = load i8*, i8** %7
br label %20
17: ; preds = %11, %5
%18 = tail call %struct.dirent* @readdir(i32* %2)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %20, label %5
20: ; preds = %17, %1, %15
%21 = phi i8* [ %16, %15 ], [ null, %1 ], [ null, %17 ]
ret i8* %21
}