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

/* Variables and functions */
scalar_t__ dtree_iserror();
int /*<<< orphan*/ *open_dir_from_dirent(struct dirent *, struct stack **);
scalar_t__ path_is_dir(struct stack **, int /*<<< orphan*/);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
DIR *go_next_dir(DIR *curr, struct stack **path) {
  struct dirent *d;
  while ((d = readdir(curr)) != NULL) {
    if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
      continue;
    if (path_is_dir(path, d->d_name))
      break;
    if (dtree_iserror())
      return NULL;
  }
  return open_dir_from_dirent(d, path);
}


x86 assembly (clang, -O0):
<go_next_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f3 <go_next_dir+0xa3>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11ad <go_next_dir+0x5d>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11b2 <go_next_dir+0x62>
jmp    1160 <go_next_dir+0x10>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1030 <path_is_dir@plt>
cmp    $0x0,%rax
je     11d0 <go_next_dir+0x80>
jmp    11f3 <go_next_dir+0xa3>
mov    $0x0,%al
call   1070 <dtree_iserror@plt>
cmp    $0x0,%rax
je     11ee <go_next_dir+0x9e>
movq   $0x0,-0x8(%rbp)
jmp    1204 <go_next_dir+0xb4>
jmp    1160 <go_next_dir+0x10>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <open_dir_from_dirent@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<go_next_dir>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r13
call   1060 <readdir@plt>
test   %rax,%rax
je     11d3 <go_next_dir+0x83>
mov    %rax,%rbx
lea    0xe8e(%rip),%r15
lea    0xe86(%rip),%r12
jmp    1190 <go_next_dir+0x40>
nopl   0x0(%rax)
mov    %r13,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d3 <go_next_dir+0x83>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1180 <go_next_dir+0x30>
mov    (%rbx),%edi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1180 <go_next_dir+0x30>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <path_is_dir@plt>
test   %rax,%rax
jne    11d5 <go_next_dir+0x85>
xor    %eax,%eax
call   1070 <dtree_iserror@plt>
test   %rax,%rax
je     1180 <go_next_dir+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <open_dir_from_dirent@plt>

LLVM IR (-O0):
%struct.stack = type { i32 }
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i32* @go_next_dir(i32* %0, %struct.stack** %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca %struct.stack**
%6 = alloca %struct.dirent*
store i32* %0, i32** %4
store %struct.stack** %1, %struct.stack*** %5
br label %7
7: ; preds = %36, %23, %2
%8 = load i32*, i32** %4
%9 = call %struct.dirent* @readdir(i32* %8)
store %struct.dirent* %9, %struct.dirent** %6
%10 = icmp ne %struct.dirent* %9, null
br i1 %10, label %11, label %37
11: ; preds = %7
%12 = load %struct.dirent*, %struct.dirent** %6
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @strcmp(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load %struct.dirent*, %struct.dirent** %6
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @strcmp(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %17, %11
br label %7
24: ; preds = %17
%25 = load %struct.stack**, %struct.stack*** %5
%26 = load %struct.dirent*, %struct.dirent** %6
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i64 @path_is_dir(%struct.stack** %25, i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %24
br label %37
32: ; preds = %24
%33 = call i64 (...) @dtree_iserror()
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %32
store i32* null, i32** %3
br label %41
36: ; preds = %32
br label %7
37: ; preds = %31, %7
%38 = load %struct.dirent*, %struct.dirent** %6
%39 = load %struct.stack**, %struct.stack*** %5
%40 = call i32* @open_dir_from_dirent(%struct.dirent* %38, %struct.stack** %39)
store i32* %40, i32** %3
br label %41
41: ; preds = %37, %35
%42 = load i32*, i32** %3
ret i32* %42
}

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