#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*/ header;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int fread(unsigned long *, int, int, int /*<<< orphan*/ *);
unsigned long own_ntohl(unsigned long);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
unsigned long int mpeg_seek_nextheader(FILE *fp) {
  unsigned long int header;
  int c;
  while ((c = fgetc(fp)) != 0xff && c != EOF)
    ;
  if (feof(fp))
    return -1;
  ungetc(c, fp);
  if (fread(&header, 1, sizeof(header), fp) != sizeof(header))
    return -1;
  header = own_ntohl(header);
  return (header);
}


x86 assembly (clang, -O0):
<mpeg_seek_nextheader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0xff,%ecx
mov    %al,-0x1d(%rbp)
je     118d <mpeg_seek_nextheader+0x3d>
mov    -0x1c(%rbp),%eax
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    119d <mpeg_seek_nextheader+0x4d>
jmp    11a2 <mpeg_seek_nextheader+0x52>
jmp    115c <mpeg_seek_nextheader+0xc>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11c2 <mpeg_seek_nextheader+0x72>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1213 <mpeg_seek_nextheader+0xc3>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <ungetc@plt>
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0x8,%edx
call   1040 <fread@plt>
cltq
cmp    $0x8,%rax
je     11fe <mpeg_seek_nextheader+0xae>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1213 <mpeg_seek_nextheader+0xc3>
mov    -0x18(%rbp),%rdi
call   1030 <own_ntohl@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpeg_seek_nextheader>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e86(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
cmp    $0xff,%eax
je     1186 <mpeg_seek_nextheader+0x36>
cmp    (%r14),%ebp
jne    1170 <mpeg_seek_nextheader+0x20>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11cb <mpeg_seek_nextheader+0x7b>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <ungetc@plt>
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x8,%eax
jne    11cb <mpeg_seek_nextheader+0x7b>
mov    0x8(%rsp),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <own_ntohl@plt>
mov    $0xffffffffffffffff,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i64 @mpeg_seek_nextheader(i32* %0) {
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
store i32* %0, i32** %3
br label %6
6: ; preds = %16, %1
%7 = load i32*, i32** %3
%8 = call i32 @fgetc(i32* %7)
store i32 %8, i32* %5
%9 = icmp ne i32 %8, 255
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* %5
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br label %14
14: ; preds = %10, %6
%15 = phi i1 [ false, %6 ], [ %13, %10 ]
br i1 %15, label %16, label %17
16: ; preds = %14
br label %6
17: ; preds = %14
%18 = load i32*, i32** %3
%19 = call i64 @feof(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i64 -1, i64* %2
br label %35
22: ; preds = %17
%23 = load i32, i32* %5
%24 = load i32*, i32** %3
%25 = call i32 @ungetc(i32 %23, i32* %24)
%26 = load i32*, i32** %3
%27 = call i32 @fread(i64* %4, i32 1, i32 8, i32* %26)
%28 = sext i32 %27 to i64
%29 = icmp ne i64 %28, 8
br i1 %29, label %30, label %31
30: ; preds = %22
store i64 -1, i64* %2
br label %35
31: ; preds = %22
%32 = load i64, i64* %4
%33 = call i64 @own_ntohl(i64 %32)
store i64 %33, i64* %4
%34 = load i64, i64* %4
store i64 %34, i64* %2
br label %35
35: ; preds = %31, %30, %21
%36 = load i64, i64* %2
ret i64 %36
}

LLVM IR (-O2):
@EOF = global i32 0
define i64 @mpeg_seek_nextheader(i32* nocapture %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
br label %4
4: ; preds = %4, %1
%5 = tail call i32 @fgetc(i32* %0)
%6 = icmp ne i32 %5, 255
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %5, %7
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %4, label %10
10: ; preds = %4
%11 = tail call i64 @feof(i32* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = tail call i32 @ungetc(i32 %5, i32* %0)
%15 = call i32 @fread(i64* %2, i32 1, i32 8, i32* %0)
%16 = icmp eq i32 %15, 8
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i64, i64* %2
%19 = tail call i64 @own_ntohl(i64 %18)
br label %20
20: ; preds = %13, %10, %17
%21 = phi i64 [ %19, %17 ], [ -1, %10 ], [ -1, %13 ]
ret i64 %21
}