#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 */
scalar_t__ _stricmp(char *, char *);
int /*<<< orphan*/ fileExists(char *);
int /*<<< orphan*/ getAliasInfo(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strrchr(char *, char);
int getAliasName(const char *name, char *newname) {
  char *dotp = NULL, *targetname = (char *)name;
  char tmp[(255)], desc[(255)];
  if (name == NULL || newname == NULL)
    return 0;
  tmp[0] = '\0';
  dotp = strrchr(targetname, '.');
  if (dotp == NULL || (dotp != NULL && _stricmp(dotp, ".lnk") != 0)) {
    strcpy(tmp, name);
    strcat(tmp, ".lnk");
    targetname = tmp;
  }
  if (!fileExists(targetname)) {
    newname = NULL;
    return 0;
  }
  if (!getAliasInfo(targetname, newname, desc)) {
    newname[0] = '\0';
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<getAliasName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1199 <getAliasName+0x39>
cmpq   $0x0,-0x18(%rbp)
jne    11a5 <getAliasName+0x45>
movl   $0x0,-0x4(%rbp)
jmp    1279 <getAliasName+0x119>
movb   $0x0,-0x130(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ee <getAliasName+0x8e>
cmpq   $0x0,-0x20(%rbp)
je     121c <getAliasName+0xbc>
mov    -0x20(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1070 <_stricmp@plt>
cmp    $0x0,%rax
je     121c <getAliasName+0xbc>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x130(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x130(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fileExists@plt>
cmp    $0x0,%eax
jne    1242 <getAliasName+0xe2>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    1279 <getAliasName+0x119>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x230(%rbp),%rdx
call   1040 <getAliasInfo@plt>
cmp    $0x0,%eax
jne    1272 <getAliasName+0x112>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1279 <getAliasName+0x119>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAliasName>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
xor    %ebp,%ebp
test   %rdi,%rdi
je     11f8 <getAliasName+0x98>
mov    %rsi,%r14
test   %rsi,%rsi
je     11f8 <getAliasName+0x98>
mov    %rdi,%rbx
movb   $0x0,(%rsp)
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     11aa <getAliasName+0x4a>
lea    0xe63(%rip),%rsi
mov    %rax,%rdi
call   1070 <_stricmp@plt>
test   %rax,%rax
je     11ca <getAliasName+0x6a>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe41(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
mov    %r15,%rbx
mov    %rbx,%rdi
call   1050 <fileExists@plt>
test   %eax,%eax
je     11f8 <getAliasName+0x98>
lea    0x100(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <getAliasInfo@plt>
mov    $0x1,%ebp
test   %eax,%eax
jne    11f8 <getAliasName+0x98>
movb   $0x0,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".lnk\00"
define i32 @getAliasName(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [255 x i8]
%9 = alloca [255 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%10 = load i8*, i8** %4
store i8* %10, i8** %7
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13, %2
store i32 0, i32* %3
br label %52
17: ; preds = %13
%18 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
store i8 0, i8* %18
%19 = load i8*, i8** %7
%20 = call i8* @strrchr(i8* %19, i8 signext 46)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp eq i8* %21, null
br i1 %22, label %30, label %23
23: ; preds = %17
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %37
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = call i64 @_stricmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %26, %17
%31 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%32 = load i8*, i8** %4
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
store i8* %36, i8** %7
br label %37
37: ; preds = %30, %26, %23
%38 = load i8*, i8** %7
%39 = call i32 @fileExists(i8* %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %37
store i8* null, i8** %5
store i32 0, i32* %3
br label %52
42: ; preds = %37
%43 = load i8*, i8** %7
%44 = load i8*, i8** %5
%45 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%46 = call i32 @getAliasInfo(i8* %43, i8* %44, i8* %45)
%47 = icmp ne i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %42
%49 = load i8*, i8** %5
%50 = getelementptr inbounds i8, i8* %49, i64 0
store i8 0, i8* %50
store i32 0, i32* %3
br label %52
51: ; preds = %42
store i32 1, i32* %3
br label %52
52: ; preds = %51, %48, %41, %16
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [5 x i8] c".lnk\00"
define i32 @getAliasName(i8* %0, i8* %1) {
%3 = alloca [255 x i8]
%4 = alloca [255 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%7 = icmp eq i8* %0, null
%8 = icmp eq i8* %1, null
%9 = or i1 %7, %8
br i1 %9, label %27, label %10
10: ; preds = %2
store i8 0, i8* %5
%11 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i64 @_stricmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13, %10
%17 = call i32 @strcpy(i8* %5, i8* %0)
%18 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %13
%20 = phi i8* [ %5, %16 ], [ %0, %13 ]
%21 = call i32 @fileExists(i8* %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = call i32 @getAliasInfo(i8* %20, i8* %1, i8* %6)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23
store i8 0, i8* %1
br label %27
27: ; preds = %23, %19, %2, %26
%28 = phi i32 [ 0, %26 ], [ 0, %2 ], [ 0, %19 ], [ 1, %23 ]
ret i32 %28
}