#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 character_count(char, char *);
int /*<<< orphan*/ environ_name_to_value(char *, char *);
int /*<<< orphan*/ piece(char *, char, char *, int);
char *environ_get_http_referer_filename(void) {
  char http_referer_with_parameter[512];
  char http_referer_with_pathname[512];
  static char http_referer_filename[512];
  int ch_count;
  if (!environ_name_to_value(http_referer_with_parameter, "HTTP_REFERER")) {
    return (char *)0;
  } else {
    piece(http_referer_with_pathname, '?', http_referer_with_parameter, 0);
    ch_count = character_count('/', http_referer_with_pathname);
    piece(http_referer_filename, '/', http_referer_with_pathname, ch_count);
    return http_referer_filename;
  }
}


x86 assembly (clang, -O0):
<environ_get_http_referer_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    -0x210(%rbp),%rdi
lea    0xeb7(%rip),%rsi
call   1040 <environ_name_to_value@plt>
cmp    $0x0,%eax
jne    1164 <environ_get_http_referer_filename+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11be <environ_get_http_referer_filename+0x8e>
lea    -0x410(%rbp),%rdi
lea    -0x210(%rbp),%rdx
mov    $0x3f,%esi
xor    %ecx,%ecx
call   1050 <piece@plt>
lea    -0x410(%rbp),%rsi
mov    $0x2f,%edi
call   1030 <character_count@plt>
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rdx
mov    -0x414(%rbp),%ecx
lea    0x2ea7(%rip),%rdi
mov    $0x2f,%esi
call   1050 <piece@plt>
lea    0x2e96(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<environ_get_http_referer_filename>:
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xebf(%rip),%rsi
mov    %rsp,%rdi
call   1040 <environ_name_to_value@plt>
test   %eax,%eax
je     118f <environ_get_http_referer_filename+0x5f>
lea    0x200(%rsp),%r14
mov    %rsp,%rdx
mov    %r14,%rdi
mov    $0x3f,%esi
xor    %ecx,%ecx
call   1050 <piece@plt>
mov    $0x2f,%edi
mov    %r14,%rsi
call   1030 <character_count@plt>
lea    0x2ed5(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
mov    %r14,%rdx
mov    %eax,%ecx
call   1050 <piece@plt>
jmp    1191 <environ_get_http_referer_filename+0x61>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@environ_get_http_referer_filename.http_referer_filename = internal global [512 x i8] zeroinitializer
@.str = [13 x i8] c"HTTP_REFERER\00"
define i8* @environ_get_http_referer_filename() {
%1 = alloca i8*
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = call i32 @environ_name_to_value(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %0
store i8* null, i8** %1
br label %18
9: ; preds = %0
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%12 = call i32 @piece(i8* %10, i8 signext 63, i8* %11, i32 0)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%14 = call i32 @character_count(i8 signext 47, i8* %13)
store i32 %14, i32* %4
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%16 = load i32, i32* %4
%17 = call i32 @piece(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @environ_get_http_referer_filename.http_referer_filename, i64 0, i64 0), i8 signext 47, i8* %15, i32 %16)
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @environ_get_http_referer_filename.http_referer_filename, i64 0, i64 0), i8** %1
br label %18
18: ; preds = %9, %8
%19 = load i8*, i8** %1
ret i8* %19
}

LLVM IR (-O2):
@environ_get_http_referer_filename.http_referer_filename = internal global [512 x i8] zeroinitializer
@.str = [13 x i8] c"HTTP_REFERER\00"
define i8* @environ_get_http_referer_filename() {
%1 = alloca [512 x i8]
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = call i32 @environ_name_to_value(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = call i32 @piece(i8* %4, i8 signext 63, i8* %3, i32 0)
%9 = call i32 @character_count(i8 signext 47, i8* %4)
%10 = call i32 @piece(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @environ_get_http_referer_filename.http_referer_filename, i64 0, i64 0), i8 signext 47, i8* %4, i32 %9)
br label %11
11: ; preds = %0, %7
%12 = phi i8* [ getelementptr inbounds ([512 x i8], [512 x i8]* @environ_get_http_referer_filename.http_referer_filename, i64 0, i64 0), %7 ], [ null, %0 ]
ret i8* %12
}