#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 */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ seekdir(int /*<<< orphan*/ *, int);
int main(void) {
  DIR *dir;
  struct dirent *d_ptr;
  dir = opendir("./");
  if (dir == NULL) {
    perror("fail to open dir");
    exit(1);
  }
  seekdir(dir, 1117558374);
  while ((d_ptr = readdir(dir)) != NULL)
    printf("dir name is :%s \n", d_ptr->d_name);
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b0 <main+0x40>
lea    0xe62(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    $0x429c9666,%esi
call   1070 <seekdir@plt>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ed <main+0x7d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
jmp    11be <main+0x4e>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11da <main+0x6a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x429c9666,%esi
call   1070 <seekdir@plt>
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11c8 <main+0x58>
lea    0xe6b(%rip),%r14
nopl   0x0(%rax)
mov    (%rax),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
jne    11b0 <main+0x40>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe22(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [3 x i8] c"./\00"
@.str.1 = [17 x i8] c"fail to open dir\00"
@.str.2 = [18 x i8] c"dir name is :%s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
store i32 0, i32* %1
%4 = call i32* @opendir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32*, i32** %2
%12 = call i32 @seekdir(i32* %11, i32 1117558374)
br label %13
13: ; preds = %17, %10
%14 = load i32*, i32** %2
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %3
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %3
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %13
22: ; preds = %13
%23 = load i32*, i32** %2
%24 = call i32 @closedir(i32* %23)
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [3 x i8] c"./\00"
@.str.1 = [17 x i8] c"fail to open dir\00"
@.str.2 = [18 x i8] c"dir name is :%s \0A\00"
define i32 @main() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32 @seekdir(i32* %1, i32 1117558374)
%8 = tail call %struct.dirent* @readdir(i32* %1)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %17, label %10
10: ; preds = %6, %10
%11 = phi %struct.dirent* [ %15, %10 ], [ %8, %6 ]
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = tail call %struct.dirent* @readdir(i32* %1)
%16 = icmp eq %struct.dirent* %15, null
br i1 %16, label %17, label %10
17: ; preds = %10, %6
%18 = tail call i32 @closedir(i32* %1)
ret i32 0
}