#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ flushbits(int, int *, int *);
int showbits(int, int, int, unsigned char *);
int startcode(int *byte_index, int *bit_index, unsigned char *buf, int len) {
  while (showbits(17, *byte_index, *bit_index, buf) != 1) {
    flushbits(1, byte_index, bit_index);
    if ((*byte_index) > len || ((*byte_index) == len && (*bit_index) < 7)) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<startcode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rcx
mov    $0x11,%edi
call   1030 <showbits@plt>
cmp    $0x1,%eax
je     11a8 <startcode+0x88>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
call   1040 <flushbits@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
jg     1197 <startcode+0x77>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
jne    11a3 <startcode+0x83>
mov    -0x18(%rbp),%rax
cmpl   $0x7,(%rax)
jge    11a3 <startcode+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <startcode+0x8f>
jmp    1137 <startcode+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startcode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    (%rdi),%esi
mov    0x0(%rbp),%edx
nopl   0x0(%rax,%rax,1)
mov    $0x11,%edi
mov    %r15,%rcx
call   1030 <showbits@plt>
cmp    $0x1,%eax
je     117a <startcode+0x5a>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <flushbits@plt>
mov    (%rbx),%esi
mov    $0xffffffff,%eax
cmp    %r14d,%esi
jg     117c <startcode+0x5c>
mov    0x0(%rbp),%edx
jne    1140 <startcode+0x20>
cmp    $0x7,%edx
jge    1140 <startcode+0x20>
jmp    117c <startcode+0x5c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @startcode(i32* %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
br label %10
10: ; preds = %36, %4
%11 = load i32*, i32** %6
%12 = load i32, i32* %11
%13 = load i32*, i32** %7
%14 = load i32, i32* %13
%15 = load i8*, i8** %8
%16 = call i32 @showbits(i32 17, i32 %12, i32 %14, i8* %15)
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %37
18: ; preds = %10
%19 = load i32*, i32** %6
%20 = load i32*, i32** %7
%21 = call i32 @flushbits(i32 1, i32* %19, i32* %20)
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = load i32, i32* %9
%25 = icmp sgt i32 %23, %24
br i1 %25, label %35, label %26
26: ; preds = %18
%27 = load i32*, i32** %6
%28 = load i32, i32* %27
%29 = load i32, i32* %9
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i32*, i32** %7
%33 = load i32, i32* %32
%34 = icmp slt i32 %33, 7
br i1 %34, label %35, label %36
35: ; preds = %31, %18
store i32 -1, i32* %5
br label %38
36: ; preds = %31, %26
br label %10
37: ; preds = %10
store i32 0, i32* %5
br label %38
38: ; preds = %37, %35
%39 = load i32, i32* %5
ret i32 %39
}

LLVM IR (-O2):
define i32 @startcode(i32* %0, i32* %1, i8* %2, i32 %3) {
%5 = load i32, i32* %0
%6 = load i32, i32* %1
%7 = tail call i32 @showbits(i32 17, i32 %5, i32 %6, i8* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %21, label %9
9: ; preds = %4, %18
%10 = tail call i32 @flushbits(i32 1, i32* %0, i32* %1)
%11 = load i32, i32* %0
%12 = icmp sgt i32 %11, %3
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = icmp eq i32 %11, %3
%15 = load i32, i32* %1
%16 = icmp slt i32 %15, 7
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = tail call i32 @showbits(i32 17, i32 %11, i32 %15, i8* %2)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %9
21: ; preds = %9, %18, %13, %4
%22 = phi i32 [ 0, %4 ], [ 0, %18 ], [ -1, %9 ], [ -1, %13 ]
ret i32 %22
}