#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 */
int /*<<< orphan*/ R_OK;
int /*<<< orphan*/ _IOLBF;
scalar_t__ access(char *, int /*<<< orphan*/);
int chdir(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/,
                   int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strchr(char *, char);
char *strrchr(char *, char);
scalar_t__ tolower(int);
int main() {
  char buf[(16 * 1024)];
  char *s, *t;
  int tlu = 0;
  if (setvbuf(stdout, NULL, _IOLBF, 0) != 0)
    return 1;
  if (chdir("/var/lib/httpd/htdocs/local/rredir") == -1)
    return 1;
  while (fgets(buf, (16 * 1024), stdin) != NULL) {
    if (strchr(buf, '\n') == NULL) {
      tlu = 1;
      continue;
    }
    if (tlu)
      goto dont_redirect;
    if ((s = strchr(buf, ' ')) == NULL)
      goto dont_redirect;
    *s = '\0';
    if ((s = strrchr(buf, '/')) == NULL)
      goto dont_redirect;
    s++;
    if (*s == '.' || *s == '\0')
      goto dont_redirect;
    for (t = s; *t != '\0'; t++)
      *t = (char)tolower((int)*t);
    if (access(s, R_OK) == 0) {
      (void)printf("%s/%s\n", "http://www.hacom.nl/local/rredir", s);
      continue;
    }
  dont_redirect:
    tlu = 0;
    (void)printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4030,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x4024(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1090 <setvbuf@plt>
cmp    $0x0,%rax
je     11cf <main+0x4f>
movl   $0x1,-0x4(%rbp)
jmp    13a5 <main+0x225>
lea    0xe2a(%rip),%rdi
call   1030 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11f0 <main+0x70>
movl   $0x1,-0x4(%rbp)
jmp    13a5 <main+0x225>
jmp    11f5 <main+0x75>
lea    -0x4010(%rbp),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%edx
mov    $0x4000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     139e <main+0x21e>
lea    -0x4010(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1243 <main+0xc3>
movl   $0x1,-0x4024(%rbp)
jmp    11f5 <main+0x75>
cmpl   $0x0,-0x4024(%rbp)
je     1255 <main+0xd5>
jmp    1381 <main+0x201>
lea    -0x4010(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x4018(%rbp)
cmp    $0x0,%rax
jne    127c <main+0xfc>
jmp    1381 <main+0x201>
mov    -0x4018(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x4010(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x4018(%rbp)
cmp    $0x0,%rax
jne    12ad <main+0x12d>
jmp    1381 <main+0x201>
mov    -0x4018(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x4018(%rbp)
mov    -0x4018(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     12e5 <main+0x165>
mov    -0x4018(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12ea <main+0x16a>
jmp    1381 <main+0x201>
mov    -0x4018(%rbp),%rax
mov    %rax,-0x4020(%rbp)
mov    -0x4020(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     133c <main+0x1bc>
mov    -0x4020(%rbp),%rax
movsbl (%rax),%edi
call   1080 <tolower@plt>
mov    %al,%cl
mov    -0x4020(%rbp),%rax
mov    %cl,(%rax)
mov    -0x4020(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x4020(%rbp)
jmp    12f8 <main+0x178>
mov    -0x4018(%rbp),%rdi
mov    0x2c7e(%rip),%rax
mov    (%rax),%esi
call   10a0 <access@plt>
cmp    $0x0,%rax
jne    137c <main+0x1fc>
mov    -0x4018(%rbp),%rdx
lea    0xcba(%rip),%rdi
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f5 <main+0x75>
jmp    1381 <main+0x201>
movl   $0x0,-0x4024(%rbp)
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f5 <main+0x75>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4008,%rsp
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   10a0 <setvbuf@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11da <main+0x4a>
mov    %ebx,%eax
add    $0x4008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1f(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     11c6 <main+0x36>
mov    0x2df6(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x4000,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     12ec <main+0x15c>
mov    $0x1,%bpl
mov    %rsp,%r14
mov    0x2db0(%rip),%r12
xor    %ebx,%ebx
jmp    1237 <main+0xa7>
nopl   0x0(%rax)
xor    %ebp,%ebp
mov    (%r15),%edx
mov    %r14,%rdi
mov    $0x4000,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     11c6 <main+0x36>
mov    %r14,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1220 <main+0x90>
test   $0x1,%bpl
je     12c0 <main+0x130>
mov    %r14,%rdi
mov    $0x20,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     12c0 <main+0x130>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     12c0 <main+0x130>
mov    %rax,%rbp
mov    0x1(%rax),%al
test   %al,%al
je     12c0 <main+0x130>
cmp    $0x2e,%al
je     12c0 <main+0x130>
lea    0x1(%rbp),%r13
add    $0x2,%rbp
nopl   0x0(%rax)
movsbl %al,%edi
call   1090 <tolower@plt>
mov    %al,-0x1(%rbp)
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    1290 <main+0x100>
mov    (%r12),%esi
mov    %r13,%rdi
call   10b0 <access@plt>
test   %rax,%rax
je     12d2 <main+0x142>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%bpl
jmp    1222 <main+0x92>
lea    0xd4a(%rip),%rdi
lea    0xd4a(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12ca <main+0x13a>
xor    %ebx,%ebx
jmp    11c6 <main+0x36>

LLVM IR (-O0):
@stdout = global i32 0
@_IOLBF = global i32 0
@.str = [35 x i8] c"/var/lib/httpd/htdocs/local/rredir\00"
@stdin = global i32 0
@R_OK = global i32 0
@.str.1 = [7 x i8] c"%s/%s\0A\00"
@.str.2 = [33 x i8] c"http://www.hacom.nl/local/rredir\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16384 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
%6 = load i32, i32* @stdout
%7 = load i32, i32* @_IOLBF
%8 = call i64 @setvbuf(i32 %6, i32* null, i32 %7, i32 0)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 1, i32* %1
br label %83
11: ; preds = %0
%12 = call i32 @chdir(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 1, i32* %1
br label %83
15: ; preds = %11
br label %16
16: ; preds = %80, %76, %25, %15
%17 = getelementptr inbounds [16384 x i8], [16384 x i8]* %2, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32* @fgets(i8* %17, i32 16384, i32 %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %82
21: ; preds = %16
%22 = getelementptr inbounds [16384 x i8], [16384 x i8]* %2, i64 0, i64 0
%23 = call i8* @strchr(i8* %22, i8 signext 10)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 1, i32* %5
br label %16
26: ; preds = %21
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
br label %80
30: ; preds = %26
%31 = getelementptr inbounds [16384 x i8], [16384 x i8]* %2, i64 0, i64 0
%32 = call i8* @strchr(i8* %31, i8 signext 32)
store i8* %32, i8** %3
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %30
br label %80
35: ; preds = %30
%36 = load i8*, i8** %3
store i8 0, i8* %36
%37 = getelementptr inbounds [16384 x i8], [16384 x i8]* %2, i64 0, i64 0
%38 = call i8* @strrchr(i8* %37, i8 signext 47)
store i8* %38, i8** %3
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %41
40: ; preds = %35
br label %80
41: ; preds = %35
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %3
%44 = load i8*, i8** %3
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 46
br i1 %47, label %53, label %48
48: ; preds = %41
%49 = load i8*, i8** %3
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %48, %41
br label %80
54: ; preds = %48
%55 = load i8*, i8** %3
store i8* %55, i8** %4
br label %56
56: ; preds = %68, %54
%57 = load i8*, i8** %4
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %71
61: ; preds = %56
%62 = load i8*, i8** %4
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = call i64 @tolower(i32 %64)
%66 = trunc i64 %65 to i8
%67 = load i8*, i8** %4
store i8 %66, i8* %67
br label %68
68: ; preds = %61
%69 = load i8*, i8** %4
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %4
br label %56
71: ; preds = %56
%72 = load i8*, i8** %3
%73 = load i32, i32* @R_OK
%74 = call i64 @access(i8* %72, i32 %73)
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = load i8*, i8** %3
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %77)
br label %16
79: ; preds = %71
br label %80
80: ; preds = %79, %53, %40, %34, %29
store i32 0, i32* %5
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %16
82: ; preds = %16
store i32 0, i32* %1
br label %83
83: ; preds = %82, %14, %10
%84 = load i32, i32* %1
ret i32 %84
}

LLVM IR (-O2):
@stdout = global i32 0
@_IOLBF = global i32 0
@.str = [35 x i8] c"/var/lib/httpd/htdocs/local/rredir\00"
@stdin = global i32 0
@R_OK = global i32 0
@.str.1 = [7 x i8] c"%s/%s\0A\00"
@.str.2 = [33 x i8] c"http://www.hacom.nl/local/rredir\00"
define i32 @main() {
%1 = alloca [16384 x i8]
%2 = getelementptr inbounds [16384 x i8], [16384 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdout
%4 = load i32, i32* @_IOLBF
%5 = tail call i64 @setvbuf(i32 %3, i32* null, i32 %4, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %50
7: ; preds = %0
%8 = tail call i32 @chdir(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32 %8, -1
br i1 %9, label %50, label %10
10: ; preds = %7
%11 = load i32, i32* @stdin
%12 = call i32* @fgets(i8* %2, i32 16384, i32 %11)
%13 = icmp eq i32* %12, null
br i1 %13, label %50, label %14
14: ; preds = %10, %43
%15 = phi i1 [ %44, %43 ], [ true, %10 ]
%16 = call i8* @strchr(i8* %2, i8 signext 10)
%17 = icmp eq i8* %16, null
br i1 %17, label %43, label %18
18: ; preds = %14
br i1 %15, label %19, label %48
19: ; preds = %18
%20 = call i8* @strchr(i8* %2, i8 signext 32)
%21 = icmp eq i8* %20, null
br i1 %21, label %48, label %22
22: ; preds = %19
store i8 0, i8* %20
%23 = call i8* @strrchr(i8* %2, i8 signext 47)
%24 = icmp eq i8* %23, null
br i1 %24, label %48, label %25
25: ; preds = %22
%26 = getelementptr inbounds i8, i8* %23, i64 1
%27 = load i8, i8* %26
switch i8 %27, label %28 [
i8 46, label %48
i8 0, label %48
]
28: ; preds = %25, %28
%29 = phi i8* [ %34, %28 ], [ %26, %25 ]
%30 = phi i8 [ %35, %28 ], [ %27, %25 ]
%31 = sext i8 %30 to i32
%32 = call i64 @tolower(i32 %31)
%33 = trunc i64 %32 to i8
store i8 %33, i8* %29
%34 = getelementptr inbounds i8, i8* %29, i64 1
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %28
37: ; preds = %28
%38 = load i32, i32* @R_OK
%39 = call i64 @access(i8* %26, i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %43
43: ; preds = %41, %48, %14
%44 = phi i1 [ true, %48 ], [ true, %41 ], [ false, %14 ]
%45 = load i32, i32* @stdin
%46 = call i32* @fgets(i8* %2, i32 16384, i32 %45)
%47 = icmp eq i32* %46, null
br i1 %47, label %50, label %14
48: ; preds = %25, %25, %37, %22, %19, %18
%49 = call i32 @putchar(i32 10)
br label %43
50: ; preds = %43, %10, %7, %0
%51 = phi i32 [ 1, %0 ], [ 1, %7 ], [ 0, %10 ], [ 0, %43 ]
ret i32 %51
}