// File: ctSkennerton[P]fxtract/util/./bergstr.c
// Function: bergstr
char *bergstr(char *phaystack, char *pneedle)
{
  unsigned char *haystack, *needle;
  unsigned b;
  unsigned char *rneedle;

  haystack = (unsigned char *) phaystack;

  if ((b = *(needle = (unsigned char *) pneedle)))
    {
      unsigned c;
      haystack--;               /* possible ANSI violation */

      {
        unsigned a;
        do
          if (!(a = *++haystack))
            goto ret0;
        while (a != b);
      }

      if (!(c = *++needle))
        goto foundneedle;
      ++needle;
      goto jin;

      for (;;)
        {
          {
            unsigned a;
            if (0)
            jin:{
                if ((a = *++haystack) == c)
                  goto crest;
              }
            else
              a = *++haystack;
            do
              {
                for (; a != b; a = *++haystack)
                  {
                    if (!a)
                      goto ret0;
                    if ((a = *++haystack) == b)
                      break;
                    if (!a)
                      goto ret0;
                  }
              }
            while ((a = *++haystack) != c);
          }
        crest:
          {
            unsigned a;
            {
              unsigned char *rhaystack;
              if (*(rhaystack = haystack-- + 1) == (a = *(rneedle = needle)))
                do
                  {
                    if (!a)
                      goto foundneedle;
                    if (*++rhaystack != (a = *++needle))
                      break;
                    if (!a)
                      goto foundneedle;
                  }
                while (*++rhaystack == (a = *++needle));
              needle = rneedle; /* took the register-poor aproach */
            }
            if (!a)
              break;
          }
        }
    }
foundneedle:
  return (char *)haystack;
ret0:
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movzbl (%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x42d5
movq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl 0x1(%rax), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, %eax
jne 0x4127
jmp 0x42e1
jmp 0x4129
movl -0x40(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x4107
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x28(%rbp)
movzbl 0x1(%rax), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
jne 0x4151
jmp 0x42d7
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x4169
xorl %eax, %eax
testb $0x1, %al
jne 0x4167
jmp 0x418b
jmp 0x4169
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl 0x1(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl -0x3c(%rbp), %eax
jne 0x4189
jmp 0x4219
jmp 0x41a1
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl 0x1(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0x41a3
jmp 0x41a5
movl -0x44(%rbp), %eax
cmpl -0x2c(%rbp), %eax
je 0x41fa
cmpl $0x0, -0x44(%rbp)
jne 0x41b8
jmp 0x42e1
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl 0x1(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl -0x2c(%rbp), %eax
jne 0x41d5
jmp 0x41fa
cmpl $0x0, -0x44(%rbp)
jne 0x41e0
jmp 0x42e1
jmp 0x41e2
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl 0x1(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0x41a5
jmp 0x41fc
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movzbl 0x1(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl -0x3c(%rbp), %eax
jne 0x41a3
jmp 0x4219
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x20(%rbp)
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x50(%rbp)
movzbl 0x1(%rax), %eax
movq -0x28(%rbp), %rcx
movq %rcx, -0x38(%rbp)
movzbl (%rcx), %ecx
movl %ecx, -0x48(%rbp)
cmpl %ecx, %eax
jne 0x42be
jmp 0x424b
cmpl $0x0, -0x48(%rbp)
jne 0x4256
jmp 0x42d7
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x50(%rbp)
movzbl 0x1(%rax), %eax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movzbl 0x1(%rcx), %ecx
movl %ecx, -0x48(%rbp)
cmpl %ecx, %eax
je 0x4285
jmp 0x42bc
cmpl $0x0, -0x48(%rbp)
jne 0x428d
jmp 0x42d7
jmp 0x428f
movq -0x50(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x50(%rbp)
movzbl 0x1(%rax), %eax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movzbl 0x1(%rcx), %ecx
movl %ecx, -0x48(%rbp)
cmpl %ecx, %eax
je 0x424b
jmp 0x42be
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x48(%rbp)
jne 0x42ce
jmp 0x42d3
jmp 0x415f
jmp 0x42d5
jmp 0x42d7
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x42e9
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nop