#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 *dirname(char *);
int /*<<< orphan*/ memmove(char *, char *, size_t);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
const char *lirc_parse_relative(char *dst, size_t dst_size, const char *child,
                                const char *current) {
  char *dir;
  size_t dirlen;
  if (!current)
    return child;
  if (*child == '/')
    return child;
  if (strlen(current) >= dst_size)
    return NULL;
  strcpy(dst, current);
  dir = dirname(dst);
  dirlen = strlen(dir);
  if (dir != dst)
    memmove(dst, dir, dirlen + 1);
  if (dirlen + 1 + strlen(child) + 1 > dst_size)
    return NULL;
  strcat(dst, "/");
  strcat(dst, child);
  return dst;
}


x86 assembly (clang, -O0):
<lirc_parse_relative>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1180 <lirc_parse_relative+0x30>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1266 <lirc_parse_relative+0x116>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    119d <lirc_parse_relative+0x4d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1266 <lirc_parse_relative+0x116>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x18(%rbp),%rax
jb     11bd <lirc_parse_relative+0x6d>
movq   $0x0,-0x8(%rbp)
jmp    1266 <lirc_parse_relative+0x116>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <dirname@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1207 <lirc_parse_relative+0xb7>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
cmp    -0x18(%rbp),%rax
jbe    1241 <lirc_parse_relative+0xf1>
movq   $0x0,-0x8(%rbp)
jmp    1266 <lirc_parse_relative+0x116>
mov    -0x10(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lirc_parse_relative>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
test   %rcx,%rcx
je     1167 <lirc_parse_relative+0x17>
cmpb   $0x2f,(%r14)
jne    116c <lirc_parse_relative+0x1c>
mov    %r14,%r12
jmp    11ea <lirc_parse_relative+0x9a>
mov    %rcx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rcx,%rdi
call   1040 <strlen@plt>
cmp    %r15,%rax
jae    11cb <lirc_parse_relative+0x7b>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1050 <dirname@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
cmp    %r12,%rbx
je     11b7 <lirc_parse_relative+0x67>
lea    0x1(%r13),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <memmove@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r13,%rax
add    $0x2,%rax
cmp    %r15,%rax
jbe    11d0 <lirc_parse_relative+0x80>
xor    %r12d,%r12d
jmp    11ea <lirc_parse_relative+0x9a>
lea    0xe29(%rip),%rsi
mov    %r12,%rdi
call   1070 <strcat@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @lirc_parse_relative(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %9
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %4
%15 = load i8*, i8** %8
store i8* %15, i8** %5
br label %63
16: ; preds = %4
%17 = load i8*, i8** %8
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 47
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i8*, i8** %8
store i8* %22, i8** %5
br label %63
23: ; preds = %16
%24 = load i8*, i8** %9
%25 = call i64 @strlen(i8* %24)
%26 = load i64, i64* %7
%27 = icmp uge i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %23
store i8* null, i8** %5
br label %63
29: ; preds = %23
%30 = load i8*, i8** %6
%31 = load i8*, i8** %9
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i8*, i8** %6
%34 = call i8* @dirname(i8* %33)
store i8* %34, i8** %10
%35 = load i8*, i8** %10
%36 = call i64 @strlen(i8* %35)
store i64 %36, i64* %11
%37 = load i8*, i8** %10
%38 = load i8*, i8** %6
%39 = icmp ne i8* %37, %38
br i1 %39, label %40, label %46
40: ; preds = %29
%41 = load i8*, i8** %6
%42 = load i8*, i8** %10
%43 = load i64, i64* %11
%44 = add i64 %43, 1
%45 = call i32 @memmove(i8* %41, i8* %42, i64 %44)
br label %46
46: ; preds = %40, %29
%47 = load i64, i64* %11
%48 = add i64 %47, 1
%49 = load i8*, i8** %8
%50 = call i64 @strlen(i8* %49)
%51 = add i64 %48, %50
%52 = add i64 %51, 1
%53 = load i64, i64* %7
%54 = icmp ugt i64 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %46
store i8* null, i8** %5
br label %63
56: ; preds = %46
%57 = load i8*, i8** %6
%58 = call i32 @strcat(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%59 = load i8*, i8** %6
%60 = load i8*, i8** %8
%61 = call i32 @strcat(i8* %59, i8* %60)
%62 = load i8*, i8** %6
store i8* %62, i8** %5
br label %63
63: ; preds = %56, %55, %28, %21, %14
%64 = load i8*, i8** %5
ret i8* %64
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @lirc_parse_relative(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = icmp eq i8* %3, null
br i1 %5, label %28, label %6
6: ; preds = %4
%7 = load i8, i8* %2
%8 = icmp eq i8 %7, 47
br i1 %8, label %28, label %9
9: ; preds = %6
%10 = tail call i64 @strlen(i8* %3)
%11 = icmp ult i64 %10, %1
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = tail call i32 @strcpy(i8* %0, i8* %3)
%14 = tail call i8* @dirname(i8* %0)
%15 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%16 = icmp eq i8* %14, %0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = add i64 %15, 1
%19 = tail call i32 @memmove(i8* %0, i8* %14, i64 %18)
br label %20
20: ; preds = %17, %12
%21 = tail call i64 @strlen(i8* %2)
%22 = add i64 %15, 2
%23 = add i64 %22, %21
%24 = icmp ugt i64 %23, %1
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = tail call i32 @strcat(i8* %0, i8* %2)
br label %28
28: ; preds = %20, %9, %6, %4, %25
%29 = phi i8* [ %0, %25 ], [ %2, %4 ], [ %2, %6 ], [ null, %9 ], [ null, %20 ]
ret i8* %29
}