#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 */
unsigned char fgetc(int /*<<< orphan*/ *);
int fread_unsync(char *frame_data, int fsize, FILE *file) {
  int j;
  for (j = 0; j < fsize; j++) {
    unsigned char uc = fgetc(file);
    frame_data[j] = (char)uc;
    if (uc == 0xFF) {
      uc = fgetc(file);
      if (uc != 0) {
        j++;
        frame_data[j] = (char)uc;
      }
    }
  }
  return j;
}


x86 assembly (clang, -O0):
<fread_unsync>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a7 <fread_unsync+0x97>
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movzbl -0x1d(%rbp),%eax
cmp    $0xff,%eax
jne    1194 <fread_unsync+0x84>
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x1d(%rbp)
movzbl -0x1d(%rbp),%eax
cmp    $0x0,%eax
je     118f <fread_unsync+0x7f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1d(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1194 <fread_unsync+0x84>
jmp    1199 <fread_unsync+0x89>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <fread_unsync+0x1a>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fread_unsync>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1164 <fread_unsync+0x54>
mov    %rdx,%r12
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebp,%ebp
jmp    1138 <fread_unsync+0x28>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    %r14d,%ebp
jge    1166 <fread_unsync+0x56>
mov    %r12,%rdi
call   1030 <fgetc@plt>
movslq %ebp,%rbx
mov    %al,(%r15,%rbx,1)
cmp    $0xff,%al
jne    1130 <fread_unsync+0x20>
mov    %r12,%rdi
call   1030 <fgetc@plt>
test   %al,%al
je     1130 <fread_unsync+0x20>
mov    %al,0x1(%r15,%rbx,1)
add    $0x1,%rbx
mov    %ebx,%ebp
jmp    1130 <fread_unsync+0x20>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @fread_unsync(i8* nocapture writeonly %0, i32 %1, i32* nocapture %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %22
5: ; preds = %3, %18
%6 = phi i32 [ %20, %18 ], [ 0, %3 ]
%7 = tail call zeroext i8 @fgetc(i32* %2)
%8 = sext i32 %6 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %7, i8* %9
%10 = icmp eq i8 %7, -1
br i1 %10, label %11, label %18
11: ; preds = %5
%12 = tail call zeroext i8 @fgetc(i32* %2)
%13 = icmp eq i8 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = add nsw i32 %6, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
store i8 %12, i8* %17
br label %18
18: ; preds = %11, %14, %5
%19 = phi i32 [ %15, %14 ], [ %6, %11 ], [ %6, %5 ]
%20 = add nsw i32 %19, 1
%21 = icmp slt i32 %20, %1
br i1 %21, label %5, label %22
22: ; preds = %18, %3
%23 = phi i32 [ 0, %3 ], [ %20, %18 ]
ret i32 %23
}