#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 asprintf(char **, char *, int /*<<< orphan*/, char const *);
int /*<<< orphan*/ datapath();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
char *real_path(const char *filename) {
  char *dst;
  if (filename[0] == '/' || filename[1] == ':') {
    dst = strdup(filename);
  } else {
    if (asprintf(&dst, "%s/%s", datapath(), filename) == -1) {
      fprintf(stderr, "out-of-memory\n");
      return NULL;
    }
  }
  return dst;
}


x86 assembly (clang, -O0):
<real_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     116d <real_path+0x2d>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3a,%eax
jne    117f <real_path+0x3f>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    11cc <real_path+0x8c>
mov    $0x0,%al
call   1050 <datapath@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    11c7 <real_path+0x87>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <real_path+0x94>
jmp    11cc <real_path+0x8c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<real_path>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
cmpb   $0x2f,(%rdi)
je     1153 <real_path+0x13>
cmpb   $0x3a,0x1(%rbx)
jne    1160 <real_path+0x20>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <strdup@plt>
xor    %eax,%eax
call   1050 <datapath@plt>
lea    0xe92(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %eax,%edx
mov    %rbx,%rcx
call   1040 <asprintf@plt>
cmp    $0xffffffff,%eax
je     1189 <real_path+0x49>
mov    0x8(%rsp),%rax
jmp    11a0 <real_path+0x60>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"out-of-memory\0A\00"
define i8* @real_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 47
br i1 %9, label %16, label %10
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 58
br i1 %15, label %16, label %19
16: ; preds = %10, %1
%17 = load i8*, i8** %3
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %4
br label %28
19: ; preds = %10
%20 = call i32 (...) @datapath()
%21 = load i8*, i8** %3
%22 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %30
27: ; preds = %19
br label %28
28: ; preds = %27, %16
%29 = load i8*, i8** %4
store i8* %29, i8** %2
br label %30
30: ; preds = %28, %24
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"out-of-memory\0A\00"
define i8* @real_path(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 47
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 58
br i1 %9, label %10, label %12
10: ; preds = %6, %1
%11 = tail call i8* @strdup(i8* %0)
br label %21
12: ; preds = %6
%13 = tail call i32 (...) @datapath()
%14 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13, i8* %0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = load i8*, i8** %2
br label %21
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %10, %16, %18
%22 = phi i8* [ null, %18 ], [ %17, %16 ], [ %11, %10 ]
ret i8* %22
}