#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*/ DEBUG_Msg(char *);
char *GetPathComponents(int, char *);
char *GetValue(char *, char *);
int /*<<< orphan*/ MSG_Error_General(char *);
char *getenv(char *);
char *FetchUserString(void) {
  char *pathInfoString;
  char *queryString;
  char *userStr;
  DEBUG_Msg("\n");
  userStr = (char *)0;
  pathInfoString = getenv("PATH_INFO");
  if (pathInfoString) {
    if (pathInfoString[0] != 0) {
      DEBUG_Msg("Trying to extract user from PATH_INFO.");
      userStr = GetPathComponents(1, pathInfoString);
    } else {
      DEBUG_Msg("PATH_INFO is empty, can't check.");
    }
  }
  queryString = getenv("QUERY_STRING");
  if (!userStr && queryString) {
    if (queryString[0] != 0) {
      DEBUG_Msg("Trying to extract user from QUERY_STRING");
      DEBUG_Msg("Read in user keyword value");
      userStr = GetValue("user", getenv("QUERY_STRING"));
    } else {
      DEBUG_Msg("QUERY_STRING is empty, can't check.");
    }
  }
  if (userStr) {
    if (userStr[0] == '~') {
      userStr++;
    }
  }
  if (!userStr) {
    MSG_Error_General("Couldn't find user and script name, check your URL.");
  }
  return userStr;
}


x86 assembly (clang, -O0):
<FetchUserString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
movq   $0x0,-0x18(%rbp)
lea    0xe8f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11cb <FetchUserString+0x7b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ba <FetchUserString+0x6a>
lea    0xe6e(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
mov    -0x8(%rbp),%rsi
mov    $0x1,%edi
call   1040 <GetPathComponents@plt>
mov    %rax,-0x18(%rbp)
jmp    11c6 <FetchUserString+0x76>
lea    0xe72(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
jmp    11cb <FetchUserString+0x7b>
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124e <FetchUserString+0xfe>
cmpq   $0x0,-0x10(%rbp)
je     124e <FetchUserString+0xfe>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     123d <FetchUserString+0xed>
lea    0xe4c(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
lea    0xe69(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
lea    0xe50(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe69(%rip),%rdi
call   1050 <GetValue@plt>
mov    %rax,-0x18(%rbp)
jmp    1249 <FetchUserString+0xf9>
lea    0xe59(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
jmp    124e <FetchUserString+0xfe>
cmpq   $0x0,-0x18(%rbp)
je     127a <FetchUserString+0x12a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    1275 <FetchUserString+0x125>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    127a <FetchUserString+0x12a>
cmpq   $0x0,-0x18(%rbp)
jne    1291 <FetchUserString+0x141>
lea    0xe35(%rip),%rdi
call   1070 <MSG_Error_General@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FetchUserString>:
push   %rbx
lea    0xea8(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a0 <FetchUserString+0x50>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1194 <FetchUserString+0x44>
lea    0xe8f(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1040 <GetPathComponents@plt>
mov    %rax,%rbx
jmp    11a2 <FetchUserString+0x52>
lea    0xe98(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
xor    %ebx,%ebx
lea    0xec7(%rip),%rdi
call   1030 <getenv@plt>
test   %rbx,%rbx
jne    11f3 <FetchUserString+0xa3>
test   %rax,%rax
je     11f3 <FetchUserString+0xa3>
cmpb   $0x0,(%rax)
je     1205 <FetchUserString+0xb5>
lea    0xe90(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
lea    0xead(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
lea    0xe94(%rip),%rdi
call   1030 <getenv@plt>
lea    0xeb0(%rip),%rdi
mov    %rax,%rsi
call   1050 <GetValue@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     1211 <FetchUserString+0xc1>
xor    %eax,%eax
cmpb   $0x7e,(%rbx)
sete   %al
add    %rbx,%rax
pop    %rbx
ret
lea    0xe91(%rip),%rdi
call   1060 <DEBUG_Msg@plt>
lea    0xea9(%rip),%rdi
call   1070 <MSG_Error_General@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [10 x i8] c"PATH_INFO\00"
@.str.2 = [39 x i8] c"Trying to extract user from PATH_INFO.\00"
@.str.3 = [33 x i8] c"PATH_INFO is empty, can't check.\00"
@.str.4 = [13 x i8] c"QUERY_STRING\00"
@.str.5 = [41 x i8] c"Trying to extract user from QUERY_STRING\00"
@.str.6 = [27 x i8] c"Read in user keyword value\00"
@.str.7 = [5 x i8] c"user\00"
@.str.8 = [36 x i8] c"QUERY_STRING is empty, can't check.\00"
@.str.9 = [52 x i8] c"Couldn't find user and script name, check your URL.\00"
define i8* @FetchUserString() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i32 @DEBUG_Msg(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
%5 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i8* %5, i8** %1
%6 = load i8*, i8** %1
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %21
8: ; preds = %0
%9 = load i8*, i8** %1
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %8
%15 = call i32 @DEBUG_Msg(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%16 = load i8*, i8** %1
%17 = call i8* @GetPathComponents(i32 1, i8* %16)
store i8* %17, i8** %3
br label %20
18: ; preds = %8
%19 = call i32 @DEBUG_Msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
br label %21
21: ; preds = %20, %0
%22 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i8* %22, i8** %2
%23 = load i8*, i8** %3
%24 = icmp ne i8* %23, null
br i1 %24, label %42, label %25
25: ; preds = %21
%26 = load i8*, i8** %2
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %42
28: ; preds = %25
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = call i32 @DEBUG_Msg(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @DEBUG_Msg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%37 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%38 = call i8* @GetValue(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %37)
store i8* %38, i8** %3
br label %41
39: ; preds = %28
%40 = call i32 @DEBUG_Msg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
br label %41
41: ; preds = %39, %34
br label %42
42: ; preds = %41, %25, %21
%43 = load i8*, i8** %3
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %55
45: ; preds = %42
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 126
br i1 %50, label %51, label %54
51: ; preds = %45
%52 = load i8*, i8** %3
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %3
br label %54
54: ; preds = %51, %45
br label %55
55: ; preds = %54, %42
%56 = load i8*, i8** %3
%57 = icmp ne i8* %56, null
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = call i32 @MSG_Error_General(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.9, i64 0, i64 0))
br label %60
60: ; preds = %58, %55
%61 = load i8*, i8** %3
ret i8* %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [10 x i8] c"PATH_INFO\00"
@.str.2 = [39 x i8] c"Trying to extract user from PATH_INFO.\00"
@.str.3 = [33 x i8] c"PATH_INFO is empty, can't check.\00"
@.str.4 = [13 x i8] c"QUERY_STRING\00"
@.str.5 = [41 x i8] c"Trying to extract user from QUERY_STRING\00"
@.str.6 = [27 x i8] c"Read in user keyword value\00"
@.str.7 = [5 x i8] c"user\00"
@.str.8 = [36 x i8] c"QUERY_STRING is empty, can't check.\00"
@.str.9 = [52 x i8] c"Couldn't find user and script name, check your URL.\00"
define i8* @FetchUserString() {
%1 = tail call i32 @DEBUG_Msg(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %0
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @DEBUG_Msg(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i8* @GetPathComponents(i32 1, i8* %2)
br label %12
10: ; preds = %4
%11 = tail call i32 @DEBUG_Msg(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %7, %10, %0
%13 = phi i8* [ %9, %7 ], [ null, %10 ], [ null, %0 ]
%14 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%15 = icmp eq i8* %13, null
%16 = icmp ne i8* %14, null
%17 = and i1 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %12
%19 = load i8, i8* %14
%20 = icmp eq i8 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = tail call i32 @DEBUG_Msg(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%23 = tail call i32 @DEBUG_Msg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%24 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%25 = tail call i8* @GetValue(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %24)
br label %28
26: ; preds = %18
%27 = tail call i32 @DEBUG_Msg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
br label %36
28: ; preds = %21, %12
%29 = phi i8* [ %25, %21 ], [ %13, %12 ]
%30 = icmp eq i8* %29, null
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = load i8, i8* %29
%33 = icmp eq i8 %32, 126
%34 = zext i1 %33 to i64
%35 = getelementptr i8, i8* %29, i64 %34
br label %38
36: ; preds = %26, %28
%37 = tail call i32 @MSG_Error_General(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.9, i64 0, i64 0))
br label %38
38: ; preds = %31, %36
%39 = phi i8* [ null, %36 ], [ %35, %31 ]
ret i8* %39
}