// File: /workspace/github_c_makefile_star2_O2/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, 0x15b67(%rip)     # 0x271f8
jne 0x117e9
callq 0x1166d
testq %rax, %rax
je 0x117e9
movq %rax, %r12
leaq 0x8087(%rip), %rsi      # 0x19736
movq %rax, %rdi
callq 0x3760
testq %rax, %rax
je 0x116cb
movl $0x1, 0x15b32(%rip)     # 0x271f8
jmp 0x1176d
leaq 0x806a(%rip), %rsi      # 0x1973c
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x116f1
movl $0x2, 0x15b0f(%rip)     # 0x271f8
addq $0x5, %rax
pushq $0x3b
jmp 0x1175d
leaq 0x804a(%rip), %rsi      # 0x19742
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x11715
movl $0x3, 0x15ae9(%rip)     # 0x271f8
addq $0x9, %rax
jmp 0x1175b
leaq 0x802e(%rip), %rsi      # 0x1974a
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x11735
movl $0x4, 0x15ac5(%rip)     # 0x271f8
jmp 0x11757
leaq 0x8015(%rip), %rsi      # 0x19751
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x1184f
movl $0x5, 0x15aa1(%rip)     # 0x271f8
addq $0x7, %rax
pushq $0x20
popq %rsi
movq %rax, %rdi
callq 0x84b7
movq %rax, 0x15a93(%rip)     # 0x27200
leaq 0x7fe4(%rip), %rsi      # 0x19758
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x11791
movl $0x1, 0x15a71(%rip)     # 0x271fc
addq $0x8, %rax
jmp 0x117d7
leaq 0x7fc8(%rip), %rsi      # 0x19760
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x117b5
movl $0x2, 0x15a4d(%rip)     # 0x271fc
addq $0x6, %rax
jmp 0x117d7
leaq 0x7faa(%rip), %rsi      # 0x19766
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x11843
movl $0x3, 0x15a29(%rip)     # 0x271fc
addq $0x4, %rax
pushq $0x3b
popq %rsi
movq %rax, %rdi
callq 0x84b7
movq %rax, 0x15a1f(%rip)     # 0x27208
testq %r15, %r15
je 0x11806
movq 0x15a0b(%rip), %rdi     # 0x27200
testq %rdi, %rdi
je 0x11801
callq 0x5ede
jmp 0x11803
xorl %eax, %eax
movq %rax, (%r15)
testq %r14, %r14
je 0x11814
movl 0x159eb(%rip), %eax     # 0x271fc
movl %eax, (%r14)
testq %rbx, %rbx
je 0x11831
movq 0x159e8(%rip), %rdi     # 0x27208
testq %rdi, %rdi
je 0x1182c
callq 0x5ede
jmp 0x1182e
xorl %eax, %eax
movq %rax, (%rbx)
movl 0x159c1(%rip), %eax     # 0x271f8
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movl $0x4, 0x159af(%rip)     # 0x271fc
jmp 0x117e9
movl $0x6, 0x1599f(%rip)     # 0x271f8
jmp 0x1176d