// File: /workspace/github_c_makefile_star2_O1/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, 0x14f18(%rip)     # 0x281d8
jne 0x13429
leaq 0x844c(%rip), %rdi      # 0x1b719
callq 0x3040
testq %rax, %rax
je 0x13429
movq %rax, %r12
leaq 0x8444(%rip), %rsi      # 0x1b729
movq %rax, %rdi
callq 0x3760
testq %rax, %rax
je 0x13301
movl $0x1, 0x14edc(%rip)     # 0x281d8
jmp 0x133ab
leaq 0x8427(%rip), %rsi      # 0x1b72f
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x1332d
movl $0x2, 0x14eb9(%rip)     # 0x281d8
addq $0x5, %rax
movq %rax, %rdi
movl $0x3b, %esi
jmp 0x1339f
leaq 0x8401(%rip), %rsi      # 0x1b735
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x13351
movl $0x3, 0x14e8d(%rip)     # 0x281d8
addq $0x9, %rax
jmp 0x13397
leaq 0x83e5(%rip), %rsi      # 0x1b73d
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x13371
movl $0x4, 0x14e69(%rip)     # 0x281d8
jmp 0x13393
leaq 0x83cc(%rip), %rsi      # 0x1b744
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x1348f
movl $0x5, 0x14e45(%rip)     # 0x281d8
addq $0x7, %rax
movq %rax, %rdi
movl $0x20, %esi
callq 0x9341
movq %rax, 0x14e35(%rip)     # 0x281e0
leaq 0x8399(%rip), %rsi      # 0x1b74b
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x133cf
movl $0x1, 0x14e13(%rip)     # 0x281dc
addq $0x8, %rax
jmp 0x13415
leaq 0x837d(%rip), %rsi      # 0x1b753
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x133f3
movl $0x2, 0x14def(%rip)     # 0x281dc
addq $0x6, %rax
jmp 0x13415
leaq 0x835f(%rip), %rsi      # 0x1b759
movq %r12, %rdi
callq 0x3760
testq %rax, %rax
je 0x13483
movl $0x3, 0x14dcb(%rip)     # 0x281dc
addq $0x4, %rax
movq %rax, %rdi
movl $0x3b, %esi
callq 0x9341
movq %rax, 0x14dbf(%rip)     # 0x281e8
testq %r15, %r15
je 0x13446
movq 0x14dab(%rip), %rdi     # 0x281e0
testq %rdi, %rdi
je 0x13441
callq 0x647e
jmp 0x13443
xorl %eax, %eax
movq %rax, (%r15)
testq %r14, %r14
je 0x13454
movl 0x14d8b(%rip), %eax     # 0x281dc
movl %eax, (%r14)
testq %rbx, %rbx
je 0x13471
movq 0x14d88(%rip), %rdi     # 0x281e8
testq %rdi, %rdi
je 0x1346c
callq 0x647e
jmp 0x1346e
xorl %eax, %eax
movq %rax, (%rbx)
movl 0x14d61(%rip), %eax     # 0x281d8
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movl $0x4, 0x14d4f(%rip)     # 0x281dc
jmp 0x13429
movl $0x6, 0x14d3f(%rip)     # 0x281d8
jmp 0x133ab