#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 */

/* Variables and functions */
int O_DIRECTORY;
int O_RDONLY;
int /*<<< orphan*/ SYS_getdents;
int open(char *, int);
int syscall(int /*<<< orphan*/, int, char *, int);
int execute_getdents() {
  int fd, nread, BUF_SIZE = 1024;
  char buf[BUF_SIZE];
  fd = open(".", O_RDONLY | O_DIRECTORY);
  for (;;) {
    nread = syscall(SYS_getdents, fd, buf, BUF_SIZE);
    if (nread == -1)
      break;
    if (nread == 0)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<execute_getdents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x400,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    0x2e73(%rip),%rax
or     (%rax),%esi
lea    0xe92(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x28(%rbp),%rdx
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%ecx
call   1030 <syscall@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11a0 <execute_getdents+0x80>
jmp    11b4 <execute_getdents+0x94>
cmpl   $0x0,-0x8(%rbp)
jne    11af <execute_getdents+0x8f>
jmp    11b4 <execute_getdents+0x94>
jmp    1176 <execute_getdents+0x56>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute_getdents>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    0x2eb5(%rip),%rax
mov    0x2e9e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xebb(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%ebx
mov    0x2e7d(%rip),%r15
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    %ebx,%esi
mov    %r14,%rdx
mov    $0x400,%ecx
call   1030 <syscall@plt>
add    $0x1,%eax
cmp    $0x1,%eax
ja     1160 <execute_getdents+0x40>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@SYS_getdents = global i32 0
define i32 @execute_getdents() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 1024, i32* %3
%6 = load i32, i32* %3
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %4
%9 = alloca i8, i64 %7
store i64 %7, i64* %5
%10 = load i32, i32* @O_RDONLY
%11 = load i32, i32* @O_DIRECTORY
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %1
br label %14
14: ; preds = %26, %0
%15 = load i32, i32* @SYS_getdents
%16 = load i32, i32* %1
%17 = load i32, i32* %3
%18 = call i32 @syscall(i32 %15, i32 %16, i8* %9, i32 %17)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %14
br label %27
22: ; preds = %14
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
br label %27
26: ; preds = %22
br label %14
27: ; preds = %25, %21
%28 = load i8*, i8** %4
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@SYS_getdents = global i32 0
define i32 @execute_getdents() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = load i32, i32* @O_DIRECTORY
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %7, %0
%8 = load i32, i32* @SYS_getdents
%9 = call i32 @syscall(i32 %8, i32 %6, i8* %2, i32 1024)
%10 = add i32 %9, 1
%11 = icmp ult i32 %10, 2
br i1 %11, label %12, label %7
12: ; preds = %7
ret i32 0
}