#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(char *, char const *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strstr(char const *, char *);
void RelativeName(char *OutFileName, const char *NamePattern,
                  const char *OrigName) {
  char *Subst;
  Subst = strstr(NamePattern, "&i");
  if (Subst) {
    strncpy(OutFileName, NamePattern, Subst - NamePattern);
    OutFileName[Subst - NamePattern] = 0;
    strncat(OutFileName, OrigName, 1024);
    strncat(OutFileName, Subst + 2, 1024);
  } else {
    strncpy(OutFileName, 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     11bd <RelativeName+0x8d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@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),%rsi
mov    $0x400,%edx
call   1040 <strncat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x2,%rsi
mov    $0x400,%edx
call   1040 <strncat@plt>
jmp    11cf <RelativeName+0x9f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1030 <strncpy@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     119e <RelativeName+0x6e>
mov    %rax,%r13
mov    %rax,%rbx
sub    %r12,%rbx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
call   1040 <strncat@plt>
add    $0x2,%r13
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x400,%edx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <strncat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x400,%edx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <strncpy@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 i8* @strstr(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %36
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = load i8*, i8** %7
%16 = load i8*, i8** %5
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = call i32 @strncpy(i8* %13, i8* %14, i32 %20)
%22 = load i8*, i8** %4
%23 = load i8*, i8** %7
%24 = load i8*, i8** %5
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = getelementptr inbounds i8, i8* %22, i64 %27
store i8 0, i8* %28
%29 = load i8*, i8** %4
%30 = load i8*, i8** %6
%31 = call i32 @strncat(i8* %29, i8* %30, i32 1024)
%32 = load i8*, i8** %4
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 2
%35 = call i32 @strncat(i8* %32, i8* %34, i32 1024)
br label %40
36: ; preds = %3
%37 = load i8*, i8** %4
%38 = load i8*, i8** %5
%39 = call i32 @strncpy(i8* %37, i8* %38, i32 1024)
br label %40
40: ; preds = %36, %12
ret void
}

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