// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpl $0x0, 0x17a51(%rip)     # 0x331fc
jne 0x1ba14
callq 0x1b770
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1ba12
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rdi
leaq 0xafaf(%rip), %rsi      # 0x26787
callq 0x3730
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x1b7f6
movl $0x1, 0x17a0b(%rip)     # 0x331fc
jmp 0x1b92a
movq -0x20(%rbp), %rdi
leaq 0xaf8c(%rip), %rsi      # 0x2678d
callq 0x3730
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x1b840
movl $0x2, 0x179e2(%rip)     # 0x331fc
movq -0x28(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x3b, %esi
callq 0xc1d0
movq %rax, 0x179cd(%rip)     # 0x33208
jmp 0x1b928
movq -0x20(%rbp), %rdi
leaq 0xaf48(%rip), %rsi      # 0x26793
callq 0x3730
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x1b88a
movl $0x3, 0x17998(%rip)     # 0x331fc
movq -0x28(%rbp), %rax
addq $0x9, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x20, %esi
callq 0xc1d0
movq %rax, 0x17983(%rip)     # 0x33208
jmp 0x1b926
movq -0x20(%rbp), %rdi
leaq 0xaf06(%rip), %rsi      # 0x2679b
callq 0x3730
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x1b8d1
movl $0x4, 0x1794e(%rip)     # 0x331fc
movq -0x28(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x20, %esi
callq 0xc1d0
movq %rax, 0x17939(%rip)     # 0x33208
jmp 0x1b924
movq -0x20(%rbp), %rdi
leaq 0xaec6(%rip), %rsi      # 0x267a2
callq 0x3730
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x1b918
movl $0x5, 0x17907(%rip)     # 0x331fc
movq -0x28(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x20, %esi
callq 0xc1d0
movq %rax, 0x178f2(%rip)     # 0x33208
jmp 0x1b922
movl $0x6, 0x178da(%rip)     # 0x331fc
jmp 0x1b924
jmp 0x1b926
jmp 0x1b928
jmp 0x1b92a
movq -0x20(%rbp), %rdi
leaq 0xae74(%rip), %rsi      # 0x267a9
callq 0x3730
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x1b974
movl $0x1, 0x178b2(%rip)     # 0x33200
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x3b, %esi
callq 0xc1d0
movq %rax, 0x178a1(%rip)     # 0x33210
jmp 0x1ba10
movq -0x20(%rbp), %rdi
leaq 0xae32(%rip), %rsi      # 0x267b1
callq 0x3730
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x1b9bb
movl $0x2, 0x17868(%rip)     # 0x33200
movq -0x28(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x3b, %esi
callq 0xc1d0
movq %rax, 0x17857(%rip)     # 0x33210
jmp 0x1ba0e
movq -0x20(%rbp), %rdi
leaq 0xadf1(%rip), %rsi      # 0x267b7
callq 0x3730
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x1ba02
movl $0x3, 0x17821(%rip)     # 0x33200
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl $0x3b, %esi
callq 0xc1d0
movq %rax, 0x17810(%rip)     # 0x33210
jmp 0x1ba0c
movl $0x4, 0x177f4(%rip)     # 0x33200
jmp 0x1ba0e
jmp 0x1ba10
jmp 0x1ba12
jmp 0x1ba14
cmpq $0x0, -0x8(%rbp)
je 0x1ba4a
cmpq $0x0, 0x177e5(%rip)     # 0x33208
je 0x1ba3d
movq 0x177dc(%rip), %rdi     # 0x33208
callq 0x7530
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
jmp 0x1ba48
movq -0x8(%rbp), %rax
movq $0x0, (%rax)
jmp 0x1ba4a
cmpq $0x0, -0x10(%rbp)
je 0x1ba5d
movl 0x177a9(%rip), %ecx     # 0x33200
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, -0x18(%rbp)
je 0x1ba93
cmpq $0x0, 0x177a4(%rip)     # 0x33210
je 0x1ba86
movq 0x1779b(%rip), %rdi     # 0x33210
callq 0x7530
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x1ba91
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
jmp 0x1ba93
movl 0x17763(%rip), %eax     # 0x331fc
addq $0x30, %rsp
popq %rbp
retq
nop