#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 EOF;
int /*<<< orphan*/ SEEK_SET;
int fgetc(int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int findSyncWord(FILE *f) {
  int c;
  int i = 0;
  int buf = 0x000000000;
  c = fseek(f, (long)0, SEEK_SET);
  if (c != 0) {
    perror("findSyncWord");
    return -1;
  }
  while (1) {
    c = fgetc(f);
    if (c == EOF) {
      return -1;
    } else {
      buf = (buf << 8) | c;
      if (buf == 0xAA995566) {
        return i - 3;
      }
    }
    i++;
  }
}


x86 assembly (clang, -O0):
<findSyncWord>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1185 <findSyncWord+0x55>
lea    0xe8c(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <findSyncWord+0xbe>
jmp    118a <findSyncWord+0x5a>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%eax
jne    11b4 <findSyncWord+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <findSyncWord+0xbe>
mov    -0x1c(%rbp),%eax
shl    $0x8,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0xaa995566,-0x1c(%rbp)
jne    11db <findSyncWord+0xab>
mov    -0x18(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x4(%rbp)
jmp    11ee <findSyncWord+0xbe>
jmp    11e0 <findSyncWord+0xb0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118a <findSyncWord+0x5a>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findSyncWord>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r12
mov    0x2e96(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
test   %eax,%eax
jne    1194 <findSyncWord+0x64>
mov    %r12,%rdi
call   1030 <fgetc@plt>
mov    0x2e8a(%rip),%r15
mov    $0xffffffff,%r14d
cmp    (%r15),%eax
je     11a6 <findSyncWord+0x76>
xor    %ebx,%ebx
mov    $0xfffffffd,%ebp
shl    $0x8,%ebx
or     %eax,%ebx
cmp    $0xaa995566,%ebx
je     118f <findSyncWord+0x5f>
mov    %r12,%rdi
call   1030 <fgetc@plt>
add    $0x1,%ebp
cmp    (%r15),%eax
jne    1170 <findSyncWord+0x40>
jmp    11a6 <findSyncWord+0x76>
mov    %ebp,%r14d
jmp    11a6 <findSyncWord+0x76>
lea    0xe65(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [13 x i8] c"findSyncWord\00"
@EOF = global i32 0
define i32 @findSyncWord(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %5
store i32 0, i32* %6
%7 = load i32*, i32** %3
%8 = load i32, i32* @SEEK_SET
%9 = call i32 @fseek(i32* %7, i64 0, i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %36
14: ; preds = %1
br label %15
15: ; preds = %14, %33
%16 = load i32*, i32** %3
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 -1, i32* %2
br label %36
22: ; preds = %15
%23 = load i32, i32* %6
%24 = shl i32 %23, 8
%25 = load i32, i32* %4
%26 = or i32 %24, %25
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, -1432791706
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* %5
%31 = sub nsw i32 %30, 3
store i32 %31, i32* %2
br label %36
32: ; preds = %22
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %15
36: ; preds = %29, %21, %12
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [13 x i8] c"findSyncWord\00"
@EOF = global i32 0
define i32 @findSyncWord(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_SET
%3 = tail call i32 @fseek(i32* %0, i64 0, i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = tail call i32 @fgetc(i32* %0)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %25, label %11
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %25
11: ; preds = %5, %20
%12 = phi i32 [ %22, %20 ], [ %6, %5 ]
%13 = phi i32 [ %16, %20 ], [ 0, %5 ]
%14 = phi i32 [ %21, %20 ], [ 0, %5 ]
%15 = shl i32 %13, 8
%16 = or i32 %15, %12
%17 = icmp eq i32 %16, -1432791706
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = add nsw i32 %14, -3
br label %25
20: ; preds = %11
%21 = add nuw nsw i32 %14, 1
%22 = tail call i32 @fgetc(i32* %0)
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %11
25: ; preds = %20, %5, %18, %9
%26 = phi i32 [ -1, %9 ], [ %19, %18 ], [ -1, %5 ], [ -1, %20 ]
ret i32 %26
}