#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 {
  scalar_t__ d_ino;
  int /*<<< orphan*/ d_name;
};
typedef scalar_t__ ino_t;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(char *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
char *strdup(int /*<<< orphan*/);
char *find_name_byino(ino_t ino) {
  DIR *dp = NULL;
  struct dirent *dptr = NULL;
  char *filename = NULL;
  if (NULL == (dp = opendir("."))) {
    fprintf("stderr", "Can not open Current Directory\n");
    exit(-1);
  } else {
    while (NULL != (dptr = readdir(dp))) {
      if (dptr->d_ino == ino) {
        filename = strdup(dptr->d_name);
        break;
      }
    }
    closedir(dp);
  }
  return filename;
}


x86 assembly (clang, -O0):
<find_name_byino>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe75(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11bf <find_name_byino+0x5f>
lea    0xe59(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11c4 <find_name_byino+0x64>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     120a <find_name_byino+0xaa>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmp    -0x8(%rbp),%rax
jne    1205 <find_name_byino+0xa5>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    120a <find_name_byino+0xaa>
jmp    11c4 <find_name_byino+0x64>
mov    -0x10(%rbp),%rdi
call   1040 <closedir@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_name_byino>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xe91(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11ae <find_name_byino+0x4e>
mov    %rax,%r15
xor    %r14d,%r14d
nop
mov    %r15,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     119d <find_name_byino+0x3d>
cmp    %rbx,(%rax)
jne    1180 <find_name_byino+0x20>
mov    0x8(%rax),%edi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <closedir@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe54(%rip),%rdi
lea    0xe46(%rip),%rcx
mov    $0x1f,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i64, i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [7 x i8] c"stderr\00"
@.str.2 = [32 x i8] c"Can not open Current Directory\0A\00"
define i8* @find_name_byino(i64 %0) {
%2 = alloca i64
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i8*
store i64 %0, i64* %2
store i32* null, i32** %3
store %struct.dirent* null, %struct.dirent** %4
store i8* null, i8** %5
%6 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = icmp eq i32* null, %6
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = call i32 @fprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %1
br label %12
12: ; preds = %27, %11
%13 = load i32*, i32** %3
%14 = call %struct.dirent* @readdir(i32* %13)
store %struct.dirent* %14, %struct.dirent** %4
%15 = icmp ne %struct.dirent* null, %14
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load %struct.dirent*, %struct.dirent** %4
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = load i64, i64* %2
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load %struct.dirent*, %struct.dirent** %4
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = call i8* @strdup(i32 %25)
store i8* %26, i8** %5
br label %28
27: ; preds = %16
br label %12
28: ; preds = %22, %12
%29 = load i32*, i32** %3
%30 = call i32 @closedir(i32* %29)
br label %31
31: ; preds = %28
%32 = load i8*, i8** %5
ret i8* %32
}

LLVM IR (-O2):
%struct.dirent = type { i64, i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [7 x i8] c"stderr\00"
@.str.2 = [32 x i8] c"Can not open Current Directory\0A\00"
define i8* @find_name_byino(i64 %0) {
%2 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i64 31, i64 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %1, %10
%8 = tail call %struct.dirent* @readdir(i32* %2)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %18, label %10
10: ; preds = %7
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, %0
br i1 %13, label %14, label %7
14: ; preds = %10
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 1
%16 = load i32, i32* %15
%17 = tail call i8* @strdup(i32 %16)
br label %18
18: ; preds = %7, %14
%19 = phi i8* [ %17, %14 ], [ null, %7 ]
%20 = tail call i32 @closedir(i32* %2)
ret i8* %19
}