// File: /workspace/github_c_makefile_star2_O3/JimKent[P]linearSat/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  = 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 = osWindows;
            ptr += strlen("Windows ");
            clientOsExtra = cloneFirstWordByDelimiter(ptr,';');
            }
        else if ((ptr = stringIn("Linux",userAgent)) != NULL)
            {
            clientOsType = osLinux;
            ptr += strlen("Linux ");
            clientOsExtra = cloneFirstWordByDelimiter(ptr,';');
            }
        else if ((ptr = stringIn("Mac ",userAgent)) != NULL)
            {
            clientOsType = osMac;
            ptr += strlen("Mac ");
            clientOsExtra = cloneFirstWordByDelimiter(ptr,';');
            }
        else
            {
            clientOsType = osOther;
            }
        }
    }
if (browserQualifier != NULL)
    {
    if (clientBrowserExtra != NULL)
        *browserQualifier = cloneString(clientBrowserExtra);
    else
        *browserQualifier = NULL;
    }
if (clientOs != NULL)
    *clientOs = 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, 0x1518d(%rip)     # 0x281d8
jne 0x131b4
leaq 0x86ce(%rip), %rdi      # 0x1b726
callq 0x3040
testq %rax, %rax
je 0x131b4
movq %rax, %r12
leaq 0x86c6(%rip), %rsi      # 0x1b736
movq %rax, %rdi
callq 0x3760
testq %rax, %rax
je 0x1308c
movl $0x1, 0x15151(%rip)     # 0x281d8
jmp 0x13136
leaq 0x86a9(%rip), %rsi      # 0x1b73c
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x130b8
movl $0x2, 0x1512e(%rip)     # 0x281d8
addq $0x5, %rax
movq %rax, %rdi
movl $0x3b, %esi
jmp 0x1312a
leaq 0x8683(%rip), %rsi      # 0x1b742
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x130dc
movl $0x3, 0x15102(%rip)     # 0x281d8
addq $0x9, %rax
jmp 0x13122
leaq 0x8667(%rip), %rsi      # 0x1b74a
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x130fc
movl $0x4, 0x150de(%rip)     # 0x281d8
jmp 0x1311e
leaq 0x864e(%rip), %rsi      # 0x1b751
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x1321a
movl $0x5, 0x150ba(%rip)     # 0x281d8
addq $0x7, %rax
movq %rax, %rdi
movl $0x20, %esi
callq 0x914f
movq %rax, 0x150aa(%rip)     # 0x281e0
leaq 0x861b(%rip), %rsi      # 0x1b758
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x1315a
movl $0x1, 0x15088(%rip)     # 0x281dc
addq $0x8, %rax
jmp 0x131a0
leaq 0x85ff(%rip), %rsi      # 0x1b760
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x1317e
movl $0x2, 0x15064(%rip)     # 0x281dc
addq $0x6, %rax
jmp 0x131a0
leaq 0x85e1(%rip), %rsi      # 0x1b766
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x1320e
movl $0x3, 0x15040(%rip)     # 0x281dc
addq $0x4, %rax
movq %rax, %rdi
movl $0x3b, %esi
callq 0x914f
movq %rax, 0x15034(%rip)     # 0x281e8
testq %r15, %r15
je 0x131d1
movq 0x15020(%rip), %rdi     # 0x281e0
testq %rdi, %rdi
je 0x131cc
callq 0x6402
jmp 0x131ce
xorl %eax, %eax
movq %rax, (%r15)
testq %r14, %r14
je 0x131df
movl 0x15000(%rip), %eax     # 0x281dc
movl %eax, (%r14)
testq %rbx, %rbx
je 0x131fc
movq 0x14ffd(%rip), %rdi     # 0x281e8
testq %rdi, %rdi
je 0x131f7
callq 0x6402
jmp 0x131f9
xorl %eax, %eax
movq %rax, (%rbx)
movl 0x14fd6(%rip), %eax     # 0x281d8
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movl $0x4, 0x14fc4(%rip)     # 0x281dc
jmp 0x131b4
movl $0x6, 0x14fb4(%rip)     # 0x281d8
jmp 0x13136