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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, scalar_t__ *);
scalar_t__ unlink(char *);
int /*<<< orphan*/ warn(char *, char *);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("usage: rino number\n");
    return 1;
  }
  ino_t ino;
  DIR *dirp;
  struct dirent *dirent;
  sscanf(argv[1], "%llu", &ino);
  dirp = opendir(".");
  if (dirp == NULL) {
    warn("%s", ".");
    return 1;
  }
  while ((dirent = readdir(dirp)) != NULL) {
    if (dirent->d_ino != ino)
      continue;
    if (unlink(dirent->d_name) != 0) {
      warn("%s", dirent->d_name);
      return 1;
    }
  }
  closedir(dirp);
  return 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)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1278 <main+0x108>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5d(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1090 <sscanf@plt>
lea    0xe52(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fa <main+0x8a>
lea    0xe39(%rip),%rdi
lea    0xe30(%rip),%rsi
call   1040 <warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    1278 <main+0x108>
jmp    11ff <main+0x8f>
mov    -0x20(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1268 <main+0xf8>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
je     122c <main+0xbc>
jmp    11ff <main+0x8f>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     1263 <main+0xf3>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdc9(%rip),%rdi
call   1040 <warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    1278 <main+0x108>
jmp    11ff <main+0x8f>
mov    -0x20(%rbp),%rdi
call   1070 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11f4 <main+0x84>
mov    0x8(%rsi),%rdi
lea    0xe7c(%rip),%rsi
mov    %rsp,%rdx
call   1090 <sscanf@plt>
lea    0xe72(%rip),%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     120e <main+0x9e>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1202 <main+0x92>
mov    %rax,%rbx
jmp    11d0 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1202 <main+0x92>
mov    (%rbx),%rax
cmp    (%rsp),%rax
jne    11c0 <main+0x50>
mov    0x8(%rbx),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
je     11c0 <main+0x50>
mov    0x8(%rbx),%rsi
lea    0xe15(%rip),%rdi
jmp    121c <main+0xac>
lea    0xe0f(%rip),%rdi
call   1050 <puts@plt>
jmp    1221 <main+0xb1>
mov    %r14,%rdi
call   1070 <closedir@plt>
xor    %eax,%eax
jmp    1226 <main+0xb6>
lea    0xdf2(%rip),%rdi
lea    0xde9(%rip),%rsi
call   1040 <warn@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.dirent = type { i64, i8* }
@.str.1 = [5 x i8] c"%llu\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"%s\00"
@str = [19 x i8] c"usage: rino number\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = icmp eq i32 %0, 2
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %41
7: ; preds = %2
%8 = bitcast i64* %3 to i8*
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%12 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %7
%15 = call %struct.dirent* @readdir(i32* %12)
%16 = icmp eq %struct.dirent* %15, null
br i1 %16, label %37, label %19
17: ; preds = %7
%18 = call i32 @warn(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %39
19: ; preds = %14, %25
%20 = phi %struct.dirent* [ %26, %25 ], [ %15, %14 ]
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 0
%22 = load i64, i64* %21
%23 = load i64, i64* %3
%24 = icmp eq i64 %22, %23
br i1 %24, label %28, label %25
25: ; preds = %19, %28
%26 = call %struct.dirent* @readdir(i32* %12)
%27 = icmp eq %struct.dirent* %26, null
br i1 %27, label %37, label %19
28: ; preds = %19
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 1
%30 = load i8*, i8** %29
%31 = call i64 @unlink(i8* %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %25, label %33
33: ; preds = %28
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 1
%35 = load i8*, i8** %34
%36 = call i32 @warn(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %35)
br label %39
37: ; preds = %25, %14
%38 = call i32 @closedir(i32* %12)
br label %39
39: ; preds = %37, %33, %17
%40 = phi i32 [ 1, %17 ], [ 1, %33 ], [ 0, %37 ]
br label %41
41: ; preds = %39, %5
%42 = phi i32 [ 1, %5 ], [ %40, %39 ]
ret i32 %42
}