#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*/ wchar_t;

/* Variables and functions */
int MAXPATHLEN;
int /*<<< orphan*/ alias_replace(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 size_t);
int /*<<< orphan*/ warnx(char *);
scalar_t__ wcscmp(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ wcslcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, size_t);
void alias_replace_recursive(wchar_t *out, wchar_t *path, size_t len) {
  wchar_t buf[MAXPATHLEN], *s = path;
  int i;
  for (i = 0; i < 100; i++) {
    wcslcpy(buf, s, len);
    alias_replace(out, buf, len);
    if (wcscmp(buf, out) == 0)
      return;
    s = out;
  }
  warnx("reached maximum alias_replace() recursion");
}


x86 assembly (clang, -O0):
<alias_replace_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x64,-0x34(%rbp)
jge    11f5 <alias_replace_recursive+0xb5>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <wcslcpy@plt>
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
call   1040 <alias_replace@plt>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <wcscmp@plt>
cmp    $0x0,%rax
jne    11df <alias_replace_recursive+0x9f>
movl   $0x1,-0x38(%rbp)
jmp    1208 <alias_replace_recursive+0xc8>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1190 <alias_replace_recursive+0x50>
lea    0xe04(%rip),%rdi
call   1050 <warnx@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alias_replace_recursive>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rdi,%r15
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    $0x64,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r14,%rdx
call   1060 <wcslcpy@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1040 <alias_replace@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <wcscmp@plt>
test   %rax,%rax
je     11bd <alias_replace_recursive+0x7d>
mov    %r15,%rsi
add    $0xffffffff,%ebx
jne    1180 <alias_replace_recursive+0x40>
lea    0xe48(%rip),%rdi
call   1050 <warnx@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [42 x i8] c"reached maximum alias_replace() recursion\00"
define void @alias_replace_recursive(i32* %0, i32* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
%12 = load i32, i32* @MAXPATHLEN
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i32, i64 %13
store i64 %13, i64* %8
%16 = load i32*, i32** %5
store i32* %16, i32** %9
store i32 0, i32* %10
br label %17
17: ; preds = %33, %3
%18 = load i32, i32* %10
%19 = icmp slt i32 %18, 100
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load i32*, i32** %9
%22 = load i64, i64* %6
%23 = call i32 @wcslcpy(i32* %15, i32* %21, i64 %22)
%24 = load i32*, i32** %4
%25 = load i64, i64* %6
%26 = call i32 @alias_replace(i32* %24, i32* %15, i64 %25)
%27 = load i32*, i32** %4
%28 = call i64 @wcscmp(i32* %15, i32* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %20
store i32 1, i32* %11
br label %38
31: ; preds = %20
%32 = load i32*, i32** %4
store i32* %32, i32** %9
br label %33
33: ; preds = %31
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %17
36: ; preds = %17
%37 = call i32 @warnx(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %11
br label %38
38: ; preds = %36, %30
%39 = load i8*, i8** %7
%40 = load i32, i32* %11
switch i32 %40, label %42 [
i32 0, label %41
i32 1, label %41
]
41: ; preds = %38, %38
ret void
42: ; preds = %38
unreachable
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [42 x i8] c"reached maximum alias_replace() recursion\00"
define void @alias_replace_recursive(i32* %0, i32* %1, i64 %2) {
%4 = load i32, i32* @MAXPATHLEN
%5 = zext i32 %4 to i64
%6 = alloca i32, i64 %5
br label %10
7: ; preds = %10
%8 = add nuw nsw i32 %11, 1
%9 = icmp eq i32 %8, 100
br i1 %9, label %17, label %10
10: ; preds = %3, %7
%11 = phi i32 [ 0, %3 ], [ %8, %7 ]
%12 = phi i32* [ %1, %3 ], [ %0, %7 ]
%13 = call i32 @wcslcpy(i32* %6, i32* %12, i64 %2)
%14 = call i32 @alias_replace(i32* %0, i32* %6, i64 %2)
%15 = call i64 @wcscmp(i32* %6, i32* %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %7
17: ; preds = %7
%18 = call i32 @warnx(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %10, %17
ret void
}