#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 *env_subst(char *, int, char const *);
char *filename_parameter(char *, int, char *, int /*<<< orphan*/);
char *filename_unix(char *buffer, size_t buflen, const char *pattern) {
  const char *ps;
  char *pb, EnvPattern[260], FilePattern[260];
  size_t cnt;
  if (pattern == (char *)NULL)
    return ((char *)NULL);
  ps = env_subst(EnvPattern, 260, pattern);
  if (ps == (char *)NULL)
    return ((char *)NULL);
  ps = filename_parameter(FilePattern, 260, EnvPattern, 0);
  if (ps == (char *)NULL)
    return ((char *)NULL);
  for (cnt = 0, pb = buffer, ps = FilePattern; (cnt < buflen - 1) && (*ps);
       ps++) {
    switch (*ps) {
    case '\\':
      *pb++ = '/';
      cnt++;
      break;
    default:
      *pb++ = *ps;
      cnt++;
    }
  }
  *pb = '\0';
  return (buffer);
}


x86 assembly (clang, -O0):
<filename_unix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    114f <filename_unix+0x2f>
movq   $0x0,-0x8(%rbp)
jmp    12a4 <filename_unix+0x184>
lea    -0x140(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x104,%esi
call   1030 <env_subst@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1180 <filename_unix+0x60>
movq   $0x0,-0x8(%rbp)
jmp    12a4 <filename_unix+0x184>
lea    -0x250(%rbp),%rdi
lea    -0x140(%rbp),%rdx
mov    $0x104,%esi
xor    %ecx,%ecx
call   1040 <filename_parameter@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b6 <filename_unix+0x96>
movq   $0x0,-0x8(%rbp)
jmp    12a4 <filename_unix+0x184>
movq   $0x0,-0x258(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x250(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x258(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x259(%rbp)
jae    1207 <filename_unix+0xe7>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x259(%rbp)
mov    -0x259(%rbp),%al
test   $0x1,%al
jne    121a <filename_unix+0xfa>
jmp    1295 <filename_unix+0x175>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
sub    $0x5c,%al
jne    1256 <filename_unix+0x136>
jmp    122d <filename_unix+0x10d>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x2f,(%rax)
mov    -0x258(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x258(%rbp)
jmp    127f <filename_unix+0x15f>
mov    -0x28(%rbp),%rax
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x258(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x258(%rbp)
jmp    1284 <filename_unix+0x164>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11d4 <filename_unix+0xb4>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename_unix>:
push   %r14
push   %rbx
sub    $0x218,%rsp
test   %rdx,%rdx
je     119f <filename_unix+0x7f>
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x110(%rsp),%rdi
mov    $0x104,%esi
call   1030 <env_subst@plt>
test   %rax,%rax
je     119f <filename_unix+0x7f>
mov    %rsp,%rdi
lea    0x110(%rsp),%rdx
mov    $0x104,%esi
xor    %ecx,%ecx
call   1040 <filename_parameter@plt>
test   %rax,%rax
je     119f <filename_unix+0x7f>
mov    %rbx,%rax
cmp    $0x1,%r14
je     11a6 <filename_unix+0x86>
add    $0xffffffffffffffff,%r14
xor    %eax,%eax
jmp    118c <filename_unix+0x6c>
nopl   0x0(%rax)
mov    %dl,(%rbx,%rax,1)
add    $0x1,%rax
cmp    %rax,%r14
je     11a3 <filename_unix+0x83>
movzbl (%rsp,%rax,1),%ecx
mov    $0x2f,%dl
cmp    $0x5c,%cl
je     1180 <filename_unix+0x60>
test   %cl,%cl
je     11a3 <filename_unix+0x83>
mov    %ecx,%edx
jmp    1180 <filename_unix+0x60>
xor    %ebx,%ebx
jmp    11a9 <filename_unix+0x89>
add    %rbx,%rax
movb   $0x0,(%rax)
mov    %rbx,%rax
add    $0x218,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @filename_unix(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [260 x i8]
%11 = alloca [260 x i8]
%12 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i8* null, i8** %4
br label %68
16: ; preds = %3
%17 = getelementptr inbounds [260 x i8], [260 x i8]* %10, i64 0, i64 0
%18 = load i8*, i8** %7
%19 = call i8* @env_subst(i8* %17, i32 260, i8* %18)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %16
store i8* null, i8** %4
br label %68
23: ; preds = %16
%24 = getelementptr inbounds [260 x i8], [260 x i8]* %11, i64 0, i64 0
%25 = getelementptr inbounds [260 x i8], [260 x i8]* %10, i64 0, i64 0
%26 = call i8* @filename_parameter(i8* %24, i32 260, i8* %25, i32 0)
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %23
store i8* null, i8** %4
br label %68
30: ; preds = %23
store i64 0, i64* %12
%31 = load i8*, i8** %5
store i8* %31, i8** %9
%32 = getelementptr inbounds [260 x i8], [260 x i8]* %11, i64 0, i64 0
store i8* %32, i8** %8
br label %33
33: ; preds = %62, %30
%34 = load i64, i64* %12
%35 = load i64, i64* %6
%36 = sub i64 %35, 1
%37 = icmp ult i64 %34, %36
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i8*, i8** %8
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 0
br label %43
43: ; preds = %38, %33
%44 = phi i1 [ false, %33 ], [ %42, %38 ]
br i1 %44, label %45, label %65
45: ; preds = %43
%46 = load i8*, i8** %8
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
switch i32 %48, label %54 [
i32 92, label %49
]
49: ; preds = %45
%50 = load i8*, i8** %9
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %9
store i8 47, i8* %50
%52 = load i64, i64* %12
%53 = add i64 %52, 1
store i64 %53, i64* %12
br label %61
54: ; preds = %45
%55 = load i8*, i8** %8
%56 = load i8, i8* %55
%57 = load i8*, i8** %9
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %9
store i8 %56, i8* %57
%59 = load i64, i64* %12
%60 = add i64 %59, 1
store i64 %60, i64* %12
br label %61
61: ; preds = %54, %49
br label %62
62: ; preds = %61
%63 = load i8*, i8** %8
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %8
br label %33
65: ; preds = %43
%66 = load i8*, i8** %9
store i8 0, i8* %66
%67 = load i8*, i8** %5
store i8* %67, i8** %4
br label %68
68: ; preds = %65, %29, %22, %15
%69 = load i8*, i8** %4
ret i8* %69
}

LLVM IR (-O2):
define i8* @filename_unix(i8* writeonly %0, i64 %1, i8* %2) {
%4 = alloca [260 x i8]
%5 = alloca [260 x i8]
%6 = getelementptr inbounds [260 x i8], [260 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [260 x i8], [260 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %2, null
br i1 %8, label %32, label %9
9: ; preds = %3
%10 = call i8* @env_subst(i8* %6, i32 260, i8* %2)
%11 = icmp eq i8* %10, null
br i1 %11, label %32, label %12
12: ; preds = %9
%13 = call i8* @filename_parameter(i8* %7, i32 260, i8* %6, i32 0)
%14 = icmp eq i8* %13, null
br i1 %14, label %32, label %15
15: ; preds = %12
%16 = icmp eq i64 %1, 1
br i1 %16, label %30, label %17
17: ; preds = %15
%18 = add i64 %1, -2
%19 = getelementptr [260 x i8], [260 x i8]* %5, i64 0, i64 %18
br label %20
20: ; preds = %17, %25
%21 = phi i8* [ %27, %25 ], [ %0, %17 ]
%22 = phi i8* [ %28, %25 ], [ %7, %17 ]
%23 = load i8, i8* %22
switch i8 %23, label %24 [
i8 0, label %30
i8 92, label %25
]
24: ; preds = %20
br label %25
25: ; preds = %20, %24
%26 = phi i8 [ %23, %24 ], [ 47, %20 ]
store i8 %26, i8* %21
%27 = getelementptr inbounds i8, i8* %21, i64 1
%28 = getelementptr inbounds i8, i8* %22, i64 1
%29 = icmp eq i8* %22, %19
br i1 %29, label %30, label %20
30: ; preds = %25, %20, %15
%31 = phi i8* [ %0, %15 ], [ %21, %20 ], [ %27, %25 ]
store i8 0, i8* %31
br label %32
32: ; preds = %12, %9, %3, %30
%33 = phi i8* [ %0, %30 ], [ null, %3 ], [ null, %9 ], [ null, %12 ]
ret i8* %33
}