// File: /workspace/github_c_makefile_star2_O1/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, 0x8004c(%rip)     # 0xc4248
jne 0x44365
leaq 0x51a3e(%rip), %rdi     # 0x95c47
callq 0x68f0
testq %rax, %rax
je 0x44365
movq %rax, %r12
leaq 0x51a36(%rip), %rsi     # 0x95c57
movq %rax, %rdi
callq 0x6180
testq %rax, %rax
je 0x4423d
movl $0x1, 0x80010(%rip)     # 0xc4248
jmp 0x442e7
leaq 0x51a19(%rip), %rsi     # 0x95c5d
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x44269
movl $0x2, 0x7ffed(%rip)     # 0xc4248
addq $0x5, %rax
movq %rax, %rdi
movl $0x3b, %esi
jmp 0x442db
leaq 0x519f3(%rip), %rsi     # 0x95c63
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x4428d
movl $0x3, 0x7ffc1(%rip)     # 0xc4248
addq $0x9, %rax
jmp 0x442d3
leaq 0x519d7(%rip), %rsi     # 0x95c6b
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x442ad
movl $0x4, 0x7ff9d(%rip)     # 0xc4248
jmp 0x442cf
leaq 0x519be(%rip), %rsi     # 0x95c72
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x443cb
movl $0x5, 0x7ff79(%rip)     # 0xc4248
addq $0x7, %rax
movq %rax, %rdi
movl $0x20, %esi
callq 0x22b21
movq %rax, 0x7ff69(%rip)     # 0xc4250
leaq 0x5198b(%rip), %rsi     # 0x95c79
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x4430b
movl $0x1, 0x7ff47(%rip)     # 0xc424c
addq $0x8, %rax
jmp 0x44351
leaq 0x5196f(%rip), %rsi     # 0x95c81
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x4432f
movl $0x2, 0x7ff23(%rip)     # 0xc424c
addq $0x6, %rax
jmp 0x44351
leaq 0x51951(%rip), %rsi     # 0x95c87
movq %r12, %rdi
callq 0x6180
testq %rax, %rax
je 0x443bf
movl $0x3, 0x7feff(%rip)     # 0xc424c
addq $0x4, %rax
movq %rax, %rdi
movl $0x3b, %esi
callq 0x22b21
movq %rax, 0x7fef3(%rip)     # 0xc4258
testq %r15, %r15
je 0x44382
movq 0x7fedf(%rip), %rdi     # 0xc4250
testq %rdi, %rdi
je 0x4437d
callq 0x1f9f6
jmp 0x4437f
xorl %eax, %eax
movq %rax, (%r15)
testq %r14, %r14
je 0x44390
movl 0x7febf(%rip), %eax     # 0xc424c
movl %eax, (%r14)
testq %rbx, %rbx
je 0x443ad
movq 0x7febc(%rip), %rdi     # 0xc4258
testq %rdi, %rdi
je 0x443a8
callq 0x1f9f6
jmp 0x443aa
xorl %eax, %eax
movq %rax, (%rbx)
movl 0x7fe95(%rip), %eax     # 0xc4248
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movl $0x4, 0x7fe83(%rip)     # 0xc424c
jmp 0x44365
movl $0x6, 0x7fe73(%rip)     # 0xc4248
jmp 0x442e7