#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 /*<<< orphan*/ strncat_s(char *, int, char const *, int);
int /*<<< orphan*/ strncpy_s(char *, int, char const *, int);
scalar_t__ strstr(char const *, char *);
void RelativeName(char *OutFileName, const char *NamePattern,
                  const char *OrigName) {
  char *Subst;
  Subst = (char *)strstr(NamePattern, "&i");
  if (Subst) {
    strncpy_s(OutFileName, 1024, NamePattern, Subst - NamePattern);
    OutFileName[Subst - NamePattern] = 0;
    strncat_s(OutFileName, 1024, OrigName, 1024);
    strncat_s(OutFileName, 1024, Subst + 2, 1024);
  } else {
    strncpy_s(OutFileName, 1024, NamePattern, 1024);
  }
}


x86 assembly (clang, -O0):
<RelativeName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c6 <RelativeName+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    $0x400,%esi
call   1040 <strncpy_s@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%ecx
mov    %ecx,%esi
call   1030 <strncat_s@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
add    $0x2,%rdx
mov    $0x400,%ecx
mov    %ecx,%esi
call   1030 <strncat_s@plt>
jmp    11da <RelativeName+0xaa>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%ecx
mov    %ecx,%esi
call   1040 <strncpy_s@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RelativeName>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
lea    0xeb7(%rip),%rsi
mov    %r12,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     11ad <RelativeName+0x7d>
mov    %rax,%r13
mov    %rax,%rbx
sub    %r12,%rbx
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1040 <strncpy_s@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
mov    $0x400,%ecx
call   1030 <strncat_s@plt>
add    $0x2,%r13
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
mov    $0x400,%ecx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <strncat_s@plt>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
mov    $0x400,%ecx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <strncpy_s@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"&i\00"
define void @RelativeName(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %5
%9 = call i64 @strstr(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %37
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = load i8*, i8** %7
%17 = load i8*, i8** %5
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = call i32 @strncpy_s(i8* %14, i32 1024, i8* %15, i32 %21)
%23 = load i8*, i8** %4
%24 = load i8*, i8** %7
%25 = load i8*, i8** %5
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = getelementptr inbounds i8, i8* %23, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %4
%31 = load i8*, i8** %6
%32 = call i32 @strncat_s(i8* %30, i32 1024, i8* %31, i32 1024)
%33 = load i8*, i8** %4
%34 = load i8*, i8** %7
%35 = getelementptr inbounds i8, i8* %34, i64 2
%36 = call i32 @strncat_s(i8* %33, i32 1024, i8* %35, i32 1024)
br label %41
37: ; preds = %3
%38 = load i8*, i8** %4
%39 = load i8*, i8** %5
%40 = call i32 @strncpy_s(i8* %38, i32 1024, i8* %39, i32 1024)
br label %41
41: ; preds = %37, %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"&i\00"
define void @RelativeName(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = inttoptr i64 %4 to i8*
%8 = ptrtoint i8* %1 to i64
%9 = sub i64 %4, %8
%10 = trunc i64 %9 to i32
%11 = tail call i32 @strncpy_s(i8* %0, i32 1024, i8* %1, i32 %10)
%12 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 0, i8* %12
%13 = tail call i32 @strncat_s(i8* %0, i32 1024, i8* %2, i32 1024)
%14 = getelementptr inbounds i8, i8* %7, i64 2
%15 = tail call i32 @strncat_s(i8* %0, i32 1024, i8* %14, i32 1024)
br label %18
16: ; preds = %3
%17 = tail call i32 @strncpy_s(i8* %0, i32 1024, i8* %1, i32 1024)
br label %18
18: ; preds = %16, %6
ret void
}