#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*/ SEEK_SET;
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int id3_lseek_syncword_r(int fd, unsigned char *data, int checked) {
  unsigned char lastchar;
  int i;
  for (i = 0; i + 1 < 4096; i++) {
    if (((data[i] & 0xFF) == 0xFF) &&
        (((data[i + 1] & 0xF0) == 0xF0) || ((data[i + 1] == 0xE0) & 0xE0))) {
      lseek(fd, checked + i, SEEK_SET);
      return 0;
    }
  }
  lastchar = data[4096 - 1];
  if (read(fd, data, 4096) < 1)
    return 0;
  if (((lastchar & 0xFF) == 0xFF) && ((data[0] & 0xE0) == 0xE0)) {
    lseek(fd, checked + 4096 - 1, SEEK_SET);
    return 0;
  }
  return id3_lseek_syncword_r(fd, data, checked + 4096);
}


x86 assembly (clang, -O0):
<id3_lseek_syncword_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    $0x1000,%eax
jge    11f9 <id3_lseek_syncword_r+0xc9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0xff,%eax
jne    11e6 <id3_lseek_syncword_r+0xb6>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf0,%eax
cmp    $0xf0,%eax
je     11c3 <id3_lseek_syncword_r+0x93>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xe0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
and    $0xe0,%eax
cmp    $0x0,%eax
je     11e6 <id3_lseek_syncword_r+0xb6>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
add    -0x1c(%rbp),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
movl   $0x0,-0x4(%rbp)
jmp    1298 <id3_lseek_syncword_r+0x168>
jmp    11eb <id3_lseek_syncword_r+0xbb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <id3_lseek_syncword_r+0x19>
mov    -0x10(%rbp),%rax
mov    0xfff(%rax),%al
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jge    122c <id3_lseek_syncword_r+0xfc>
movl   $0x0,-0x4(%rbp)
jmp    1298 <id3_lseek_syncword_r+0x168>
movzbl -0x15(%rbp),%eax
and    $0xff,%eax
cmp    $0xff,%eax
jne    1280 <id3_lseek_syncword_r+0x150>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
and    $0xe0,%eax
cmp    $0xe0,%eax
jne    1280 <id3_lseek_syncword_r+0x150>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
add    $0x1000,%esi
sub    $0x1,%esi
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
movl   $0x0,-0x4(%rbp)
jmp    1298 <id3_lseek_syncword_r+0x168>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x1000,%edx
call   1050 <id3_lseek_syncword_r@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id3_lseek_syncword_r>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %edi,%r14d
xor    %eax,%eax
jmp    114c <id3_lseek_syncword_r+0x2c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x3,%rax
cmp    $0xfff,%rax
je     1180 <id3_lseek_syncword_r+0x60>
cmpb   $0xff,0x0(%rbp,%rax,1)
jne    115a <id3_lseek_syncword_r+0x3a>
cmpb   $0xef,0x1(%rbp,%rax,1)
ja     11b8 <id3_lseek_syncword_r+0x98>
cmpb   $0xff,0x1(%rbp,%rax,1)
jne    1168 <id3_lseek_syncword_r+0x48>
cmpb   $0xef,0x2(%rbp,%rax,1)
ja     11ae <id3_lseek_syncword_r+0x8e>
cmpb   $0xff,0x2(%rbp,%rax,1)
jne    1140 <id3_lseek_syncword_r+0x20>
cmpb   $0xef,0x3(%rbp,%rax,1)
jbe    1140 <id3_lseek_syncword_r+0x20>
jmp    11b4 <id3_lseek_syncword_r+0x94>
nopl   0x0(%rax,%rax,1)
mov    0xfff(%rbp),%bl
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    11cf <id3_lseek_syncword_r+0xaf>
cmp    $0xff,%bl
jne    11a5 <id3_lseek_syncword_r+0x85>
cmpb   $0xdf,0x0(%rbp)
ja     11dc <id3_lseek_syncword_r+0xbc>
add    $0x1000,%r15d
jmp    1130 <id3_lseek_syncword_r+0x10>
add    $0x1,%rax
jmp    11b8 <id3_lseek_syncword_r+0x98>
add    $0x2,%rax
add    %eax,%r15d
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
mov    %r15d,%esi
call   1030 <lseek@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xfff,%eax
jmp    11b8 <id3_lseek_syncword_r+0x98>

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @id3_lseek_syncword_r(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %9
br label %10
10: ; preds = %53, %3
%11 = load i32, i32* %9
%12 = add nsw i32 %11, 1
%13 = icmp slt i32 %12, 4096
br i1 %13, label %14, label %56
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = and i32 %20, 255
%22 = icmp eq i32 %21, 255
br i1 %22, label %23, label %52
23: ; preds = %14
%24 = load i8*, i8** %6
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = and i32 %30, 240
%32 = icmp eq i32 %31, 240
br i1 %32, label %45, label %33
33: ; preds = %23
%34 = load i8*, i8** %6
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = icmp eq i32 %40, 224
%42 = zext i1 %41 to i32
%43 = and i32 %42, 224
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %52
45: ; preds = %33, %23
%46 = load i32, i32* %5
%47 = load i32, i32* %7
%48 = load i32, i32* %9
%49 = add nsw i32 %47, %48
%50 = load i32, i32* @SEEK_SET
%51 = call i32 @lseek(i32 %46, i32 %49, i32 %50)
store i32 0, i32* %4
br label %90
52: ; preds = %33, %14
br label %53
53: ; preds = %52
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %10
56: ; preds = %10
%57 = load i8*, i8** %6
%58 = getelementptr inbounds i8, i8* %57, i64 4095
%59 = load i8, i8* %58
store i8 %59, i8* %8
%60 = load i32, i32* %5
%61 = load i8*, i8** %6
%62 = call i32 @read(i32 %60, i8* %61, i32 4096)
%63 = icmp slt i32 %62, 1
br i1 %63, label %64, label %65
64: ; preds = %56
store i32 0, i32* %4
br label %90
65: ; preds = %56
%66 = load i8, i8* %8
%67 = zext i8 %66 to i32
%68 = and i32 %67, 255
%69 = icmp eq i32 %68, 255
br i1 %69, label %70, label %84
70: ; preds = %65
%71 = load i8*, i8** %6
%72 = getelementptr inbounds i8, i8* %71, i64 0
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = and i32 %74, 224
%76 = icmp eq i32 %75, 224
br i1 %76, label %77, label %84
77: ; preds = %70
%78 = load i32, i32* %5
%79 = load i32, i32* %7
%80 = add nsw i32 %79, 4096
%81 = sub nsw i32 %80, 1
%82 = load i32, i32* @SEEK_SET
%83 = call i32 @lseek(i32 %78, i32 %81, i32 %82)
store i32 0, i32* %4
br label %90
84: ; preds = %70, %65
%85 = load i32, i32* %5
%86 = load i8*, i8** %6
%87 = load i32, i32* %7
%88 = add nsw i32 %87, 4096
%89 = call i32 @id3_lseek_syncword_r(i32 %85, i8* %86, i32 %88)
store i32 %89, i32* %4
br label %90
90: ; preds = %84, %77, %64, %45
%91 = load i32, i32* %4
ret i32 %91
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @id3_lseek_syncword_r(i32 %0, i8* nocapture %1, i32 %2) {
%4 = getelementptr inbounds i8, i8* %1, i64 4095
br label %5
5: ; preds = %53, %3
%6 = phi i32 [ %2, %3 ], [ %54, %53 ]
br label %7
7: ; preds = %41, %5
%8 = phi i64 [ 0, %5 ], [ %32, %41 ]
%9 = phi i64 [ 1, %5 ], [ %42, %41 ]
%10 = add nuw nsw i64 %8, 1
%11 = getelementptr inbounds i8, i8* %1, i64 %8
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %7
%15 = getelementptr inbounds i8, i8* %1, i64 %9
%16 = load i8, i8* %15
%17 = icmp ugt i8 %16, -17
br i1 %17, label %18, label %21
18: ; preds = %36, %26, %14
%19 = phi i64 [ %8, %14 ], [ %10, %26 ], [ %22, %36 ]
%20 = trunc i64 %19 to i32
br label %55
21: ; preds = %14, %7
%22 = add nuw nsw i64 %8, 2
%23 = getelementptr inbounds i8, i8* %1, i64 %10
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = add nuw nsw i64 %9, 1
%28 = getelementptr inbounds i8, i8* %1, i64 %27
%29 = load i8, i8* %28
%30 = icmp ugt i8 %29, -17
br i1 %30, label %18, label %31
31: ; preds = %26, %21
%32 = add nuw nsw i64 %8, 3
%33 = getelementptr inbounds i8, i8* %1, i64 %22
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, -1
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = add nuw nsw i64 %9, 2
%38 = getelementptr inbounds i8, i8* %1, i64 %37
%39 = load i8, i8* %38
%40 = icmp ugt i8 %39, -17
br i1 %40, label %18, label %41
41: ; preds = %36, %31
%42 = add nuw nsw i64 %9, 3
%43 = icmp eq i64 %32, 4095
br i1 %43, label %44, label %7
44: ; preds = %41
%45 = load i8, i8* %4
%46 = tail call i32 @read(i32 %0, i8* %1, i32 4096)
%47 = icmp slt i32 %46, 1
br i1 %47, label %60, label %48
48: ; preds = %44
%49 = icmp eq i8 %45, -1
br i1 %49, label %50, label %53
50: ; preds = %48
%51 = load i8, i8* %1
%52 = icmp ugt i8 %51, -33
br i1 %52, label %55, label %53
53: ; preds = %50, %48
%54 = add nsw i32 %6, 4096
br label %5
55: ; preds = %50, %18
%56 = phi i32 [ %20, %18 ], [ 4095, %50 ]
%57 = add nsw i32 %6, %56
%58 = load i32, i32* @SEEK_SET
%59 = tail call i32 @lseek(i32 %0, i32 %57, i32 %58)
br label %60
60: ; preds = %44, %55
ret i32 0
}