#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 */

/* Variables and functions */
scalar_t__ fs_exists(char const *);
char *path_next_sep(char const *);
const char *fs_resolve(const char *path) {
  if (fs_exists(path))
    return path;
  while ((path = path_next_sep(path))) {
    path += 1;
    if (fs_exists(path))
      return path;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<fs_resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fs_exists@plt>
cmp    $0x0,%rax
je     114c <fs_resolve+0x2c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a1 <fs_resolve+0x81>
jmp    1151 <fs_resolve+0x31>
mov    -0x10(%rbp),%rdi
call   1030 <path_next_sep@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1199 <fs_resolve+0x79>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fs_exists@plt>
cmp    $0x0,%rax
je     1194 <fs_resolve+0x74>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a1 <fs_resolve+0x81>
jmp    1151 <fs_resolve+0x31>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fs_resolve>:
push   %rbx
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1040 <fs_exists@plt>
test   %rax,%rax
jne    1155 <fs_resolve+0x35>
mov    %rbx,%rdi
call   1030 <path_next_sep@plt>
test   %rax,%rax
je     1153 <fs_resolve+0x33>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
jmp    1130 <fs_resolve+0x10>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @fs_resolve(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i64 @fs_exists(i8* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i8*, i8** %3
store i8* %8, i8** %2
br label %24
9: ; preds = %1
br label %10
10: ; preds = %22, %9
%11 = load i8*, i8** %3
%12 = call i8* @path_next_sep(i8* %11)
store i8* %12, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = call i64 @fs_exists(i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = load i8*, i8** %3
store i8* %21, i8** %2
br label %24
22: ; preds = %14
br label %10
23: ; preds = %10
store i8* null, i8** %2
br label %24
24: ; preds = %23, %20, %7
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
define i8* @fs_resolve(i8* %0) {
%2 = tail call i64 @fs_exists(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %1, %8
%5 = phi i8* [ %9, %8 ], [ %0, %1 ]
%6 = tail call i8* @path_next_sep(i8* %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = tail call i64 @fs_exists(i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %4, label %12
12: ; preds = %4, %8, %1
%13 = phi i8* [ %0, %1 ], [ null, %4 ], [ %9, %8 ]
ret i8* %13
}