#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*/ EXIT_FAILURE;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
extern void inode_num_to_name(ino_t this_ino, char this_inode_name[]) {
  struct dirent *dirent_p;
  DIR *dir_p = opendir("..");
  if (dir_p == NULL) {
    perror("..");
    exit(EXIT_FAILURE);
  }
  while ((dirent_p = readdir(dir_p)) != NULL) {
    if (dirent_p->d_ino == this_ino) {
      strcpy(this_inode_name, dirent_p->d_name);
      closedir(dir_p);
      return;
    }
  }
  fprintf(stderr, "error looking from inum %ld\n", this_ino);
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<inode_num_to_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe79(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b5 <inode_num_to_name+0x45>
lea    0xe5e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11ba <inode_num_to_name+0x4a>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1206 <inode_num_to_name+0x96>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmp    -0x8(%rbp),%rax
jne    1201 <inode_num_to_name+0x91>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%esi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1050 <closedir@plt>
add    $0x20,%rsp
pop    %rbp
ret
jmp    11ba <inode_num_to_name+0x4a>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xde9(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<inode_num_to_name>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe7e(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     11e0 <inode_num_to_name+0x70>
mov    %rax,%rbx
nop
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11ba <inode_num_to_name+0x4a>
cmp    %r15,(%rax)
jne    1190 <inode_num_to_name+0x20>
mov    0x8(%rax),%esi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <closedir@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe19(%rip),%rdi
call   1080 <perror@plt>
jmp    11d2 <inode_num_to_name+0x62>

LLVM IR (-O0):
%struct.dirent = type { i64, i32 }
@.str = [3 x i8] c"..\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"error looking from inum %ld\0A\00"
define void @inode_num_to_name(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca %struct.dirent*
%6 = alloca i32*
store i64 %0, i64* %3
store i8* %1, i8** %4
%7 = call i32* @opendir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %6
%8 = load i32*, i32** %6
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
br label %15
15: ; preds = %33, %14
%16 = load i32*, i32** %6
%17 = call %struct.dirent* @readdir(i32* %16)
store %struct.dirent* %17, %struct.dirent** %5
%18 = icmp ne %struct.dirent* %17, null
br i1 %18, label %19, label %34
19: ; preds = %15
%20 = load %struct.dirent*, %struct.dirent** %5
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i64, i64* %21
%23 = load i64, i64* %3
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = load %struct.dirent*, %struct.dirent** %5
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = call i32 @strcpy(i8* %26, i32 %29)
%31 = load i32*, i32** %6
%32 = call i32 @closedir(i32* %31)
ret void
33: ; preds = %19
br label %15
34: ; preds = %15
%35 = load i32, i32* @stderr
%36 = load i64, i64* %3
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
}

LLVM IR (-O2):
%struct.dirent = type { i64, i32 }
@.str = [3 x i8] c"..\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"error looking from inum %ld\0A\00"
define void @inode_num_to_name(i64 %0, i8* %1) {
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2, %12
%10 = tail call %struct.dirent* @readdir(i32* %3)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, %0
br i1 %15, label %16, label %9
16: ; preds = %12
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 1
%18 = load i32, i32* %17
%19 = tail call i32 @strcpy(i8* %1, i32 %18)
%20 = tail call i32 @closedir(i32* %3)
ret void
21: ; preds = %9
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i64 %0)
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
}