#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 /*<<< orphan*/ fp_move_forward(int /*<<< orphan*/ *, int);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int read_app0(int /*<<< orphan*/ *, int);
int read_app1(int /*<<< orphan*/ *, int);
int read_sofx(int /*<<< orphan*/ *, int);
int strbe_to_word(unsigned char *);
int read_marker(FILE *fp) {
  unsigned char buf[4];
  int clen, ret, id;
  if (fread(buf, 1, 2, fp) != 2)
    return -1;
  if (buf[0] != 0xFF)
    return -1;
  while (buf[1] == 0xFF) {
    if ((ret = getc(fp)) < 0)
      return -1;
    buf[1] = ret;
  }
  id = buf[1];
  if (id == 0xD9 || id == 0xDA) {
    return 0;
  }
  if (fread(buf, 1, 2, fp) != 2)
    return -1;
  clen = strbe_to_word(buf) - 2;
  if (clen < 0)
    return -1;
  ret = 1;
  if (id >= 0xC0 && id <= 0xC3) {
    ret = read_sofx(fp, clen);
  } else if (id == 0xe0) {
    ret = read_app0(fp, clen);
  } else if (id == 0xe1) {
    ret = read_app1(fp, clen);
  } else {
    if (!fp_move_forward(fp, clen))
      return -1;
  }
  if (!ret)
    return -1;
  return 1;
}


x86 assembly (clang, -O0):
<read_marker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
cmp    $0x2,%eax
je     11a8 <read_marker+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <read_marker+0x1d5>
movzbl -0x14(%rbp),%eax
cmp    $0xff,%eax
je     11c3 <read_marker+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <read_marker+0x1d5>
jmp    11c8 <read_marker+0x58>
movzbl -0x13(%rbp),%eax
cmp    $0xff,%eax
jne    1203 <read_marker+0x93>
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11f8 <read_marker+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <read_marker+0x1d5>
mov    -0x1c(%rbp),%eax
mov    %al,-0x13(%rbp)
jmp    11c8 <read_marker+0x58>
movzbl -0x13(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0xd9,-0x20(%rbp)
je     1224 <read_marker+0xb4>
cmpl   $0xda,-0x20(%rbp)
jne    1230 <read_marker+0xc0>
movl   $0x0,-0x4(%rbp)
jmp    1345 <read_marker+0x1d5>
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1030 <fread@plt>
cmp    $0x2,%eax
je     125c <read_marker+0xec>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <read_marker+0x1d5>
lea    -0x14(%rbp),%rdi
call   1040 <strbe_to_word@plt>
sub    $0x2,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1281 <read_marker+0x111>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <read_marker+0x1d5>
movl   $0x1,-0x1c(%rbp)
cmpl   $0xc0,-0x20(%rbp)
jl     12b6 <read_marker+0x146>
cmpl   $0xc3,-0x20(%rbp)
jg     12b6 <read_marker+0x146>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1070 <read_sofx@plt>
mov    %eax,-0x1c(%rbp)
jmp    1328 <read_marker+0x1b8>
cmpl   $0xe0,-0x20(%rbp)
jne    12d7 <read_marker+0x167>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <read_app0@plt>
mov    %eax,-0x1c(%rbp)
jmp    1323 <read_marker+0x1b3>
cmpl   $0xe1,-0x20(%rbp)
jne    12f8 <read_marker+0x188>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <read_app1@plt>
mov    %eax,-0x1c(%rbp)
jmp    131e <read_marker+0x1ae>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <fp_move_forward@plt>
cmp    $0x0,%eax
jne    1319 <read_marker+0x1a9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <read_marker+0x1d5>
jmp    131e <read_marker+0x1ae>
jmp    1323 <read_marker+0x1b3>
jmp    1328 <read_marker+0x1b8>
cmpl   $0x0,-0x1c(%rbp)
jne    133e <read_marker+0x1ce>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <read_marker+0x1d5>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_marker>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x2,%eax
jne    1219 <read_marker+0xa9>
cmpb   $0xff,0x4(%rsp)
jne    1219 <read_marker+0xa9>
mov    0x5(%rsp),%bl
cmp    $0xff,%bl
jne    11c3 <read_marker+0x53>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1090 <getc@plt>
test   %eax,%eax
js     1219 <read_marker+0xa9>
mov    %eax,%ebx
cmp    $0xff,%bl
je     11b0 <read_marker+0x40>
mov    %bl,0x5(%rsp)
lea    0x27(%rbx),%eax
xor    %ecx,%ecx
cmp    $0x2,%al
jb     121e <read_marker+0xae>
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x2,%eax
jne    1219 <read_marker+0xa9>
lea    0x4(%rsp),%rdi
call   1040 <strbe_to_word@plt>
mov    $0xffffffff,%ecx
cmp    $0x2,%eax
jl     121e <read_marker+0xae>
add    $0xfffffffe,%eax
mov    %ebx,%ecx
and    $0xfc,%cl
mov    %r14,%rdi
mov    %eax,%esi
cmp    $0xc0,%cl
jne    1228 <read_marker+0xb8>
call   1070 <read_sofx@plt>
jmp    1245 <read_marker+0xd5>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
cmp    $0xe1,%bl
je     1239 <read_marker+0xc9>
cmp    $0xe0,%bl
jne    1240 <read_marker+0xd0>
call   1050 <read_app0@plt>
jmp    1245 <read_marker+0xd5>
call   1080 <read_app1@plt>
jmp    1245 <read_marker+0xd5>
call   1060 <fp_move_forward@plt>
cmp    $0x1,%eax
sbb    %ecx,%ecx
or     $0x1,%ecx
jmp    121e <read_marker+0xae>

LLVM IR (-O0):
define i32 @read_marker(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [4 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%9 = load i32*, i32** %3
%10 = call i32 @fread(i8* %8, i32 1, i32 2, i32* %9)
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %95
13: ; preds = %1
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = icmp ne i32 %16, 255
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -1, i32* %2
br label %95
19: ; preds = %13
br label %20
20: ; preds = %30, %19
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %23, 255
br i1 %24, label %25, label %34
25: ; preds = %20
%26 = load i32*, i32** %3
%27 = call i32 @getc(i32* %26)
store i32 %27, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 -1, i32* %2
br label %95
30: ; preds = %25
%31 = load i32, i32* %6
%32 = trunc i32 %31 to i8
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
store i8 %32, i8* %33
br label %20
34: ; preds = %20
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = icmp eq i32 %38, 217
br i1 %39, label %43, label %40
40: ; preds = %34
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, 218
br i1 %42, label %43, label %44
43: ; preds = %40, %34
store i32 0, i32* %2
br label %95
44: ; preds = %40
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%46 = load i32*, i32** %3
%47 = call i32 @fread(i8* %45, i32 1, i32 2, i32* %46)
%48 = icmp ne i32 %47, 2
br i1 %48, label %49, label %50
49: ; preds = %44
store i32 -1, i32* %2
br label %95
50: ; preds = %44
%51 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%52 = call i32 @strbe_to_word(i8* %51)
%53 = sub nsw i32 %52, 2
store i32 %53, i32* %5
%54 = load i32, i32* %5
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %50
store i32 -1, i32* %2
br label %95
57: ; preds = %50
store i32 1, i32* %6
%58 = load i32, i32* %7
%59 = icmp sge i32 %58, 192
br i1 %59, label %60, label %67
60: ; preds = %57
%61 = load i32, i32* %7
%62 = icmp sle i32 %61, 195
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = load i32*, i32** %3
%65 = load i32, i32* %5
%66 = call i32 @read_sofx(i32* %64, i32 %65)
store i32 %66, i32* %6
br label %90
67: ; preds = %60, %57
%68 = load i32, i32* %7
%69 = icmp eq i32 %68, 224
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load i32*, i32** %3
%72 = load i32, i32* %5
%73 = call i32 @read_app0(i32* %71, i32 %72)
store i32 %73, i32* %6
br label %89
74: ; preds = %67
%75 = load i32, i32* %7
%76 = icmp eq i32 %75, 225
br i1 %76, label %77, label %81
77: ; preds = %74
%78 = load i32*, i32** %3
%79 = load i32, i32* %5
%80 = call i32 @read_app1(i32* %78, i32 %79)
store i32 %80, i32* %6
br label %88
81: ; preds = %74
%82 = load i32*, i32** %3
%83 = load i32, i32* %5
%84 = call i32 @fp_move_forward(i32* %82, i32 %83)
%85 = icmp ne i32 %84, 0
br i1 %85, label %87, label %86
86: ; preds = %81
store i32 -1, i32* %2
br label %95
87: ; preds = %81
br label %88
88: ; preds = %87, %77
br label %89
89: ; preds = %88, %70
br label %90
90: ; preds = %89, %63
%91 = load i32, i32* %6
%92 = icmp ne i32 %91, 0
br i1 %92, label %94, label %93
93: ; preds = %90
store i32 -1, i32* %2
br label %95
94: ; preds = %90
store i32 1, i32* %2
br label %95
95: ; preds = %94, %93, %86, %56, %49, %43, %29, %18, %12
%96 = load i32, i32* %2
ret i32 %96
}

LLVM IR (-O2):
define i32 @read_marker(i32* %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = call i32 @fread(i8* %3, i32 1, i32 2, i32* %0)
%5 = icmp eq i32 %4, 2
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, -1
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %50
9: ; preds = %1
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, -1
br i1 %12, label %16, label %21
13: ; preds = %16
%14 = trunc i32 %17 to i8
%15 = icmp eq i8 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %9, %13
%17 = tail call i32 @getc(i32* %0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %50, label %13
19: ; preds = %13
%20 = trunc i32 %17 to i8
br label %21
21: ; preds = %19, %9
%22 = phi i8 [ %11, %9 ], [ %20, %19 ]
store i8 %22, i8* %10
%23 = add i8 %22, 39
%24 = icmp ult i8 %23, 2
br i1 %24, label %50, label %25
25: ; preds = %21
%26 = call i32 @fread(i8* %3, i32 1, i32 2, i32* %0)
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %50
28: ; preds = %25
%29 = call i32 @strbe_to_word(i8* %3)
%30 = add nsw i32 %29, -2
%31 = icmp slt i32 %29, 2
br i1 %31, label %50, label %32
32: ; preds = %28
%33 = and i8 %22, -4
%34 = icmp eq i8 %33, -64
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @read_sofx(i32* %0, i32 %30)
br label %46
37: ; preds = %32
switch i8 %22, label %42 [
i8 -32, label %38
i8 -31, label %40
]
38: ; preds = %37
%39 = call i32 @read_app0(i32* %0, i32 %30)
br label %46
40: ; preds = %37
%41 = call i32 @read_app1(i32* %0, i32 %30)
br label %46
42: ; preds = %37
%43 = call i32 @fp_move_forward(i32* %0, i32 %30)
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i32 -1, i32 1
br label %50
46: ; preds = %38, %40, %35
%47 = phi i32 [ %36, %35 ], [ %39, %38 ], [ %41, %40 ]
%48 = icmp eq i32 %47, 0
%49 = select i1 %48, i32 -1, i32 1
br label %50
50: ; preds = %16, %46, %42, %28, %25, %21, %1
%51 = phi i32 [ -1, %1 ], [ 0, %21 ], [ -1, %25 ], [ -1, %28 ], [ %45, %42 ], [ %49, %46 ], [ -1, %16 ]
ret i32 %51
}