#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *);
int ByteSyncOnSyncword(unsigned char *bitStreamIn, double *bitStreamInTime,
                       unsigned long nSamples, char *syncWord,
                       unsigned int syncWordLength, int frameLength,
                       int startBit, FILE *minorFrameFile) {
  int idx2;
  static char firstTime = 1;
  static char *historyBufferCirc;
  static int oldest = 0, syncIndicator, frameByteIdx, minorFrameShiftFlag,
             bitIdx;
  int framesFound = 0;
  unsigned long idx;
  static unsigned char zero = 0, one = 1;
  static unsigned char byte = 0;
  if (firstTime == 1) {
    firstTime = 0;
    historyBufferCirc = (char *)malloc(sizeof(char) * syncWordLength);
    if (historyBufferCirc == NULL) {
      printf("Error in malloc\n");
      exit(1);
    }
    memset(historyBufferCirc, 48, sizeof(char) * syncWordLength);
  }
  for (idx = 0; idx < nSamples; idx++) {
    if (minorFrameShiftFlag == 1) {
      if (bitStreamIn[idx] == '0') {
        byte = byte << 1;
        byte = byte | zero;
      } else {
        byte = byte << 1;
        byte = byte | one;
      }
      bitIdx++;
      if (bitIdx > 7) {
        fprintf(minorFrameFile, "%.2X ", byte);
        byte = 0;
        bitIdx = 0;
        frameByteIdx++;
        if (frameByteIdx > frameLength) {
          minorFrameShiftFlag = 0;
          fprintf(minorFrameFile, "\n");
        }
      }
    }
    historyBufferCirc[oldest] = bitStreamIn[idx];
    syncIndicator = 1;
    for (idx2 = 0; idx2 < syncWordLength; idx2++) {
      if (syncWord[idx2] !=
          historyBufferCirc[(oldest + idx2 + 1) % syncWordLength]) {
        syncIndicator = 0;
        break;
      }
    }
    if (syncIndicator == 1 && minorFrameShiftFlag == 0) {
      fprintf(minorFrameFile, "%.5f ", bitStreamInTime[idx]);
      fprintf(minorFrameFile, "%.2X ", 0b11101101);
      fprintf(minorFrameFile, "%.2X ", 0b11100010);
      frameByteIdx = 2;
      minorFrameShiftFlag = 1;
      framesFound++;
      bitIdx = startBit;
      byte = 0;
      zero = 0;
      one = 1;
    }
    syncIndicator = 1;
    for (idx2 = 0; idx2 < syncWordLength; idx2++) {
      if (syncWord[idx2] ==
          historyBufferCirc[(oldest + idx2 + 1) % syncWordLength]) {
        syncIndicator = 0;
        break;
      }
    }
    if (syncIndicator == 1 && minorFrameShiftFlag == 0) {
      fprintf(minorFrameFile, "%.5fi ", bitStreamInTime[idx]);
      fprintf(minorFrameFile, "%.2X ", 0b11101101);
      fprintf(minorFrameFile, "%.2X ", 0b11100010);
      frameByteIdx = 2;
      minorFrameShiftFlag = 1;
      framesFound++;
      bitIdx = startBit;
      byte = 0;
      zero = 1;
      one = 0;
    }
    oldest = (oldest + 1) % syncWordLength;
  }
  return framesFound;
}


x86 assembly (clang, -O0):
<ByteSyncOnSyncword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movsbl 0x2ec3(%rip),%eax
cmp    $0x1,%eax
jne    11e8 <ByteSyncOnSyncword+0x98>
movb   $0x0,0x2eb3(%rip)
mov    -0x24(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,0x2eae(%rip)
cmpq   $0x0,0x2ea6(%rip)
jne    11ce <ByteSyncOnSyncword+0x7e>
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e83(%rip),%rdi
mov    -0x24(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edx
mov    $0x30,%esi
call   1040 <memset@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    156e <ByteSyncOnSyncword+0x41e>
cmpl   $0x1,0x2e67(%rip)
jne    12fb <ByteSyncOnSyncword+0x1ab>
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    124b <ByteSyncOnSyncword+0xfb>
movzbl 0x2e4e(%rip),%eax
shl    $0x1,%eax
mov    %al,0x2e45(%rip)
movzbl 0x2e3e(%rip),%eax
movzbl 0x2e36(%rip),%ecx
or     %ecx,%eax
mov    %al,0x2e2f(%rip)
jmp    1271 <ByteSyncOnSyncword+0x121>
movzbl 0x2e23(%rip),%eax
shl    $0x1,%eax
mov    %al,0x2e1a(%rip)
movzbl 0x2e13(%rip),%eax
movzbl 0x2de0(%rip),%ecx
or     %ecx,%eax
mov    %al,0x2e04(%rip)
mov    0x2df9(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2df0(%rip)
cmpl   $0x7,0x2de9(%rip)
jle    12f6 <ByteSyncOnSyncword+0x1a6>
mov    0x18(%rbp),%rdi
movzbl 0x2ddd(%rip),%edx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movb   $0x0,0x2dc8(%rip)
movl   $0x0,0x2db9(%rip)
mov    0x2dab(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2da2(%rip)
mov    0x2d9c(%rip),%eax
cmp    -0x28(%rbp),%eax
jle    12f1 <ByteSyncOnSyncword+0x1a1>
movl   $0x0,0x2d8d(%rip)
mov    0x18(%rbp),%rdi
lea    0xd25(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12f6 <ByteSyncOnSyncword+0x1a6>
jmp    12fb <ByteSyncOnSyncword+0x1ab>
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    0x2d4b(%rip),%rax
movslq 0x2d4c(%rip),%rcx
mov    %dl,(%rax,%rcx,1)
movl   $0x1,0x2d43(%rip)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    138e <ByteSyncOnSyncword+0x23e>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d0e(%rip),%rcx
mov    0x2d10(%rip),%eax
add    -0x2c(%rbp),%eax
add    $0x1,%eax
xor    %edx,%edx
divl   -0x24(%rbp)
mov    -0x3c(%rbp),%eax
mov    %edx,%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     137b <ByteSyncOnSyncword+0x22b>
movl   $0x0,0x2cee(%rip)
jmp    138e <ByteSyncOnSyncword+0x23e>
jmp    1380 <ByteSyncOnSyncword+0x230>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1328 <ByteSyncOnSyncword+0x1d8>
cmpl   $0x1,0x2ccf(%rip)
jne    1430 <ByteSyncOnSyncword+0x2e0>
cmpl   $0x0,0x2cca(%rip)
jne    1430 <ByteSyncOnSyncword+0x2e0>
mov    0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xc57(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x18(%rbp),%rdi
lea    0xc3f(%rip),%rsi
mov    $0xed,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x18(%rbp),%rdi
lea    0xc28(%rip),%rsi
mov    $0xe2,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,0x2c69(%rip)
movl   $0x1,0x2c63(%rip)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    0x10(%rbp),%eax
mov    %eax,0x2c55(%rip)
movb   $0x0,0x2c53(%rip)
movb   $0x0,0x2c4b(%rip)
movb   $0x1,0x2c19(%rip)
movl   $0x1,0x2c2a(%rip)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    14a7 <ByteSyncOnSyncword+0x357>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x40(%rbp)
mov    0x2bf5(%rip),%rcx
mov    0x2bf7(%rip),%eax
add    -0x2c(%rbp),%eax
add    $0x1,%eax
xor    %edx,%edx
divl   -0x24(%rbp)
mov    -0x40(%rbp),%eax
mov    %edx,%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1494 <ByteSyncOnSyncword+0x344>
movl   $0x0,0x2bd5(%rip)
jmp    14a7 <ByteSyncOnSyncword+0x357>
jmp    1499 <ByteSyncOnSyncword+0x349>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1441 <ByteSyncOnSyncword+0x2f1>
cmpl   $0x1,0x2bb6(%rip)
jne    1549 <ByteSyncOnSyncword+0x3f9>
cmpl   $0x0,0x2bb1(%rip)
jne    1549 <ByteSyncOnSyncword+0x3f9>
mov    0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xb44(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    0x18(%rbp),%rdi
lea    0xb26(%rip),%rsi
mov    $0xed,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x18(%rbp),%rdi
lea    0xb0f(%rip),%rsi
mov    $0xe2,%edx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,0x2b50(%rip)
movl   $0x1,0x2b4a(%rip)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    0x10(%rbp),%eax
mov    %eax,0x2b3c(%rip)
movb   $0x0,0x2b3a(%rip)
movb   $0x1,0x2b32(%rip)
movb   $0x0,0x2b00(%rip)
mov    0x2b11(%rip),%eax
add    $0x1,%eax
xor    %edx,%edx
divl   -0x24(%rbp)
mov    %edx,0x2b03(%rip)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11f0 <ByteSyncOnSyncword+0xa0>
mov    -0x30(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ByteSyncOnSyncword>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8d,%ebp
mov    %rcx,%r12
mov    %rdx,0x18(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,0x20(%rsp)
cmpb   $0x0,0x2ec9(%rip)
jne    11be <ByteSyncOnSyncword+0x5e>
movb   $0x1,0x2ec0(%rip)
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,0x2eba(%rip)
test   %rax,%rax
je     149d <ByteSyncOnSyncword+0x33d>
mov    %rax,%rdi
mov    $0x30,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
cmpq   $0x0,0x18(%rsp)
je     1482 <ByteSyncOnSyncword+0x322>
mov    0x2e9f(%rip),%r13b
mov    %ebp,%r15d
xor    %r14d,%r14d
movl   $0x0,0x8(%rsp)
jmp    1212 <ByteSyncOnSyncword+0xb2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2e72(%rip),%eax
add    $0x1,%eax
xor    %edx,%edx
div    %ebp
mov    %edx,0x2e65(%rip)
add    $0x1,%r14
cmp    0x18(%rsp),%r14
je     148a <ByteSyncOnSyncword+0x32a>
test   $0x1,%r13b
je     12c0 <ByteSyncOnSyncword+0x160>
mov    0x2e58(%rip),%al
add    %al,%al
mov    0x20(%rsp),%rcx
cmpb   $0x30,(%rcx,%r14,1)
jne    1240 <ByteSyncOnSyncword+0xe0>
mov    0x2e42(%rip),%cl
jmp    1249 <ByteSyncOnSyncword+0xe9>
nopl   0x0(%rax,%rax,1)
mov    0x2e33(%rip),%cl
xor    $0x1,%cl
and    $0x1,%cl
or     %cl,%al
mov    %al,0x2e26(%rip)
mov    0x2e1a(%rip),%ecx
lea    0x1(%rcx),%edx
mov    %edx,0x2e11(%rip)
cmp    $0x7,%ecx
jl     12c0 <ByteSyncOnSyncword+0x160>
movzbl %al,%edx
mov    0x68(%rsp),%rdi
lea    0xd89(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
movb   $0x0,0x2df5(%rip)
movl   $0x0,0x2de5(%rip)
mov    0x2dd7(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2dce(%rip)
cmp    0xc(%rsp),%eax
jl     12c0 <ByteSyncOnSyncword+0x160>
movb   $0x0,0x2dc5(%rip)
mov    $0xa,%edi
mov    0x68(%rsp),%rsi
call   1050 <fputc@plt>
nopw   0x0(%rax,%rax,1)
mov    0x20(%rsp),%rax
mov    (%rax,%r14,1),%al
mov    0x2d90(%rip),%rcx
movslq 0x2d91(%rip),%rsi
mov    %al,(%rcx,%rsi,1)
test   %ebp,%ebp
je     130e <ByteSyncOnSyncword+0x1ae>
add    $0x1,%esi
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r12,%rdi,1),%ebx
lea    (%rsi,%rdi,1),%eax
xor    %edx,%edx
div    %ebp
cmp    (%rcx,%rdx,1),%bl
jne    13b0 <ByteSyncOnSyncword+0x250>
add    $0x1,%rdi
cmp    %rdi,%r15
jne    12f0 <ByteSyncOnSyncword+0x190>
mov    0x2d5b(%rip),%r13b
test   %r13b,%r13b
jne    13a3 <ByteSyncOnSyncword+0x243>
mov    0x10(%rsp),%rax
movsd  (%rax,%r14,8),%xmm0
mov    $0x1,%r13b
mov    0x68(%rsp),%rbx
mov    %rbx,%rdi
lea    0xccb(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    %rbx,%rdi
lea    0xcb4(%rip),%rsi
mov    $0xed,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
lea    0xc9e(%rip),%rsi
mov    $0xe2,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
movl   $0x2,0x2cf4(%rip)
movb   $0x1,0x2cf1(%rip)
addl   $0x1,0x8(%rsp)
mov    0x60(%rsp),%eax
mov    %eax,0x2ce6(%rip)
movb   $0x0,0x2ce5(%rip)
movb   $0x0,0x2cdc(%rip)
movb   $0x0,0x2cd6(%rip)
test   %ebp,%ebp
jne    13bb <ByteSyncOnSyncword+0x25b>
jmp    13ee <ByteSyncOnSyncword+0x28e>
nopl   0x0(%rax)
mov    0x2cb9(%rip),%r13b
test   %ebp,%ebp
je     13ee <ByteSyncOnSyncword+0x28e>
mov    0x2c9e(%rip),%rcx
mov    0x2ca0(%rip),%esi
add    $0x1,%esi
xor    %edi,%edi
nopl   (%rax)
movzbl (%r12,%rdi,1),%ebx
lea    (%rsi,%rdi,1),%eax
xor    %edx,%edx
div    %ebp
cmp    (%rcx,%rdx,1),%bl
je     11f0 <ByteSyncOnSyncword+0x90>
add    $0x1,%rdi
cmp    %rdi,%r15
jne    13d0 <ByteSyncOnSyncword+0x270>
test   $0x1,%r13b
jne    11f0 <ByteSyncOnSyncword+0x90>
mov    0x10(%rsp),%rax
movsd  (%rax,%r14,8),%xmm0
mov    $0x1,%r13b
mov    0x68(%rsp),%rbx
mov    %rbx,%rdi
lea    0xbf7(%rip),%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    %rbx,%rdi
lea    0xbda(%rip),%rsi
mov    $0xed,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
lea    0xbc4(%rip),%rsi
mov    $0xe2,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
movl   $0x2,0x2c1a(%rip)
movb   $0x1,0x2c17(%rip)
addl   $0x1,0x8(%rsp)
mov    0x60(%rsp),%eax
mov    %eax,0x2c0c(%rip)
movb   $0x0,0x2c0b(%rip)
movb   $0x1,0x2c02(%rip)
movb   $0x1,0x2bfc(%rip)
jmp    11f0 <ByteSyncOnSyncword+0x90>
movl   $0x0,0x8(%rsp)
mov    0x8(%rsp),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb6f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@ByteSyncOnSyncword.firstTime = internal global i8 1
@ByteSyncOnSyncword.historyBufferCirc = internal global i8* null
@ByteSyncOnSyncword.oldest = internal global i32 0
@ByteSyncOnSyncword.syncIndicator = internal global i32 0
@ByteSyncOnSyncword.frameByteIdx = internal global i32 0
@ByteSyncOnSyncword.minorFrameShiftFlag = internal global i32 0
@ByteSyncOnSyncword.bitIdx = internal global i32 0
@ByteSyncOnSyncword.zero = internal global i8 0
@ByteSyncOnSyncword.one = internal global i8 1
@ByteSyncOnSyncword.byte = internal global i8 0
@.str = [17 x i8] c"Error in malloc\0A\00"
@.str.1 = [6 x i8] c"%.2X \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c"%.5f \00"
@.str.4 = [7 x i8] c"%.5fi \00"
define i32 @ByteSyncOnSyncword(i8* %0, double* %1, i64 %2, i8* %3, i32 %4, i32 %5, i32 %6, i32* %7) {
%9 = alloca i8*
%10 = alloca double*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i64
store i8* %0, i8** %9
store double* %1, double** %10
store i64 %2, i64* %11
store i8* %3, i8** %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32* %7, i32** %16
store i32 0, i32* %18
%20 = load i8, i8* @ByteSyncOnSyncword.firstTime
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %42
23: ; preds = %8
store i8 0, i8* @ByteSyncOnSyncword.firstTime
%24 = load i32, i32* %13
%25 = zext i32 %24 to i64
%26 = mul i64 1, %25
%27 = trunc i64 %26 to i32
%28 = call i64 @malloc(i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** @ByteSyncOnSyncword.historyBufferCirc
%30 = load i8*, i8** @ByteSyncOnSyncword.historyBufferCirc
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %23
%33 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %23
%36 = load i8*, i8** @ByteSyncOnSyncword.historyBufferCirc
%37 = load i32, i32* %13
%38 = zext i32 %37 to i64
%39 = mul i64 1, %38
%40 = trunc i64 %39 to i32
%41 = call i32 @memset(i8* %36, i32 48, i32 %40)
br label %42
42: ; preds = %35, %8
store i64 0, i64* %19
br label %43
43: ; preds = %210, %42
%44 = load i64, i64* %19
%45 = load i64, i64* %11
%46 = icmp ult i64 %44, %45
br i1 %46, label %47, label %213
47: ; preds = %43
%48 = load i32, i32* @ByteSyncOnSyncword.minorFrameShiftFlag
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %99
50: ; preds = %47
%51 = load i8*, i8** %9
%52 = load i64, i64* %19
%53 = getelementptr inbounds i8, i8* %51, i64 %52
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = icmp eq i32 %55, 48
br i1 %56, label %57, label %68
57: ; preds = %50
%58 = load i8, i8* @ByteSyncOnSyncword.byte
%59 = zext i8 %58 to i32
%60 = shl i32 %59, 1
%61 = trunc i32 %60 to i8
store i8 %61, i8* @ByteSyncOnSyncword.byte
%62 = load i8, i8* @ByteSyncOnSyncword.byte
%63 = zext i8 %62 to i32
%64 = load i8, i8* @ByteSyncOnSyncword.zero
%65 = zext i8 %64 to i32
%66 = or i32 %63, %65
%67 = trunc i32 %66 to i8
store i8 %67, i8* @ByteSyncOnSyncword.byte
br label %79
68: ; preds = %50
%69 = load i8, i8* @ByteSyncOnSyncword.byte
%70 = zext i8 %69 to i32
%71 = shl i32 %70, 1
%72 = trunc i32 %71 to i8
store i8 %72, i8* @ByteSyncOnSyncword.byte
%73 = load i8, i8* @ByteSyncOnSyncword.byte
%74 = zext i8 %73 to i32
%75 = load i8, i8* @ByteSyncOnSyncword.one
%76 = zext i8 %75 to i32
%77 = or i32 %74, %76
%78 = trunc i32 %77 to i8
store i8 %78, i8* @ByteSyncOnSyncword.byte
br label %79
79: ; preds = %68, %57
%80 = load i32, i32* @ByteSyncOnSyncword.bitIdx
%81 = add nsw i32 %80, 1
store i32 %81, i32* @ByteSyncOnSyncword.bitIdx
%82 = load i32, i32* @ByteSyncOnSyncword.bitIdx
%83 = icmp sgt i32 %82, 7
br i1 %83, label %84, label %98
84: ; preds = %79
%85 = load i32*, i32** %16
%86 = load i8, i8* @ByteSyncOnSyncword.byte
%87 = zext i8 %86 to i32
%88 = call i32 (i32*, i8*, ...) @fprintf(i32* %85, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %87)
store i8 0, i8* @ByteSyncOnSyncword.byte
store i32 0, i32* @ByteSyncOnSyncword.bitIdx
%89 = load i32, i32* @ByteSyncOnSyncword.frameByteIdx
%90 = add nsw i32 %89, 1
store i32 %90, i32* @ByteSyncOnSyncword.frameByteIdx
%91 = load i32, i32* @ByteSyncOnSyncword.frameByteIdx
%92 = load i32, i32* %14
%93 = icmp sgt i32 %91, %92
br i1 %93, label %94, label %97
94: ; preds = %84
store i32 0, i32* @ByteSyncOnSyncword.minorFrameShiftFlag
%95 = load i32*, i32** %16
%96 = call i32 (i32*, i8*, ...) @fprintf(i32* %95, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %97
97: ; preds = %94, %84
br label %98
98: ; preds = %97, %79
br label %99
99: ; preds = %98, %47
%100 = load i8*, i8** %9
%101 = load i64, i64* %19
%102 = getelementptr inbounds i8, i8* %100, i64 %101
%103 = load i8, i8* %102
%104 = load i8*, i8** @ByteSyncOnSyncword.historyBufferCirc
%105 = load i32, i32* @ByteSyncOnSyncword.oldest
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8, i8* %104, i64 %106
store i8 %103, i8* %107
store i32 1, i32* @ByteSyncOnSyncword.syncIndicator
store i32 0, i32* %17
br label %108
108: ; preds = %133, %99
%109 = load i32, i32* %17
%110 = load i32, i32* %13
%111 = icmp ult i32 %109, %110
br i1 %111, label %112, label %136
112: ; preds = %108
%113 = load i8*, i8** %12
%114 = load i32, i32* %17
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8, i8* %113, i64 %115
%117 = load i8, i8* %116
%118 = sext i8 %117 to i32
%119 = load i8*, i8** @ByteSyncOnSyncword.historyBufferCirc
%120 = load i32, i32* @ByteSyncOnSyncword.oldest
%121 = load i32, i32* %17
%122 = add nsw i32 %120, %121
%123 = add nsw i32 %122, 1
%124 = load i32, i32* %13
%125 = urem i32 %123, %124
%126 = zext i32 %125 to i64
%127 = getelementptr inbounds i8, i8* %119, i64 %126
%128 = load i8, i8* %127
%129 = sext i8 %128 to i32
%130 = icmp ne i32 %118, %129
br i1 %130, label %131, label %132
131: ; preds = %112
store i32 0, i32* @ByteSyncOnSyncword.syncIndicator
br label %136
132: ; preds = %112
br label %133
133: ; preds = %132
%134 = load i32, i32* %17
%135 = add nsw i32 %134, 1
store i32 %135, i32* %17
br label %108
136: ; preds = %131, %108
%137 = load i32, i32* @ByteSyncOnSyncword.syncIndicator
%138 = icmp eq i32 %137, 1
br i1 %138, label %139, label %156
139: ; preds = %136
%140 = load i32, i32* @ByteSyncOnSyncword.minorFrameShiftFlag
%141 = icmp eq i32 %140, 0
br i1 %141, label %142, label %156
142: ; preds = %139
%143 = load i32*, i32** %16
%144 = load double*, double** %10
%145 = load i64, i64* %19
%146 = getelementptr inbounds double, double* %144, i64 %145
%147 = load double, double* %146
%148 = call i32 (i32*, i8*, ...) @fprintf(i32* %143, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %147)
%149 = load i32*, i32** %16
%150 = call i32 (i32*, i8*, ...) @fprintf(i32* %149, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 237)
%151 = load i32*, i32** %16
%152 = call i32 (i32*, i8*, ...) @fprintf(i32* %151, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 226)
store i32 2, i32* @ByteSyncOnSyncword.frameByteIdx
store i32 1, i32* @ByteSyncOnSyncword.minorFrameShiftFlag
%153 = load i32, i32* %18
%154 = add nsw i32 %153, 1
store i32 %154, i32* %18
%155 = load i32, i32* %15
store i32 %155, i32* @ByteSyncOnSyncword.bitIdx
store i8 0, i8* @ByteSyncOnSyncword.byte
store i8 0, i8* @ByteSyncOnSyncword.zero
store i8 1, i8* @ByteSyncOnSyncword.one
br label %156
156: ; preds = %142, %139, %136
store i32 1, i32* @ByteSyncOnSyncword.syncIndicator
store i32 0, i32* %17
br label %157
157: ; preds = %182, %156
%158 = load i32, i32* %17
%159 = load i32, i32* %13
%160 = icmp ult i32 %158, %159
br i1 %160, label %161, label %185
161: ; preds = %157
%162 = load i8*, i8** %12
%163 = load i32, i32* %17
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds i8, i8* %162, i64 %164
%166 = load i8, i8* %165
%167 = sext i8 %166 to i32
%168 = load i8*, i8** @ByteSyncOnSyncword.historyBufferCirc
%169 = load i32, i32* @ByteSyncOnSyncword.oldest
%170 = load i32, i32* %17
%171 = add nsw i32 %169, %170
%172 = add nsw i32 %171, 1
%173 = load i32, i32* %13
%174 = urem i32 %172, %173
%175 = zext i32 %174 to i64
%176 = getelementptr inbounds i8, i8* %168, i64 %175
%177 = load i8, i8* %176
%178 = sext i8 %177 to i32
%179 = icmp eq i32 %167, %178
br i1 %179, label %180, label %181
180: ; preds = %161
store i32 0, i32* @ByteSyncOnSyncword.syncIndicator
br label %185
181: ; preds = %161
br label %182
182: ; preds = %181
%183 = load i32, i32* %17
%184 = add nsw i32 %183, 1
store i32 %184, i32* %17
br label %157
185: ; preds = %180, %157
%186 = load i32, i32* @ByteSyncOnSyncword.syncIndicator
%187 = icmp eq i32 %186, 1
br i1 %187, label %188, label %205
188: ; preds = %185
%189 = load i32, i32* @ByteSyncOnSyncword.minorFrameShiftFlag
%190 = icmp eq i32 %189, 0
br i1 %190, label %191, label %205
191: ; preds = %188
%192 = load i32*, i32** %16
%193 = load double*, double** %10
%194 = load i64, i64* %19
%195 = getelementptr inbounds double, double* %193, i64 %194
%196 = load double, double* %195
%197 = call i32 (i32*, i8*, ...) @fprintf(i32* %192, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %196)
%198 = load i32*, i32** %16
%199 = call i32 (i32*, i8*, ...) @fprintf(i32* %198, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 237)
%200 = load i32*, i32** %16
%201 = call i32 (i32*, i8*, ...) @fprintf(i32* %200, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 226)
store i32 2, i32* @ByteSyncOnSyncword.frameByteIdx
store i32 1, i32* @ByteSyncOnSyncword.minorFrameShiftFlag
%202 = load i32, i32* %18
%203 = add nsw i32 %202, 1
store i32 %203, i32* %18
%204 = load i32, i32* %15
store i32 %204, i32* @ByteSyncOnSyncword.bitIdx
store i8 0, i8* @ByteSyncOnSyncword.byte
store i8 1, i8* @ByteSyncOnSyncword.zero
store i8 0, i8* @ByteSyncOnSyncword.one
br label %205
205: ; preds = %191, %188, %185
%206 = load i32, i32* @ByteSyncOnSyncword.oldest
%207 = add nsw i32 %206, 1
%208 = load i32, i32* %13
%209 = urem i32 %207, %208
store i32 %209, i32* @ByteSyncOnSyncword.oldest
br label %210
210: ; preds = %205
%211 = load i64, i64* %19
%212 = add i64 %211, 1
store i64 %212, i64* %19
br label %43
213: ; preds = %43
%214 = load i32, i32* %18
ret i32 %214
}

LLVM IR (-O2):
@ByteSyncOnSyncword.firstTime = internal unnamed_addr global i1 false
@ByteSyncOnSyncword.historyBufferCirc = internal unnamed_addr global i8* null
@ByteSyncOnSyncword.oldest = internal unnamed_addr global i32 0
@ByteSyncOnSyncword.frameByteIdx = internal unnamed_addr global i32 0
@ByteSyncOnSyncword.minorFrameShiftFlag = internal unnamed_addr global i1 false
@ByteSyncOnSyncword.bitIdx = internal unnamed_addr global i32 0
@ByteSyncOnSyncword.zero = internal unnamed_addr global i1 false
@ByteSyncOnSyncword.one = internal unnamed_addr global i1 false
@ByteSyncOnSyncword.byte = internal unnamed_addr global i8 0
@.str.1 = [6 x i8] c"%.2X \00"
@.str.3 = [6 x i8] c"%.5f \00"
@.str.4 = [7 x i8] c"%.5fi \00"
@str = [16 x i8] c"Error in malloc\00"
define i32 @ByteSyncOnSyncword(i8* nocapture %0, double* nocapture %1, i64 %2, i8* nocapture %3, i32 %4, i32 %5, i32 %6, i32* nocapture %7) {
%9 = load i1, i1* @ByteSyncOnSyncword.firstTime
br i1 %9, label %19, label %10
10: ; preds = %8
store i1 true, i1* @ByteSyncOnSyncword.firstTime
%11 = tail call i64 @malloc(i32 %4)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** @ByteSyncOnSyncword.historyBufferCirc
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = tail call i32 @memset(i8* %12, i32 48, i32 %4)
br label %19
19: ; preds = %17, %8
%20 = icmp eq i64 %2, 0
br i1 %20, label %124, label %21
21: ; preds = %19
%22 = icmp eq i32 %4, 0
%23 = load i1, i1* @ByteSyncOnSyncword.minorFrameShiftFlag
%24 = zext i32 %4 to i64
%25 = zext i32 %4 to i64
br label %26
26: ; preds = %21, %116
%27 = phi i1 [ %23, %21 ], [ %117, %116 ]
%28 = phi i64 [ 0, %21 ], [ %122, %116 ]
%29 = phi i32 [ 0, %21 ], [ %118, %116 ]
br i1 %27, label %30, label %56
30: ; preds = %26
%31 = getelementptr inbounds i8, i8* %0, i64 %28
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 48
%34 = load i8, i8* @ByteSyncOnSyncword.byte
%35 = shl i8 %34, 1
br i1 %33, label %36, label %38
36: ; preds = %30
%37 = load i1, i1* @ByteSyncOnSyncword.zero
br label %41
38: ; preds = %30
%39 = load i1, i1* @ByteSyncOnSyncword.one
%40 = xor i1 %39, true
br label %41
41: ; preds = %38, %36
%42 = phi i1 [ %40, %38 ], [ %37, %36 ]
%43 = zext i1 %42 to i8
%44 = or i8 %35, %43
store i8 %44, i8* @ByteSyncOnSyncword.byte
%45 = load i32, i32* @ByteSyncOnSyncword.bitIdx
%46 = add nsw i32 %45, 1
store i32 %46, i32* @ByteSyncOnSyncword.bitIdx
%47 = icmp sgt i32 %45, 6
br i1 %47, label %48, label %56
48: ; preds = %41
%49 = zext i8 %44 to i32
%50 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %49)
store i8 0, i8* @ByteSyncOnSyncword.byte
store i32 0, i32* @ByteSyncOnSyncword.bitIdx
%51 = load i32, i32* @ByteSyncOnSyncword.frameByteIdx
%52 = add nsw i32 %51, 1
store i32 %52, i32* @ByteSyncOnSyncword.frameByteIdx
%53 = icmp slt i32 %51, %5
br i1 %53, label %56, label %54
54: ; preds = %48
store i1 false, i1* @ByteSyncOnSyncword.minorFrameShiftFlag
%55 = tail call i32 @fputc(i32 10, i32* %7)
br label %56
56: ; preds = %41, %54, %48, %26
%57 = getelementptr inbounds i8, i8* %0, i64 %28
%58 = load i8, i8* %57
%59 = load i8*, i8** @ByteSyncOnSyncword.historyBufferCirc
%60 = load i32, i32* @ByteSyncOnSyncword.oldest
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 %58, i8* %62
br i1 %22, label %79, label %65
63: ; preds = %65
%64 = icmp eq i64 %69, %24
br i1 %64, label %79, label %65
65: ; preds = %56, %63
%66 = phi i64 [ %69, %63 ], [ 0, %56 ]
%67 = getelementptr inbounds i8, i8* %3, i64 %66
%68 = load i8, i8* %67
%69 = add nuw nsw i64 %66, 1
%70 = trunc i64 %69 to i32
%71 = add i32 %60, %70
%72 = urem i32 %71, %4
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %59, i64 %73
%75 = load i8, i8* %74
%76 = icmp eq i8 %68, %75
br i1 %76, label %63, label %77
77: ; preds = %65
%78 = load i1, i1* @ByteSyncOnSyncword.minorFrameShiftFlag
br label %88
79: ; preds = %63, %56
%80 = load i1, i1* @ByteSyncOnSyncword.minorFrameShiftFlag
br i1 %80, label %88, label %81
81: ; preds = %79
%82 = getelementptr inbounds double, double* %1, i64 %28
%83 = load double, double* %82
%84 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %83)
%85 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 237)
%86 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 226)
store i32 2, i32* @ByteSyncOnSyncword.frameByteIdx
store i1 true, i1* @ByteSyncOnSyncword.minorFrameShiftFlag
%87 = add nsw i32 %29, 1
store i32 %6, i32* @ByteSyncOnSyncword.bitIdx
store i8 0, i8* @ByteSyncOnSyncword.byte
store i1 false, i1* @ByteSyncOnSyncword.zero
store i1 false, i1* @ByteSyncOnSyncword.one
br label %88
88: ; preds = %77, %81, %79
%89 = phi i1 [ true, %81 ], [ %80, %79 ], [ %78, %77 ]
%90 = phi i32 [ %87, %81 ], [ %29, %79 ], [ %29, %77 ]
br i1 %22, label %108, label %91
91: ; preds = %88
%92 = load i8*, i8** @ByteSyncOnSyncword.historyBufferCirc
%93 = load i32, i32* @ByteSyncOnSyncword.oldest
br label %96
94: ; preds = %96
%95 = icmp eq i64 %100, %25
br i1 %95, label %108, label %96
96: ; preds = %91, %94
%97 = phi i64 [ 0, %91 ], [ %100, %94 ]
%98 = getelementptr inbounds i8, i8* %3, i64 %97
%99 = load i8, i8* %98
%100 = add nuw nsw i64 %97, 1
%101 = trunc i64 %100 to i32
%102 = add i32 %93, %101
%103 = urem i32 %102, %4
%104 = zext i32 %103 to i64
%105 = getelementptr inbounds i8, i8* %92, i64 %104
%106 = load i8, i8* %105
%107 = icmp eq i8 %99, %106
br i1 %107, label %116, label %94
108: ; preds = %94, %88
br i1 %89, label %116, label %109
109: ; preds = %108
%110 = getelementptr inbounds double, double* %1, i64 %28
%111 = load double, double* %110
%112 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %111)
%113 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 237)
%114 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 226)
store i32 2, i32* @ByteSyncOnSyncword.frameByteIdx
store i1 true, i1* @ByteSyncOnSyncword.minorFrameShiftFlag
%115 = add nsw i32 %90, 1
store i32 %6, i32* @ByteSyncOnSyncword.bitIdx
store i8 0, i8* @ByteSyncOnSyncword.byte
store i1 true, i1* @ByteSyncOnSyncword.zero
store i1 true, i1* @ByteSyncOnSyncword.one
br label %116
116: ; preds = %96, %109, %108
%117 = phi i1 [ true, %109 ], [ %89, %108 ], [ %89, %96 ]
%118 = phi i32 [ %115, %109 ], [ %90, %108 ], [ %90, %96 ]
%119 = load i32, i32* @ByteSyncOnSyncword.oldest
%120 = add nsw i32 %119, 1
%121 = urem i32 %120, %4
store i32 %121, i32* @ByteSyncOnSyncword.oldest
%122 = add nuw i64 %28, 1
%123 = icmp eq i64 %122, %2
br i1 %123, label %124, label %26
124: ; preds = %116, %19
%125 = phi i32 [ 0, %19 ], [ %118, %116 ]
ret i32 %125
}