#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 */
typedef int /*<<< orphan*/ prefix;

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
void remap_command(const char **path) {
  static const char prefix[] = "TANDYALF";
  char envname[256];
  char *replacement;
  unsigned i;
  strcpy(envname, prefix);
  strncat(envname, *path, 256 - sizeof(prefix));
  for (i = 0; i < 256 && envname[i]; ++i)
    if (envname[i] == '/' || envname[i] == '.')
      envname[i] = '_';
    else if (envname[i] == '+')
      envname[i] = 'x';
  replacement = getenv(envname);
  if (replacement)
    *path = replacement;
}


x86 assembly (clang, -O0):
<remap_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xeb3(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    $0xf7,%edx
call   1050 <strncat@plt>
movl   $0x0,-0x11c(%rbp)
xor    %eax,%eax
cmpl   $0x100,-0x11c(%rbp)
mov    %al,-0x11d(%rbp)
jae    11a6 <remap_command+0x76>
mov    -0x11c(%rbp),%eax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11d(%rbp)
mov    -0x11d(%rbp),%al
test   $0x1,%al
jne    11b9 <remap_command+0x89>
jmp    123d <remap_command+0x10d>
mov    -0x11c(%rbp),%eax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
je     11e7 <remap_command+0xb7>
mov    -0x11c(%rbp),%eax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2e,%eax
jne    11fa <remap_command+0xca>
mov    -0x11c(%rbp),%eax
movb   $0x5f,-0x110(%rbp,%rax,1)
5f
jmp    1224 <remap_command+0xf4>
mov    -0x11c(%rbp),%eax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2b,%eax
jne    121f <remap_command+0xef>
mov    -0x11c(%rbp),%eax
movb   $0x78,-0x110(%rbp,%rax,1)
78
jmp    1224 <remap_command+0xf4>
jmp    1229 <remap_command+0xf9>
mov    -0x11c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x11c(%rbp)
jmp    1174 <remap_command+0x44>
lea    -0x110(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     126c <remap_command+0x13c>
mov    -0x118(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remap_command>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
lea    0xebc(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    (%r14),%rsi
mov    %rbx,%rdi
mov    $0xf7,%edx
call   1050 <strncat@plt>
xor    %eax,%eax
jmp    1182 <remap_command+0x52>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x78,%dl
mov    %dl,0x1(%rsp,%rax,1)
add    $0x2,%rax
cmp    $0x100,%rax
je     11be <remap_command+0x8e>
movzbl (%rsp,%rax,1),%ecx
mov    $0x5f,%dl
lea    -0x2e(%rcx),%esi
cmp    $0x2,%sil
jb     11a2 <remap_command+0x72>
cmp    $0x2b,%cl
je     11a0 <remap_command+0x70>
test   %cl,%cl
jne    11a5 <remap_command+0x75>
jmp    11be <remap_command+0x8e>
nopl   0x0(%rax)
mov    $0x78,%dl
mov    %dl,(%rsp,%rax,1)
movzbl 0x1(%rsp,%rax,1),%ecx
mov    $0x5f,%dl
lea    -0x2e(%rcx),%esi
cmp    $0x2,%sil
jb     1172 <remap_command+0x42>
cmp    $0x2b,%cl
je     1170 <remap_command+0x40>
test   %cl,%cl
jne    1176 <remap_command+0x46>
mov    %rsp,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ce <remap_command+0x9e>
mov    %rax,(%r14)
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@remap_command.prefix = internal constant [9 x i8] c"TANDYALF\00"
define void @remap_command(i8** nocapture %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @remap_command.prefix, i64 0, i64 0))
%5 = load i8*, i8** %0
%6 = call i32 @strncat(i8* %3, i8* %5, i32 247)
br label %7
7: ; preds = %21, %1
%8 = phi i64 [ 0, %1 ], [ %22, %21 ]
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %8
%10 = load i8, i8* %9
switch i8 %10, label %14 [
i8 0, label %24
i8 47, label %12
i8 46, label %12
i8 43, label %11
]
11: ; preds = %7
br label %12
12: ; preds = %7, %7, %11
%13 = phi i8 [ 120, %11 ], [ 95, %7 ], [ 95, %7 ]
store i8 %13, i8* %9
br label %14
14: ; preds = %12, %7
%15 = or i64 %8, 1
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %15
%17 = load i8, i8* %16
switch i8 %17, label %21 [
i8 0, label %24
i8 47, label %19
i8 46, label %19
i8 43, label %18
]
18: ; preds = %14
br label %19
19: ; preds = %18, %14, %14
%20 = phi i8 [ 120, %18 ], [ 95, %14 ], [ 95, %14 ]
store i8 %20, i8* %16
br label %21
21: ; preds = %19, %14
%22 = add nuw nsw i64 %8, 2
%23 = icmp eq i64 %22, 256
br i1 %23, label %24, label %7
24: ; preds = %21, %14, %7
%25 = call i8* @getenv(i8* %3)
%26 = icmp eq i8* %25, null
br i1 %26, label %28, label %27
27: ; preds = %24
store i8* %25, i8** %0
br label %28
28: ; preds = %27, %24
ret void
}