#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 */
unsigned char *gcr_find_sector_data(unsigned char *offset,
                                    unsigned char *gcr_track_start_ptr,
                                    unsigned int gcr_current_track_size) {
  unsigned char *GCR_track_end = gcr_track_start_ptr + gcr_current_track_size;
  int header = 0;
  while (*offset != 0xff) {
    offset++;
    if (offset >= GCR_track_end)
      offset = gcr_track_start_ptr;
    header++;
    if (header >= 500)
      return NULL;
  }
  while (*offset == 0xff) {
    offset++;
    if (offset == GCR_track_end)
      offset = gcr_track_start_ptr;
  }
  return offset;
}


x86 assembly (clang, -O0):
<gcr_find_sector_data>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
je     1180 <gcr_find_sector_data+0x80>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jb     1158 <gcr_find_sector_data+0x58>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x1f4,-0x2c(%rbp)
jl     117b <gcr_find_sector_data+0x7b>
movq   $0x0,-0x8(%rbp)
jmp    11c6 <gcr_find_sector_data+0xc6>
jmp    1124 <gcr_find_sector_data+0x24>
jmp    1185 <gcr_find_sector_data+0x85>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xff,%eax
jne    11be <gcr_find_sector_data+0xbe>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11b9 <gcr_find_sector_data+0xb9>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1185 <gcr_find_sector_data+0x85>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<gcr_find_sector_data>:
mov    %rdi,%rax
mov    %edx,%ecx
add    %rsi,%rcx
mov    $0x1f4,%edx
jmp    1115 <gcr_find_sector_data+0x15>
nop
add    $0xfffffffc,%edx
je     1171 <gcr_find_sector_data+0x71>
cmpb   $0xff,(%rax)
je     1160 <gcr_find_sector_data+0x60>
add    $0x1,%rax
cmp    %rcx,%rax
jb     1126 <gcr_find_sector_data+0x26>
mov    %rsi,%rax
cmpb   $0xff,(%rax)
je     1160 <gcr_find_sector_data+0x60>
add    $0x1,%rax
cmp    %rcx,%rax
jb     1137 <gcr_find_sector_data+0x37>
mov    %rsi,%rax
cmpb   $0xff,(%rax)
je     1160 <gcr_find_sector_data+0x60>
add    $0x1,%rax
cmp    %rcx,%rax
jb     1148 <gcr_find_sector_data+0x48>
mov    %rsi,%rax
cmpb   $0xff,(%rax)
je     1160 <gcr_find_sector_data+0x60>
add    $0x1,%rax
cmp    %rcx,%rax
jb     1110 <gcr_find_sector_data+0x10>
mov    %rsi,%rax
jmp    1110 <gcr_find_sector_data+0x10>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    %rcx,%rax
cmove  %rsi,%rax
cmpb   $0xff,(%rax)
je     1160 <gcr_find_sector_data+0x60>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i8* @gcr_find_sector_data(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
store i8* %13, i8** %8
store i32 0, i32* %9
br label %14
14: ; preds = %33, %3
%15 = load i8*, i8** %5
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp ne i32 %17, 255
br i1 %18, label %19, label %34
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = load i8*, i8** %8
%24 = icmp uge i8* %22, %23
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i8*, i8** %6
store i8* %26, i8** %5
br label %27
27: ; preds = %25, %19
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp sge i32 %30, 500
br i1 %31, label %32, label %33
32: ; preds = %27
store i8* null, i8** %4
br label %51
33: ; preds = %27
br label %14
34: ; preds = %14
br label %35
35: ; preds = %48, %34
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp eq i32 %38, 255
br i1 %39, label %40, label %49
40: ; preds = %35
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %5
%43 = load i8*, i8** %5
%44 = load i8*, i8** %8
%45 = icmp eq i8* %43, %44
br i1 %45, label %46, label %48
46: ; preds = %40
%47 = load i8*, i8** %6
store i8* %47, i8** %5
br label %48
48: ; preds = %46, %40
br label %35
49: ; preds = %35
%50 = load i8*, i8** %5
store i8* %50, i8** %4
br label %51
51: ; preds = %49, %32
%52 = load i8*, i8** %4
ret i8* %52
}

LLVM IR (-O2):
define i8* @gcr_find_sector_data(i8* %0, i8* %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = getelementptr inbounds i8, i8* %1, i64 %4
br label %6
6: ; preds = %31, %3
%7 = phi i8* [ %0, %3 ], [ %34, %31 ]
%8 = phi i32 [ 0, %3 ], [ %35, %31 ]
%9 = load i8, i8* %7
%10 = icmp eq i8 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %25, %19, %13, %6
%12 = phi i8* [ %7, %6 ], [ %16, %13 ], [ %22, %19 ], [ %28, %25 ]
br label %37
13: ; preds = %6
%14 = getelementptr inbounds i8, i8* %7, i64 1
%15 = icmp ult i8* %14, %5
%16 = select i1 %15, i8* %14, i8* %1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, -1
br i1 %18, label %11, label %19
19: ; preds = %13
%20 = getelementptr inbounds i8, i8* %16, i64 1
%21 = icmp ult i8* %20, %5
%22 = select i1 %21, i8* %20, i8* %1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, -1
br i1 %24, label %11, label %25
25: ; preds = %19
%26 = getelementptr inbounds i8, i8* %22, i64 1
%27 = icmp ult i8* %26, %5
%28 = select i1 %27, i8* %26, i8* %1
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, -1
br i1 %30, label %11, label %31
31: ; preds = %25
%32 = getelementptr inbounds i8, i8* %28, i64 1
%33 = icmp ult i8* %32, %5
%34 = select i1 %33, i8* %32, i8* %1
%35 = add nuw nsw i32 %8, 4
%36 = icmp eq i32 %35, 500
br i1 %36, label %44, label %6
37: ; preds = %11, %37
%38 = phi i8* [ %41, %37 ], [ %12, %11 ]
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = icmp eq i8* %39, %5
%41 = select i1 %40, i8* %1, i8* %39
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, -1
br i1 %43, label %37, label %44
44: ; preds = %31, %37
%45 = phi i8* [ %41, %37 ], [ null, %31 ]
ret i8* %45
}