#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 */
int PATH_MAX;
char *realpath(char const *, char *);
int /*<<< orphan*/ strncpy(scalar_t__, char const *, int);
scalar_t__ strrchr(char *, char);
char *resolve_config_path(const char *file_name, const char *root) {
  const char *real_fname = NULL;
  char buffer[PATH_MAX * 2 + 1];
  if (file_name[0] == '/') {
    real_fname = file_name;
  } else if (realpath(root, buffer) != NULL) {
    strncpy(strrchr(buffer, '/') + 1, file_name, PATH_MAX);
    real_fname = buffer;
  }
  char *ret = (real_fname == NULL) ? NULL : realpath(real_fname, NULL);
  return ret;
}


x86 assembly (clang, -O0):
<resolve_config_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%ecx
mov    %ecx,%eax
lea    0x1(%rax,%rax,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1197 <resolve_config_path+0x67>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11e2 <resolve_config_path+0xb2>
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1050 <realpath@plt>
cmp    $0x0,%rax
je     11dd <resolve_config_path+0xad>
mov    -0x38(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    -0x8(%rbp),%rsi
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11e2 <resolve_config_path+0xb2>
cmpq   $0x0,-0x18(%rbp)
jne    11f8 <resolve_config_path+0xc8>
xor    %eax,%eax
mov    %rax,-0x40(%rbp)
jmp    1209 <resolve_config_path+0xd9>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <realpath@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_config_path>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eac(%rip),%r15
mov    (%r15),%eax
add    %eax,%eax
add    $0x1,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
cmpb   $0x2f,(%rdi)
jne    1167 <resolve_config_path+0x37>
mov    %r14,%rbx
jmp    1193 <resolve_config_path+0x63>
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1050 <realpath@plt>
test   %rax,%rax
je     119f <resolve_config_path+0x6f>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rdi
mov    (%r15),%edx
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <realpath@plt>
jmp    11a1 <resolve_config_path+0x71>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
define i8* @resolve_config_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%9 = load i32, i32* @PATH_MAX
%10 = mul nsw i32 %9, 2
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 47
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = load i8*, i8** %3
store i8* %21, i8** %5
br label %33
22: ; preds = %2
%23 = load i8*, i8** %4
%24 = call i8* @realpath(i8* %23, i8* %14)
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = call i64 @strrchr(i8* %14, i8 signext 47)
%28 = add nsw i64 %27, 1
%29 = load i8*, i8** %3
%30 = load i32, i32* @PATH_MAX
%31 = call i32 @strncpy(i64 %28, i8* %29, i32 %30)
store i8* %14, i8** %5
br label %32
32: ; preds = %26, %22
br label %33
33: ; preds = %32, %20
%34 = load i8*, i8** %5
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %37
36: ; preds = %33
br label %40
37: ; preds = %33
%38 = load i8*, i8** %5
%39 = call i8* @realpath(i8* %38, i8* null)
br label %40
40: ; preds = %37, %36
%41 = phi i8* [ null, %36 ], [ %39, %37 ]
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = load i8*, i8** %6
ret i8* %42
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
define i8* @resolve_config_path(i8* %0, i8* nocapture %1) {
%3 = load i32, i32* @PATH_MAX
%4 = shl nsw i32 %3, 1
%5 = or i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 47
br i1 %9, label %18, label %10
10: ; preds = %2
%11 = call i8* @realpath(i8* %1, i8* %7)
%12 = icmp eq i8* %11, null
br i1 %12, label %21, label %13
13: ; preds = %10
%14 = call i64 @strrchr(i8* %7, i8 signext 47)
%15 = add nsw i64 %14, 1
%16 = load i32, i32* @PATH_MAX
%17 = call i32 @strncpy(i64 %15, i8* %0, i32 %16)
br label %18
18: ; preds = %13, %2
%19 = phi i8* [ %0, %2 ], [ %7, %13 ]
%20 = call i8* @realpath(i8* %19, i8* null)
br label %21
21: ; preds = %10, %18
%22 = phi i8* [ %20, %18 ], [ null, %10 ]
ret i8* %22
}