#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 BUFSIZ;
int /*<<< orphan*/ input_close_fd(int);
int input_open_fd(char *);
int input_read_fd(int, unsigned char *, unsigned int);
unsigned char *memchr(unsigned char *, float, size_t);
int /*<<< orphan*/ memcmp(char *, unsigned char *, int);
int /*<<< orphan*/ memmove(unsigned char *, unsigned char *, size_t);
int input_read_mp3_padding(char *filename, unsigned *start, unsigned *end) {
  unsigned char buffer[BUFSIZ];
  int fd = input_open_fd(filename);
  int bytes_read, bytes_read_new;
  if (fd < 0) {
    *start = *end = 0;
    return 1;
  }
  while ((bytes_read = input_read_fd(fd, buffer, BUFSIZ)) > 0) {
    unsigned char *match_maybe = memchr(buffer, '\xFF', (size_t)bytes_read);
    while (match_maybe) {
      size_t good_bytes = (size_t)(buffer + bytes_read - match_maybe);
      memmove(buffer, match_maybe, good_bytes);
      bytes_read_new = input_read_fd(fd, buffer + good_bytes,
                                     (unsigned int)(BUFSIZ - good_bytes));
      if (bytes_read_new < 0)
        break;
      bytes_read = (int)good_bytes + bytes_read_new;
      if (bytes_read >= 180 && !memcmp("\xFF\xFB", buffer, 2) &&
          !memcmp("\x00\x00\x00\x00\x00\x00\x00\x00"
                  "\x00\x00\x00\x00\x00\x00\x00\x00",
                  buffer + 4, 16)) {
        *start = (unsigned)((buffer[177] << 4) + (buffer[178] >> 4));
        *end = (unsigned)(((buffer[178] & 0x0f) << 8) + buffer[179]);
        input_close_fd(fd);
        return 0;
      }
      match_maybe = memchr(buffer + 1, '\xFF', (size_t)(bytes_read - 1));
    }
  }
  input_close_fd(fd);
  return 1;
}


x86 assembly (clang, -O0):
<input_read_mp3_padding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <input_open_fd@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11dd <input_read_mp3_padding+0x7d>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    136f <input_read_mp3_padding+0x20f>
jmp    11e2 <input_read_mp3_padding+0x82>
mov    -0x58(%rbp),%rsi
mov    -0x34(%rbp),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
call   1080 <input_read_fd@plt>
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jle    1359 <input_read_mp3_padding+0x1f9>
mov    -0x58(%rbp),%rdi
movslq -0x38(%rbp),%rsi
movss  0xded(%rip),%xmm0
call   1030 <memchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1354 <input_read_mp3_padding+0x1f4>
mov    -0x58(%rbp),%rdi
movslq -0x38(%rbp),%rcx
mov    %rdi,%rax
add    %rcx,%rax
mov    -0x48(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1070 <memmove@plt>
mov    -0x58(%rbp),%rsi
mov    -0x34(%rbp),%edi
add    -0x50(%rbp),%rsi
mov    0x2d81(%rip),%rax
movslq (%rax),%rax
sub    -0x50(%rbp),%rax
mov    %eax,%edx
call   1080 <input_read_fd@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    127f <input_read_mp3_padding+0x11f>
jmp    1354 <input_read_mp3_padding+0x1f4>
mov    -0x50(%rbp),%rax
add    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpl   $0xb4,-0x38(%rbp)
jl     132d <input_read_mp3_padding+0x1cd>
mov    -0x58(%rbp),%rsi
lea    0xd63(%rip),%rdi
mov    $0x2,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    132d <input_read_mp3_padding+0x1cd>
mov    -0x58(%rbp),%rsi
add    $0x4,%rsi
lea    0xd44(%rip),%rdi
mov    $0x10,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    132d <input_read_mp3_padding+0x1cd>
mov    -0x58(%rbp),%rax
movzbl 0xb1(%rax),%edx
shl    $0x4,%edx
movzbl 0xb2(%rax),%ecx
sar    $0x4,%ecx
add    %ecx,%edx
mov    -0x18(%rbp),%rcx
mov    %edx,(%rcx)
movzbl 0xb2(%rax),%ecx
and    $0xf,%ecx
shl    $0x8,%ecx
movzbl 0xb3(%rax),%eax
add    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x34(%rbp),%edi
call   1050 <input_close_fd@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
jmp    136f <input_read_mp3_padding+0x20f>
mov    -0x58(%rbp),%rdi
add    $0x1,%rdi
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rsi
movss  0xcba(%rip),%xmm0
call   1030 <memchr@plt>
mov    %rax,-0x48(%rbp)
jmp    121c <input_read_mp3_padding+0xbc>
jmp    11e2 <input_read_mp3_padding+0x82>
mov    -0x34(%rbp),%edi
call   1050 <input_close_fd@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input_read_mp3_padding>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    0x2e62(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1060 <input_open_fd@plt>
test   %eax,%eax
js     12e2 <input_read_mp3_padding+0x182>
mov    %eax,%r12d
mov    %r15,-0x30(%rbp)
mov    %r14,-0x38(%rbp)
mov    0x0(%r13),%edx
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <input_read_fd@plt>
test   %eax,%eax
jle    12f2 <input_read_mp3_padding+0x192>
mov    %eax,%r13d
lea    0x4(%rbx),%rax
mov    %rax,-0x40(%rbp)
lea    0x1(%rbx),%r14
jmp    11ff <input_read_mp3_padding+0x9f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
mov    %rbx,%rsi
call   1080 <input_read_fd@plt>
mov    %eax,%r13d
test   %eax,%eax
jle    12f2 <input_read_mp3_padding+0x192>
mov    %r13d,%esi
mov    %rbx,%rdi
jmp    121a <input_read_mp3_padding+0xba>
nopw   0x0(%rax,%rax,1)
lea    -0x1(%r13),%eax
movslq %eax,%rsi
mov    %r14,%rdi
movss  0xdde(%rip),%xmm0
call   1030 <memchr@plt>
test   %rax,%rax
je     11e0 <input_read_mp3_padding+0x80>
movslq %r13d,%r15
add    %rbx,%r15
sub    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r15,%rdx
call   1070 <memmove@plt>
lea    (%rbx,%r15,1),%rsi
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
sub    %r15d,%edx
mov    %r12d,%edi
call   1080 <input_read_fd@plt>
test   %eax,%eax
js     11e0 <input_read_mp3_padding+0x80>
mov    %eax,%r13d
add    %r15d,%r13d
cmp    $0xb4,%r13d
jl     1210 <input_read_mp3_padding+0xb0>
lea    0xd8f(%rip),%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1040 <memcmp@plt>
test   %eax,%eax
jne    1210 <input_read_mp3_padding+0xb0>
lea    0xd7a(%rip),%rdi
mov    -0x40(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcmp@plt>
test   %eax,%eax
jne    1210 <input_read_mp3_padding+0xb0>
movzbl 0xb1(%rbx),%eax
shl    $0x4,%eax
movzbl 0xb2(%rbx),%ecx
mov    %ecx,%edx
shr    $0x4,%edx
or     %eax,%edx
mov    -0x30(%rbp),%rax
mov    %edx,(%rax)
and    $0xf,%ecx
shl    $0x8,%ecx
movzbl 0xb3(%rbx),%eax
or     %ecx,%eax
mov    -0x38(%rbp),%rcx
mov    %eax,(%rcx)
mov    %r12d,%edi
call   1050 <input_close_fd@plt>
xor    %eax,%eax
jmp    12ff <input_read_mp3_padding+0x19f>
movl   $0x0,(%r14)
movl   $0x0,(%r15)
jmp    12fa <input_read_mp3_padding+0x19a>
mov    %r12d,%edi
call   1050 <input_close_fd@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"\FF\FB\00"
@.str.1 = [17 x i8] zeroinitializer
define i32 @input_read_mp3_padding(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%16 = load i32, i32* @BUFSIZ
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %8
%19 = alloca i8, i64 %17
store i64 %17, i64* %9
%20 = load i8*, i8** %5
%21 = call i32 @input_open_fd(i8* %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %3
%25 = load i32*, i32** %7
store i32 0, i32* %25
%26 = load i32*, i32** %6
store i32 0, i32* %26
store i32 1, i32* %4
store i32 1, i32* %13
br label %110
27: ; preds = %3
br label %28
28: ; preds = %106, %27
%29 = load i32, i32* %10
%30 = load i32, i32* @BUFSIZ
%31 = call i32 @input_read_fd(i32 %29, i8* %19, i32 %30)
store i32 %31, i32* %11
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %107
33: ; preds = %28
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = call i8* @memchr(i8* %19, float -1.000000e+00, i64 %35)
store i8* %36, i8** %14
br label %37
37: ; preds = %100, %33
%38 = load i8*, i8** %14
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %106
40: ; preds = %37
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %19, i64 %42
%44 = load i8*, i8** %14
%45 = ptrtoint i8* %43 to i64
%46 = ptrtoint i8* %44 to i64
%47 = sub i64 %45, %46
store i64 %47, i64* %15
%48 = load i8*, i8** %14
%49 = load i64, i64* %15
%50 = call i32 @memmove(i8* %19, i8* %48, i64 %49)
%51 = load i32, i32* %10
%52 = load i64, i64* %15
%53 = getelementptr inbounds i8, i8* %19, i64 %52
%54 = load i32, i32* @BUFSIZ
%55 = sext i32 %54 to i64
%56 = load i64, i64* %15
%57 = sub i64 %55, %56
%58 = trunc i64 %57 to i32
%59 = call i32 @input_read_fd(i32 %51, i8* %53, i32 %58)
store i32 %59, i32* %12
%60 = load i32, i32* %12
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %40
br label %106
63: ; preds = %40
%64 = load i64, i64* %15
%65 = trunc i64 %64 to i32
%66 = load i32, i32* %12
%67 = add nsw i32 %65, %66
store i32 %67, i32* %11
%68 = load i32, i32* %11
%69 = icmp sge i32 %68, 180
br i1 %69, label %70, label %100
70: ; preds = %63
%71 = call i32 @memcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19, i32 2)
%72 = icmp ne i32 %71, 0
br i1 %72, label %100, label %73
73: ; preds = %70
%74 = getelementptr inbounds i8, i8* %19, i64 4
%75 = call i32 @memcmp(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %74, i32 16)
%76 = icmp ne i32 %75, 0
br i1 %76, label %100, label %77
77: ; preds = %73
%78 = getelementptr inbounds i8, i8* %19, i64 177
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = shl i32 %80, 4
%82 = getelementptr inbounds i8, i8* %19, i64 178
%83 = load i8, i8* %82
%84 = zext i8 %83 to i32
%85 = ashr i32 %84, 4
%86 = add nsw i32 %81, %85
%87 = load i32*, i32** %6
store i32 %86, i32* %87
%88 = getelementptr inbounds i8, i8* %19, i64 178
%89 = load i8, i8* %88
%90 = zext i8 %89 to i32
%91 = and i32 %90, 15
%92 = shl i32 %91, 8
%93 = getelementptr inbounds i8, i8* %19, i64 179
%94 = load i8, i8* %93
%95 = zext i8 %94 to i32
%96 = add nsw i32 %92, %95
%97 = load i32*, i32** %7
store i32 %96, i32* %97
%98 = load i32, i32* %10
%99 = call i32 @input_close_fd(i32 %98)
store i32 0, i32* %4
store i32 1, i32* %13
br label %110
100: ; preds = %73, %70, %63
%101 = getelementptr inbounds i8, i8* %19, i64 1
%102 = load i32, i32* %11
%103 = sub nsw i32 %102, 1
%104 = sext i32 %103 to i64
%105 = call i8* @memchr(i8* %101, float -1.000000e+00, i64 %104)
store i8* %105, i8** %14
br label %37
106: ; preds = %62, %37
br label %28
107: ; preds = %28
%108 = load i32, i32* %10
%109 = call i32 @input_close_fd(i32 %108)
store i32 1, i32* %4
store i32 1, i32* %13
br label %110
110: ; preds = %107, %77, %24
%111 = load i8*, i8** %8
%112 = load i32, i32* %4
ret i32 %112
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [3 x i8] c"\FF\FB\00"
@.str.1 = [17 x i8] zeroinitializer
define i32 @input_read_mp3_padding(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = tail call i32 @input_open_fd(i8* %0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %3
%10 = load i32, i32* @BUFSIZ
%11 = call i32 @input_read_fd(i32 %7, i8* %6, i32 %10)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %73
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %6, i64 4
%15 = getelementptr inbounds i8, i8* %6, i64 1
br label %17
16: ; preds = %3
store i32 0, i32* %2
store i32 0, i32* %1
br label %75
17: ; preds = %13, %69
%18 = phi i32 [ %11, %13 ], [ %71, %69 ]
%19 = zext i32 %18 to i64
%20 = call i8* @memchr(i8* %6, float -1.000000e+00, i64 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %69, label %22
22: ; preds = %17, %64
%23 = phi i8* [ %67, %64 ], [ %20, %17 ]
%24 = phi i32 [ %38, %64 ], [ %18, %17 ]
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %6, i64 %25
%27 = ptrtoint i8* %26 to i64
%28 = ptrtoint i8* %23 to i64
%29 = sub i64 %27, %28
%30 = call i32 @memmove(i8* %6, i8* %23, i64 %29)
%31 = getelementptr inbounds i8, i8* %6, i64 %29
%32 = load i32, i32* @BUFSIZ
%33 = trunc i64 %29 to i32
%34 = sub i32 %32, %33
%35 = call i32 @input_read_fd(i32 %7, i8* %31, i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %69, label %37
37: ; preds = %22
%38 = add nsw i32 %35, %33
%39 = icmp sgt i32 %38, 179
br i1 %39, label %40, label %64
40: ; preds = %37
%41 = call i32 @memcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6, i32 2)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %64
43: ; preds = %40
%44 = call i32 @memcmp(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 16)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %64
46: ; preds = %43
%47 = getelementptr inbounds i8, i8* %6, i64 177
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = shl nuw nsw i32 %49, 4
%51 = getelementptr inbounds i8, i8* %6, i64 178
%52 = load i8, i8* %51
%53 = lshr i8 %52, 4
%54 = zext i8 %53 to i32
%55 = or i32 %50, %54
store i32 %55, i32* %1
%56 = and i8 %52, 15
%57 = zext i8 %56 to i32
%58 = shl nuw nsw i32 %57, 8
%59 = getelementptr inbounds i8, i8* %6, i64 179
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = or i32 %58, %61
store i32 %62, i32* %2
%63 = call i32 @input_close_fd(i32 %7)
br label %75
64: ; preds = %37, %40, %43
%65 = add nsw i32 %38, -1
%66 = sext i32 %65 to i64
%67 = call i8* @memchr(i8* %15, float -1.000000e+00, i64 %66)
%68 = icmp eq i8* %67, null
br i1 %68, label %69, label %22
69: ; preds = %64, %22, %17
%70 = load i32, i32* @BUFSIZ
%71 = call i32 @input_read_fd(i32 %7, i8* %6, i32 %70)
%72 = icmp sgt i32 %71, 0
br i1 %72, label %17, label %73
73: ; preds = %69, %9
%74 = call i32 @input_close_fd(i32 %7)
br label %75
75: ; preds = %46, %73, %16
%76 = phi i32 [ 1, %16 ], [ 1, %73 ], [ 0, %46 ]
ret i32 %76
}