#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 /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ seekdir(int /*<<< orphan*/ *, long);
long telldir(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  DIR *dirp;
  long int save3 = 0;
  int i = 0;
  struct dirent *dp;
  dirp = opendir(".");
  for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
    if (i++ == 3)
      save3 = telldir(dirp);
    printf("%s\n", dp->d_name);
    if (i == 400)
      break;
  }
  printf("going back past 4-th entry...\n");
  seekdir(dirp, save3);
  for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
    printf("%s\n", dp->d_name);
  closedir(dirp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe64(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     121c <main+0xac>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x3,%eax
jne    11de <main+0x6e>
mov    -0x18(%rbp),%rdi
call   1080 <telldir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x190,-0x24(%rbp)
jne    1205 <main+0x95>
jmp    121c <main+0xac>
jmp    120a <main+0x9a>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x30(%rbp)
jmp    11b2 <main+0x42>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <seekdir@plt>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1276 <main+0x106>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x30(%rbp)
jmp    1244 <main+0xd4>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
jne    1198 <main+0x28>
xor    %r14d,%r14d
jmp    11ea <main+0x7a>
mov    %rax,%rbx
mov    $0x18f,%ebp
xor    %r14d,%r14d
jmp    11d6 <main+0x66>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1080 <telldir@plt>
mov    %rax,%r14
mov    (%rbx),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbx
add    $0xffffffff,%ebp
test   %rax,%rax
je     11ea <main+0x7a>
cmp    $0x18c,%ebp
je     11b0 <main+0x40>
mov    (%rbx),%rdi
call   1030 <puts@plt>
test   %ebp,%ebp
jne    11c3 <main+0x53>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <seekdir@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     1227 <main+0xb7>
mov    (%rax),%rdi
call   1030 <puts@plt>
jmp    1210 <main+0xa0>
mov    %r15,%rdi
call   1050 <closedir@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [31 x i8] c"going back past 4-th entry...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
store i32 0, i32* %8
%10 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = call %struct.dirent* @readdir(i32* %11)
store %struct.dirent* %12, %struct.dirent** %9
br label %13
13: ; preds = %32, %2
%14 = load %struct.dirent*, %struct.dirent** %9
%15 = icmp ne %struct.dirent* %14, null
br i1 %15, label %16, label %35
16: ; preds = %13
%17 = load i32, i32* %8
%18 = add nsw i32 %17, 1
store i32 %18, i32* %8
%19 = icmp eq i32 %17, 3
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32*, i32** %6
%22 = call i64 @telldir(i32* %21)
store i64 %22, i64* %7
br label %23
23: ; preds = %20, %16
%24 = load %struct.dirent*, %struct.dirent** %9
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, 400
br i1 %29, label %30, label %31
30: ; preds = %23
br label %35
31: ; preds = %23
br label %32
32: ; preds = %31
%33 = load i32*, i32** %6
%34 = call %struct.dirent* @readdir(i32* %33)
store %struct.dirent* %34, %struct.dirent** %9
br label %13
35: ; preds = %30, %13
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32*, i32** %6
%38 = load i64, i64* %7
%39 = call i32 @seekdir(i32* %37, i64 %38)
%40 = load i32*, i32** %6
%41 = call %struct.dirent* @readdir(i32* %40)
store %struct.dirent* %41, %struct.dirent** %9
br label %42
42: ; preds = %50, %35
%43 = load %struct.dirent*, %struct.dirent** %9
%44 = icmp ne %struct.dirent* %43, null
br i1 %44, label %45, label %53
45: ; preds = %42
%46 = load %struct.dirent*, %struct.dirent** %9
%47 = getelementptr inbounds %struct.dirent, %struct.dirent* %46, i32 0, i32 0
%48 = load i8*, i8** %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %45
%51 = load i32*, i32** %6
%52 = call %struct.dirent* @readdir(i32* %51)
store %struct.dirent* %52, %struct.dirent** %9
br label %42
53: ; preds = %42
%54 = load i32*, i32** %6
%55 = call i32 @closedir(i32* %54)
%56 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@str = [30 x i8] c"going back past 4-th entry...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call %struct.dirent* @readdir(i32* %3)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %26, label %6
6: ; preds = %2, %22
%7 = phi %struct.dirent* [ %24, %22 ], [ %4, %2 ]
%8 = phi i32 [ %10, %22 ], [ 0, %2 ]
%9 = phi i64 [ %23, %22 ], [ 0, %2 ]
%10 = add nuw nsw i32 %8, 1
%11 = icmp eq i32 %8, 3
br i1 %11, label %12, label %17
12: ; preds = %6
%13 = tail call i64 @telldir(i32* %3)
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = tail call i32 @puts(i8* dereferenceable(1) %15)
br label %22
17: ; preds = %6
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = tail call i32 @puts(i8* dereferenceable(1) %19)
%21 = icmp eq i32 %10, 400
br i1 %21, label %26, label %22
22: ; preds = %12, %17
%23 = phi i64 [ %13, %12 ], [ %9, %17 ]
%24 = tail call %struct.dirent* @readdir(i32* %3)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %26, label %6
26: ; preds = %22, %17, %2
%27 = phi i64 [ 0, %2 ], [ %9, %17 ], [ %23, %22 ]
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%29 = tail call i32 @seekdir(i32* %3, i64 %27)
%30 = tail call %struct.dirent* @readdir(i32* %3)
%31 = icmp eq %struct.dirent* %30, null
br i1 %31, label %39, label %32
32: ; preds = %26, %32
%33 = phi %struct.dirent* [ %37, %32 ], [ %30, %26 ]
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i64 0, i32 0
%35 = load i8*, i8** %34
%36 = tail call i32 @puts(i8* dereferenceable(1) %35)
%37 = tail call %struct.dirent* @readdir(i32* %3)
%38 = icmp eq %struct.dirent* %37, null
br i1 %38, label %39, label %32
39: ; preds = %32, %26
%40 = tail call i32 @closedir(i32* %3)
%41 = tail call i32 @exit(i32 0)
unreachable
}