#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 FindSyncWords(unsigned char *bitStreamIn, double *bitStreamInTime,
                  unsigned long nSamples, char *syncWord,
                  unsigned int syncWordLength, FILE *packetFile) {
  int idx2;
  static char firstTime = 1;
  static char *historyBufferCirc;
  static int oldest = 0, syncIndicator, frameByteIdx, packetShiftFlag = 0,
             bitIdx;
  static unsigned char zero = 0, one = 1;
  static unsigned char byte = 0;
  int packetsFound = 0;
  unsigned long idx;
  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 (packetShiftFlag == 1) {
      if (bitStreamIn[idx] == '0') {
        byte = byte << 1;
        byte = byte | zero;
      } else {
        byte = byte << 1;
        byte = byte | one;
      }
      bitIdx++;
      if (bitIdx > 7) {
        fprintf(packetFile, "%.2X ", byte);
        printf("%.2X ", byte);
        byte = 0;
        bitIdx = 0;
        frameByteIdx++;
        if (frameByteIdx > 8) {
          packetShiftFlag = 0;
          fprintf(packetFile, "\n");
          printf("\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 && packetShiftFlag == 0) {
      fprintf(packetFile, "%.5f ", bitStreamInTime[idx]);
      printf("%.5f ", bitStreamInTime[idx]);
      frameByteIdx = 2;
      packetShiftFlag = 1;
      packetsFound++;
      bitIdx = 0;
      byte = 0;
      zero = 0;
      one = 1;
    }
    syncIndicator = 0;
    for (idx2 = 0; idx2 < syncWordLength; idx2++) {
      if (syncWord[idx2] ==
          historyBufferCirc[(oldest + idx2 + 1) % syncWordLength]) {
        syncIndicator = 0;
        break;
      }
    }
    if (syncIndicator == 1 && packetShiftFlag == 0) {
      fprintf(packetFile, "%.5fi ", bitStreamInTime[idx]);
      printf("\t%.5fi ", bitStreamInTime[idx]);
      frameByteIdx = 2;
      packetShiftFlag = 1;
      packetsFound++;
      bitIdx = 0;
      byte = 0;
      zero = 1;
      one = 0;
    }
    oldest = (oldest + 1) % syncWordLength;
  }
  return packetsFound;
}


x86 assembly (clang, -O0):
<FindSyncWords>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
movsbl 0x2eca(%rip),%eax
cmp    $0x1,%eax
jne    11e3 <FindSyncWords+0x93>
movb   $0x0,0x2eba(%rip)
mov    -0x24(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,0x2eb5(%rip)
cmpq   $0x0,0x2ead(%rip)
jne    11c9 <FindSyncWords+0x79>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2e88(%rip),%rdi
mov    -0x24(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edx
mov    $0x30,%esi
call   1040 <memset@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1566 <FindSyncWords+0x416>
cmpl   $0x1,0x2e6c(%rip)
jne    1317 <FindSyncWords+0x1c7>
mov    -0x8(%rbp),%rax
mov    -0x40(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    1246 <FindSyncWords+0xf6>
movzbl 0x2e53(%rip),%eax
shl    $0x1,%eax
mov    %al,0x2e4a(%rip)
movzbl 0x2e43(%rip),%eax
movzbl 0x2e3b(%rip),%ecx
or     %ecx,%eax
mov    %al,0x2e34(%rip)
jmp    126c <FindSyncWords+0x11c>
movzbl 0x2e28(%rip),%eax
shl    $0x1,%eax
mov    %al,0x2e1f(%rip)
movzbl 0x2e18(%rip),%eax
movzbl 0x2de5(%rip),%ecx
or     %ecx,%eax
mov    %al,0x2e09(%rip)
mov    0x2dfe(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2df5(%rip)
cmpl   $0x7,0x2dee(%rip)
jle    1312 <FindSyncWords+0x1c2>
mov    -0x30(%rbp),%rdi
movzbl 0x2de2(%rip),%edx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movzbl 0x2dcd(%rip),%esi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x0,0x2db8(%rip)
movl   $0x0,0x2da9(%rip)
mov    0x2d9b(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2d92(%rip)
cmpl   $0x8,0x2d8b(%rip)
jle    130d <FindSyncWords+0x1bd>
movl   $0x0,0x2d7f(%rip)
mov    -0x30(%rbp),%rdi
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    0xd09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1312 <FindSyncWords+0x1c2>
jmp    1317 <FindSyncWords+0x1c7>
mov    -0x8(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    0x2d2f(%rip),%rax
movslq 0x2d30(%rip),%rcx
mov    %dl,(%rax,%rcx,1)
movl   $0x1,0x2d27(%rip)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    13aa <FindSyncWords+0x25a>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x44(%rbp)
mov    0x2cf2(%rip),%rcx
mov    0x2cf4(%rip),%eax
add    -0x34(%rbp),%eax
add    $0x1,%eax
xor    %edx,%edx
divl   -0x24(%rbp)
mov    -0x44(%rbp),%eax
mov    %edx,%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     1397 <FindSyncWords+0x247>
movl   $0x0,0x2cd2(%rip)
jmp    13aa <FindSyncWords+0x25a>
jmp    139c <FindSyncWords+0x24c>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1344 <FindSyncWords+0x1f4>
cmpl   $0x1,0x2cb3(%rip)
jne    143a <FindSyncWords+0x2ea>
cmpl   $0x0,0x2cae(%rip)
jne    143a <FindSyncWords+0x2ea>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xc3b(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xc20(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x2,0x2c60(%rip)
movl   $0x1,0x2c5a(%rip)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,0x2c4b(%rip)
movb   $0x0,0x2c49(%rip)
movb   $0x0,0x2c41(%rip)
movb   $0x1,0x2c0f(%rip)
movl   $0x0,0x2c20(%rip)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    14b1 <FindSyncWords+0x361>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x48(%rbp)
mov    0x2beb(%rip),%rcx
mov    0x2bed(%rip),%eax
add    -0x34(%rbp),%eax
add    $0x1,%eax
xor    %edx,%edx
divl   -0x24(%rbp)
mov    -0x48(%rbp),%eax
mov    %edx,%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    149e <FindSyncWords+0x34e>
movl   $0x0,0x2bcb(%rip)
jmp    14b1 <FindSyncWords+0x361>
jmp    14a3 <FindSyncWords+0x353>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    144b <FindSyncWords+0x2fb>
cmpl   $0x1,0x2bac(%rip)
jne    1541 <FindSyncWords+0x3f1>
cmpl   $0x0,0x2ba7(%rip)
jne    1541 <FindSyncWords+0x3f1>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xb3b(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xb1f(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movl   $0x2,0x2b59(%rip)
movl   $0x1,0x2b53(%rip)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,0x2b44(%rip)
movb   $0x0,0x2b42(%rip)
movb   $0x1,0x2b3a(%rip)
movb   $0x0,0x2b08(%rip)
mov    0x2b19(%rip),%eax
add    $0x1,%eax
xor    %edx,%edx
divl   -0x24(%rbp)
mov    %edx,0x2b0b(%rip)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11eb <FindSyncWords+0x9b>
mov    -0x38(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FindSyncWords>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x10(%rsp)
mov    %r8d,%r15d
mov    %rcx,%r13
mov    %rdx,0x18(%rsp)
mov    %rsi,0x20(%rsp)
cmpb   $0x0,0x2ebe(%rip)
mov    %rdi,0x8(%rsp)
jne    11e5 <FindSyncWords+0x65>
movb   $0x1,0x2eb0(%rip)
mov    %r15d,%edi
call   1090 <malloc@plt>
mov    %rax,0x2ea9(%rip)
test   %rax,%rax
je     13c0 <FindSyncWords+0x240>
mov    %rax,%rdi
mov    $0x30,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
mov    0x8(%rsp),%rdi
cmpq   $0x0,0x18(%rsp)
je     13a5 <FindSyncWords+0x225>
mov    0x2e89(%rip),%bl
mov    %r15d,%r14d
xor    %r12d,%r12d
movl   $0x0,0x4(%rsp)
jmp    1239 <FindSyncWords+0xb9>
nopw   0x0(%rax,%rax,1)
mov    0x2e6a(%rip),%bl
mov    0x2e5c(%rip),%eax
add    $0x1,%eax
xor    %edx,%edx
div    %r15d
mov    %edx,0x2e4e(%rip)
add    $0x1,%r12
cmp    0x18(%rsp),%r12
je     13ad <FindSyncWords+0x22d>
test   $0x1,%bl
je     12f0 <FindSyncWords+0x170>
cmpb   $0x30,(%rdi,%r12,1)
setne  %cl
mov    0x2e38(%rip),%al
add    %al,%al
or     %cl,%al
mov    %al,0x2e2e(%rip)
mov    0x2e24(%rip),%ecx
lea    0x1(%rcx),%edx
mov    %edx,0x2e1b(%rip)
cmp    $0x7,%ecx
jl     12f0 <FindSyncWords+0x170>
movzbl %al,%edx
mov    0x10(%rsp),%rdi
lea    0xd7f(%rip),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
movzbl 0x2df6(%rip),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
movb   $0x0,0x2de0(%rip)
movl   $0x0,0x2dd2(%rip)
mov    0x2dc4(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2dbb(%rip)
cmp    $0x8,%eax
jl     12f0 <FindSyncWords+0x170>
movb   $0x0,0x2db3(%rip)
mov    $0xa,%edi
mov    0x10(%rsp),%rsi
call   1070 <fputc@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x8(%rsp),%rdi
nopl   0x0(%rax,%rax,1)
mov    (%rdi,%r12,1),%al
mov    0x2d75(%rip),%rcx
movslq 0x2d76(%rip),%rsi
mov    %al,(%rcx,%rsi,1)
test   %r15d,%r15d
je     1330 <FindSyncWords+0x1b0>
add    $0x1,%esi
xor    %ebp,%ebp
nop
movzbl 0x0(%r13,%rbp,1),%ebx
lea    (%rsi,%rbp,1),%eax
xor    %edx,%edx
div    %r15d
cmp    (%rcx,%rdx,1),%bl
jne    1210 <FindSyncWords+0x90>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1310 <FindSyncWords+0x190>
mov    0x2d4a(%rip),%bl
test   %bl,%bl
jne    1216 <FindSyncWords+0x96>
mov    0x20(%rsp),%rbp
movsd  0x0(%rbp,%r12,8),%xmm0
mov    $0x1,%bl
mov    0x10(%rsp),%rdi
lea    0xcae(%rip),%rsi
mov    $0x1,%al
call   1080 <fprintf@plt>
movsd  0x0(%rbp,%r12,8),%xmm0
lea    0xc99(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
movl   $0x2,0x2cf9(%rip)
movb   $0x1,0x2cf6(%rip)
addl   $0x1,0x4(%rsp)
movl   $0x0,0x2ceb(%rip)
movb   $0x0,0x2ce8(%rip)
jmp    1216 <FindSyncWords+0x96>
movl   $0x0,0x4(%rsp)
mov    0x4(%rsp),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc45(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
@FindSyncWords.firstTime = internal unnamed_addr global i1 false
@FindSyncWords.historyBufferCirc = internal unnamed_addr global i8* null
@FindSyncWords.oldest = internal unnamed_addr global i32 0
@FindSyncWords.frameByteIdx = internal unnamed_addr global i32 0
@FindSyncWords.packetShiftFlag = internal unnamed_addr global i1 false
@FindSyncWords.bitIdx = internal unnamed_addr global i32 0
@FindSyncWords.byte = internal unnamed_addr global i8 0
@.str.1 = [6 x i8] c"%.2X \00"
@.str.3 = [6 x i8] c"%.5f \00"
@str = [16 x i8] c"Error in malloc\00"
define i32 @FindSyncWords(i8* nocapture %0, double* nocapture %1, i64 %2, i8* nocapture %3, i32 %4, i32* nocapture %5) {
%7 = load i1, i1* @FindSyncWords.firstTime
br i1 %7, label %17, label %8
8: ; preds = %6
store i1 true, i1* @FindSyncWords.firstTime
%9 = tail call i64 @malloc(i32 %4)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** @FindSyncWords.historyBufferCirc
%11 = icmp eq i64 %9, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = tail call i32 @memset(i8* %10, i32 48, i32 %4)
br label %17
17: ; preds = %15, %6
%18 = icmp eq i64 %2, 0
br i1 %18, label %90, label %19
19: ; preds = %17
%20 = icmp eq i32 %4, 0
%21 = load i1, i1* @FindSyncWords.packetShiftFlag
%22 = zext i32 %4 to i64
br label %23
23: ; preds = %19, %82
%24 = phi i1 [ %21, %19 ], [ %83, %82 ]
%25 = phi i64 [ 0, %19 ], [ %88, %82 ]
%26 = phi i32 [ 0, %19 ], [ %84, %82 ]
br i1 %24, label %27, label %50
27: ; preds = %23
%28 = getelementptr inbounds i8, i8* %0, i64 %25
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 48
%31 = load i8, i8* @FindSyncWords.byte
%32 = shl i8 %31, 1
%33 = zext i1 %30 to i8
%34 = or i8 %32, %33
store i8 %34, i8* @FindSyncWords.byte
%35 = load i32, i32* @FindSyncWords.bitIdx
%36 = add nsw i32 %35, 1
store i32 %36, i32* @FindSyncWords.bitIdx
%37 = icmp sgt i32 %35, 6
br i1 %37, label %38, label %50
38: ; preds = %27
%39 = zext i8 %34 to i32
%40 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i8, i8* @FindSyncWords.byte
%42 = zext i8 %41 to i32
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %42)
store i8 0, i8* @FindSyncWords.byte
store i32 0, i32* @FindSyncWords.bitIdx
%44 = load i32, i32* @FindSyncWords.frameByteIdx
%45 = add nsw i32 %44, 1
store i32 %45, i32* @FindSyncWords.frameByteIdx
%46 = icmp sgt i32 %44, 7
br i1 %46, label %47, label %50
47: ; preds = %38
store i1 false, i1* @FindSyncWords.packetShiftFlag
%48 = tail call i32 @fputc(i32 10, i32* %5)
%49 = tail call i32 @putchar(i32 10)
br label %50
50: ; preds = %27, %47, %38, %23
%51 = getelementptr inbounds i8, i8* %0, i64 %25
%52 = load i8, i8* %51
%53 = load i8*, i8** @FindSyncWords.historyBufferCirc
%54 = load i32, i32* @FindSyncWords.oldest
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 %52, i8* %56
br i1 %20, label %73, label %59
57: ; preds = %59
%58 = icmp eq i64 %63, %22
br i1 %58, label %73, label %59
59: ; preds = %50, %57
%60 = phi i64 [ %63, %57 ], [ 0, %50 ]
%61 = getelementptr inbounds i8, i8* %3, i64 %60
%62 = load i8, i8* %61
%63 = add nuw nsw i64 %60, 1
%64 = trunc i64 %63 to i32
%65 = add i32 %54, %64
%66 = urem i32 %65, %4
%67 = zext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %53, i64 %67
%69 = load i8, i8* %68
%70 = icmp eq i8 %62, %69
br i1 %70, label %57, label %71
71: ; preds = %59
%72 = load i1, i1* @FindSyncWords.packetShiftFlag
br label %82
73: ; preds = %57, %50
%74 = load i1, i1* @FindSyncWords.packetShiftFlag
br i1 %74, label %82, label %75
75: ; preds = %73
%76 = getelementptr inbounds double, double* %1, i64 %25
%77 = load double, double* %76
%78 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %77)
%79 = load double, double* %76
%80 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %79)
store i32 2, i32* @FindSyncWords.frameByteIdx
store i1 true, i1* @FindSyncWords.packetShiftFlag
%81 = add nsw i32 %26, 1
store i32 0, i32* @FindSyncWords.bitIdx
store i8 0, i8* @FindSyncWords.byte
br label %82
82: ; preds = %71, %75, %73
%83 = phi i1 [ true, %75 ], [ %74, %73 ], [ %72, %71 ]
%84 = phi i32 [ %81, %75 ], [ %26, %73 ], [ %26, %71 ]
%85 = load i32, i32* @FindSyncWords.oldest
%86 = add nsw i32 %85, 1
%87 = urem i32 %86, %4
store i32 %87, i32* @FindSyncWords.oldest
%88 = add nuw i64 %25, 1
%89 = icmp eq i64 %88, %2
br i1 %89, label %90, label %23
90: ; preds = %82, %17
%91 = phi i32 [ 0, %17 ], [ %84, %82 ]
ret i32 %91
}