#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 */
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[4096 * 2 + 1];
  if (file_name[0] == '/') {
    real_fname = file_name;
  } else if (realpath(root, buffer) != NULL) {
    strncpy(strrchr(buffer, '/') + 1, file_name, 4096);
    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    $0x2030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1168 <resolve_config_path+0x38>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11b8 <resolve_config_path+0x88>
mov    -0x10(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
call   1050 <realpath@plt>
cmp    $0x0,%rax
je     11b3 <resolve_config_path+0x83>
lea    -0x2020(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    -0x8(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
lea    -0x2020(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11b8 <resolve_config_path+0x88>
cmpq   $0x0,-0x18(%rbp)
jne    11d1 <resolve_config_path+0xa1>
xor    %eax,%eax
mov    %rax,-0x2030(%rbp)
jmp    11e5 <resolve_config_path+0xb5>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <realpath@plt>
mov    %rax,-0x2030(%rbp)
mov    -0x2030(%rbp),%rax
mov    %rax,-0x2028(%rbp)
mov    -0x2028(%rbp),%rax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_config_path>:
push   %r14
push   %rbx
sub    $0x2008,%rsp
mov    %rdi,%rbx
cmpb   $0x2f,(%rdi)
jne    1147 <resolve_config_path+0x17>
mov    %rbx,%r14
jmp    1178 <resolve_config_path+0x48>
mov    %rsp,%r14
mov    %rsi,%rdi
mov    %r14,%rsi
call   1050 <realpath@plt>
test   %rax,%rax
je     1184 <resolve_config_path+0x54>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rdi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <realpath@plt>
jmp    1186 <resolve_config_path+0x56>
xor    %eax,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %r14
ret

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

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