#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 minix_fs_dat {
  int dummy;
};

/* Variables and functions */
int ilookup_name(struct minix_fs_dat *, int, char const *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/ *);
char *strchr(char const *, char);
int /*<<< orphan*/ strcmp(char const *, char *);
int find_inode(struct minix_fs_dat *fs, const char *path) {
  int inode = 1;
  if (!strcmp(path, "/") || path[0] == 0) {
    path = ".";
  } else if (path[0] == '/')
    ++path;
  while (path) {
    inode = ilookup_name(fs, inode, path, NULL, NULL);
    if (inode == -1)
      return -1;
    path = strchr(path, '/');
    if (path)
      path++;
  }
  return inode;
}


x86 assembly (clang, -O0):
<find_inode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     1170 <find_inode+0x40>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1180 <find_inode+0x50>
lea    0xe8b(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11a1 <find_inode+0x71>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    119c <find_inode+0x6c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a1 <find_inode+0x71>
jmp    11a6 <find_inode+0x76>
cmpq   $0x0,-0x18(%rbp)
je     1210 <find_inode+0xe0>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1050 <ilookup_name@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11e2 <find_inode+0xb2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <find_inode+0xe6>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120b <find_inode+0xdb>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a6 <find_inode+0x76>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_inode>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xebf(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strcmp@plt>
lea    0xeb2(%rip),%rbx
test   %eax,%eax
je     1166 <find_inode+0x36>
mov    0x0(%rbp),%al
test   %al,%al
je     1166 <find_inode+0x36>
cmp    $0x2f,%al
jne    1163 <find_inode+0x33>
add    $0x1,%rbp
mov    %rbp,%rbx
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <ilookup_name@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     119f <find_inode+0x6f>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
jne    1170 <find_inode+0x40>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.minix_fs_dat = type { i32 }
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define i32 @find_inode(%struct.minix_fs_dat* %0, i8* %1) {
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i8, i8* %1
switch i8 %6, label %9 [
i8 0, label %10
i8 47, label %7
]
7: ; preds = %5
%8 = getelementptr inbounds i8, i8* %1, i64 1
br label %10
9: ; preds = %5
br label %10
10: ; preds = %5, %9, %2, %7
%11 = phi i8* [ %8, %7 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %1, %9 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %5 ]
br label %12
12: ; preds = %10, %17
%13 = phi i32 [ %15, %17 ], [ 1, %10 ]
%14 = phi i8* [ %20, %17 ], [ %11, %10 ]
%15 = tail call i32 @ilookup_name(%struct.minix_fs_dat* %0, i32 %13, i8* %14, i32* null, i32* null)
%16 = icmp eq i32 %15, -1
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = tail call i8* @strchr(i8* %14, i8 signext 47)
%19 = icmp eq i8* %18, null
%20 = getelementptr inbounds i8, i8* %18, i64 1
br i1 %19, label %21, label %12
21: ; preds = %17, %12
ret i32 %15
}