// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/lib/cheapcgi.c
// Function: cgiClientBrowser
enum browserType cgiClientBrowser(char **browserQualifier, enum osType *clientOs,
                                  char **clientOsQualifier)
/* Return client browser type determined from (HTTP_USER_AGENT)
   Optionally requuest the additional info about the client */
{
// WARNING: The specifics of the HTTP_USER_AGENT vary widely.
//          This has only been tested on a few cases.
static enum browserType clientBrowser = btUnknown;
static enum browserType clientOsType  = (enum browserType)osUnknown;
static char *clientBrowserExtra       = NULL;
static char *clientOsExtra            = NULL;

if (clientBrowser == btUnknown)
    {
    char *userAgent = cgiUserAgent();
    if (userAgent != NULL)
        {
        //warn(userAgent);  // Use this to investigate other cases
        char *ptr=NULL;

        // Determine the browser
        if ((ptr = stringIn("Opera",userAgent)) != NULL) // Must be before IE
            {
            clientBrowser = btOpera;
            }
        else if ((ptr = stringIn("MSIE ",userAgent)) != NULL)
            {
            clientBrowser = btIE;
            ptr += strlen("MSIE ");
            clientBrowserExtra = cloneFirstWordByDelimiter(ptr,';');
            }
        else if ((ptr = stringIn("Firefox",userAgent)) != NULL)
            {
            clientBrowser = btFF;
            ptr += strlen("(Firefox/");
            clientBrowserExtra = cloneFirstWordByDelimiter(ptr,' ');
            }
        else if ((ptr = stringIn("Chrome",userAgent)) != NULL)  // Must be before Safari
            {
            clientBrowser = btChrome;
            ptr += strlen("Chrome/");
            clientBrowserExtra = cloneFirstWordByDelimiter(ptr,' ');
            }
        else if ((ptr = stringIn("Safari",userAgent)) != NULL)
            {
            clientBrowser = btSafari;
            ptr += strlen("Safari/");
            clientBrowserExtra = cloneFirstWordByDelimiter(ptr,' ');
            }
        else
            {
            clientBrowser = btOther;
            }

        // Determine the OS
        if ((ptr = stringIn("Windows",userAgent)) != NULL)
            {
            clientOsType = (enum browserType)osWindows;
            ptr += strlen("Windows ");
            clientOsExtra = cloneFirstWordByDelimiter(ptr,';');
            }
        else if ((ptr = stringIn("Linux",userAgent)) != NULL)
            {
            clientOsType = (enum browserType)osLinux;
            ptr += strlen("Linux ");
            clientOsExtra = cloneFirstWordByDelimiter(ptr,';');
            }
        else if ((ptr = stringIn("Mac ",userAgent)) != NULL)
            {
            clientOsType = (enum browserType)osMac;
            ptr += strlen("Mac ");
            clientOsExtra = cloneFirstWordByDelimiter(ptr,';');
            }
        else
            {
            clientOsType = (enum browserType)osOther;
            }
        }
    }
if (browserQualifier != NULL)
    {
    if (clientBrowserExtra != NULL)
        *browserQualifier = cloneString(clientBrowserExtra);
    else
        *browserQualifier = NULL;
    }
if (clientOs != NULL)
    *clientOs = (enum osType)clientOsType;
if (clientOsQualifier != NULL)
    {
    if (clientOsExtra != NULL)
        *clientOsQualifier = cloneString(clientOsExtra);
    else
        *clientOsQualifier = NULL;
    }

return clientBrowser;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
cmpl $0x0, 0x7fcb6(%rip)     # 0xc4248
jne 0x446fb
leaq 0x51788(%rip), %rdi     # 0x95d27
callq 0x68f0
testq %rax, %rax
je 0x446fb
movq %rax, %r12
leaq 0x51780(%rip), %rsi     # 0x95d37
movq %rax, %rdi
callq 0x6180
testq %rax, %rax
je 0x445d3
movl $0x1, 0x7fc7a(%rip)     # 0xc4248
jmp 0x4467d
leaq 0x51763(%rip), %rsi     # 0x95d3d
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x445ff
movl $0x2, 0x7fc57(%rip)     # 0xc4248
addq $0x5, %rax
movq %rax, %rdi
movl $0x3b, %esi
jmp 0x44671
leaq 0x5173d(%rip), %rsi     # 0x95d43
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x44623
movl $0x3, 0x7fc2b(%rip)     # 0xc4248
addq $0x9, %rax
jmp 0x44669
leaq 0x51721(%rip), %rsi     # 0x95d4b
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x44643
movl $0x4, 0x7fc07(%rip)     # 0xc4248
jmp 0x44665
leaq 0x51708(%rip), %rsi     # 0x95d52
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x44761
movl $0x5, 0x7fbe3(%rip)     # 0xc4248
addq $0x7, %rax
movq %rax, %rdi
movl $0x20, %esi
callq 0x22e4f
movq %rax, 0x7fbd3(%rip)     # 0xc4250
leaq 0x516d5(%rip), %rsi     # 0x95d59
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x446a1
movl $0x1, 0x7fbb1(%rip)     # 0xc424c
addq $0x8, %rax
jmp 0x446e7
leaq 0x516b9(%rip), %rsi     # 0x95d61
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x446c5
movl $0x2, 0x7fb8d(%rip)     # 0xc424c
addq $0x6, %rax
jmp 0x446e7
leaq 0x5169b(%rip), %rsi     # 0x95d67
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x44755
movl $0x3, 0x7fb69(%rip)     # 0xc424c
addq $0x4, %rax
movq %rax, %rdi
movl $0x3b, %esi
callq 0x22e4f
movq %rax, 0x7fb5d(%rip)     # 0xc4258
testq %r15, %r15
je 0x44718
movq 0x7fb49(%rip), %rdi     # 0xc4250
testq %rdi, %rdi
je 0x44713
callq 0x1feba
jmp 0x44715
xorl %eax, %eax
movq %rax, (%r15)
testq %r14, %r14
je 0x44726
movl 0x7fb29(%rip), %eax     # 0xc424c
movl %eax, (%r14)
testq %rbx, %rbx
je 0x44743
movq 0x7fb26(%rip), %rdi     # 0xc4258
testq %rdi, %rdi
je 0x4473e
callq 0x1feba
jmp 0x44740
xorl %eax, %eax
movq %rax, (%rbx)
movl 0x7faff(%rip), %eax     # 0xc4248
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movl $0x4, 0x7faed(%rip)     # 0xc424c
jmp 0x446fb
movl $0x6, 0x7fadd(%rip)     # 0xc4248
jmp 0x4467d