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

/* Variables and functions */
int /*<<< orphan*/ FixFilename(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strrchr(char *, char);
void ShowRefs(char *filename) {
  char logdir[256];
  char fn[256];
  char buf[512];
  FILE *fp;
  char *s;
  if ("logs/"[0] != '/')
    FixFilename("logs/", logdir);
  else
    strcpy(logdir, "logs/");
  s = logdir + strlen(logdir) - 1;
  if (*s != '/')
    strcat(logdir, "/");
  strcpy(fn, filename);
  s = strrchr(fn, '.');
  if (s)
    *s = '\0';
  sprintf(buf, "%s%s.ref", logdir, fn);
  fp = fopen(buf, "r");
  if (!fp)
    return;
  strcpy(buf, filename);
  s = strrchr(buf, '.');
  if (s)
    *s = '\0';
  printf("<h2>Reference URL's for %s.html</h2>\n<ul>\n", buf);
  while (!feof(fp)) {
    if (fgets(buf, 511, fp)) {
      s = buf + strlen(buf) - 1;
      if (*s == '\n')
        *s = '\0';
      printf("<li><a href=\"%s\">%s</a><br>\n", buf, buf);
    }
  }
  fclose(fp);
  puts("</ul><hr>");
}


x86 assembly (clang, -O0):
<ShowRefs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rsi
lea    0xe23(%rip),%rdi
call   10e0 <FixFilename@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x110(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x428(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     123c <ShowRefs+0x7c>
lea    -0x110(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   10c0 <strcat@plt>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rdi
mov    $0x2e,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     127c <ShowRefs+0xbc>
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    -0x210(%rbp),%rcx
lea    0xd6e(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    0xd64(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    12ca <ShowRefs+0x10a>
jmp    13ec <ShowRefs+0x22c>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
mov    $0x2e,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
je     130a <ShowRefs+0x14a>
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rsi
lea    0xcf9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x418(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1340 <ShowRefs+0x180>
jmp    13d4 <ShowRefs+0x214>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x1ff,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     13cf <ShowRefs+0x20f>
lea    -0x410(%rbp),%rax
mov    %rax,-0x430(%rbp)
lea    -0x410(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x430(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    13b3 <ShowRefs+0x1f3>
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rsi
lea    -0x410(%rbp),%rdx
lea    0xc74(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    131f <ShowRefs+0x15f>
mov    -0x418(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xc72(%rip),%rdi
call   1040 <puts@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ShowRefs>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
lea    0xe2a(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10e0 <FixFilename@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rsp,%rax,1)
je     1201 <ShowRefs+0x41>
lea    0xe0b(%rip),%rsi
mov    %rsp,%rdi
call   10c0 <strcat@plt>
lea    0x300(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1080 <strrchr@plt>
test   %rax,%rax
je     1229 <ShowRefs+0x69>
movb   $0x0,(%rax)
lea    0xdd6(%rip),%rsi
lea    0x100(%rsp),%rbx
mov    %rsp,%rdx
lea    0x300(%rsp),%rcx
mov    %rbx,%rdi
call   10d0 <sprintf@plt>
lea    0xdbd(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12c0 <ShowRefs+0x100>
mov    %rax,%rbx
lea    0x100(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    $0x2e,%esi
call   1080 <strrchr@plt>
test   %rax,%rax
je     128a <ShowRefs+0xca>
movb   $0x0,(%rax)
lea    0xd80(%rip),%rdi
lea    0x100(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     12cd <ShowRefs+0x10d>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xd9e(%rip),%rdi
call   1040 <puts@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0x100(%rsp),%r14
lea    0xd60(%rip),%r15
jmp    12fc <ShowRefs+0x13c>
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    12ac <ShowRefs+0xec>
mov    %r14,%rdi
mov    $0x1ff,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12f0 <ShowRefs+0x130>
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0xa,0xff(%rsp,%rax,1)
0a
jne    12e0 <ShowRefs+0x120>
movb   $0x0,0xff(%rsp,%rax,1)
jmp    12e0 <ShowRefs+0x120>

LLVM IR (-O0):
@.str = [6 x i8] c"logs/\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [9 x i8] c"%s%s.ref\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [43 x i8] c"<h2>Reference URL's for %s.html</h2>\0A<ul>\0A\00"
@.str.5 = [29 x i8] c"<li><a href=\22%s\22>%s</a><br>\0A\00"
@.str.6 = [10 x i8] c"</ul><hr>\00"
define void @ShowRefs(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca [512 x i8]
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = call i32 @FixFilename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 -1
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 47
br i1 %19, label %20, label %23
20: ; preds = %1
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %20, %1
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = load i8*, i8** %2
%26 = call i32 @strcpy(i8* %24, i8* %25)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%28 = call i8* @strrchr(i8* %27, i8 signext 46)
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = load i8*, i8** %7
store i8 0, i8* %32
br label %33
33: ; preds = %31, %23
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%37 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %36)
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %6
%40 = load i32*, i32** %6
%41 = icmp ne i32* %40, null
br i1 %41, label %43, label %42
42: ; preds = %33
br label %88
43: ; preds = %33
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%45 = load i8*, i8** %2
%46 = call i32 @strcpy(i8* %44, i8* %45)
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%48 = call i8* @strrchr(i8* %47, i8 signext 46)
store i8* %48, i8** %7
%49 = load i8*, i8** %7
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %53
51: ; preds = %43
%52 = load i8*, i8** %7
store i8 0, i8* %52
br label %53
53: ; preds = %51, %43
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%55 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %83, %53
%57 = load i32*, i32** %6
%58 = call i32 @feof(i32* %57)
%59 = icmp ne i32 %58, 0
%60 = xor i1 %59, true
br i1 %60, label %61, label %84
61: ; preds = %56
%62 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%63 = load i32*, i32** %6
%64 = call i64 @fgets(i8* %62, i32 511, i32* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %83
66: ; preds = %61
%67 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%68 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%69 = call i32 @strlen(i8* %68)
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %67, i64 %70
%72 = getelementptr inbounds i8, i8* %71, i64 -1
store i8* %72, i8** %7
%73 = load i8*, i8** %7
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 10
br i1 %76, label %77, label %79
77: ; preds = %66
%78 = load i8*, i8** %7
store i8 0, i8* %78
br label %79
79: ; preds = %77, %66
%80 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%81 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%82 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %80, i8* %81)
br label %83
83: ; preds = %79, %61
br label %56
84: ; preds = %56
%85 = load i32*, i32** %6
%86 = call i32 @fclose(i32* %85)
%87 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %88
88: ; preds = %84, %42
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"logs/\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [9 x i8] c"%s%s.ref\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [43 x i8] c"<h2>Reference URL's for %s.html</h2>\0A<ul>\0A\00"
@.str.5 = [29 x i8] c"<li><a href=\22%s\22>%s</a><br>\0A\00"
@.str.6 = [10 x i8] c"</ul><hr>\00"
define void @ShowRefs(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = call i32 @FixFilename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5)
%9 = call i32 @strlen(i8* %5)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
br i1 %14, label %17, label %15
15: ; preds = %1
%16 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %1
%18 = call i32 @strcpy(i8* %6, i8* %0)
%19 = call i8* @strrchr(i8* %6, i8 signext 46)
%20 = icmp eq i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %17
store i8 0, i8* %19
br label %22
22: ; preds = %21, %17
%23 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %6)
%24 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %54, label %26
26: ; preds = %22
%27 = call i32 @strcpy(i8* %7, i8* %0)
%28 = call i8* @strrchr(i8* %7, i8 signext 46)
%29 = icmp eq i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %26
store i8 0, i8* %28
br label %31
31: ; preds = %30, %26
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%33 = call i32 @feof(i32* %24)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %51
35: ; preds = %31, %48
%36 = call i64 @fgets(i8* %7, i32 511, i32* %24)
%37 = icmp eq i64 %36, 0
br i1 %37, label %48, label %38
38: ; preds = %35
%39 = call i32 @strlen(i8* %7)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 -1
%43 = load i8, i8* %42
%44 = icmp eq i8 %43, 10
br i1 %44, label %45, label %46
45: ; preds = %38
store i8 0, i8* %42
br label %46
46: ; preds = %45, %38
%47 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %7, i8* %7)
br label %48
48: ; preds = %46, %35
%49 = call i32 @feof(i32* %24)
%50 = icmp eq i32 %49, 0
br i1 %50, label %35, label %51
51: ; preds = %48, %31
%52 = call i32 @fclose(i32* %24)
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %54
54: ; preds = %22, %51
ret void
}