#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int amr_file_read_frame(FILE *fpamr, unsigned char frameBuffer[],
                        int stdFrameSize, unsigned char stdFrameHeader) {
  size_t bytes = 0;
  unsigned char frameHeader;
  while (1) {
    bytes = fread(&frameHeader, 1, sizeof(unsigned char), fpamr);
    if (feof(fpamr))
      return 0;
    if (frameHeader == stdFrameHeader)
      break;
  }
  frameBuffer[0] = frameHeader;
  bytes = fread(&(frameBuffer[1]), 1,
                (stdFrameSize - 1) * sizeof(unsigned char), fpamr);
  if (feof(fpamr))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<amr_file_read_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x29(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     1177 <amr_file_read_frame+0x57>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <amr_file_read_frame+0xc8>
movzbl -0x29(%rbp),%eax
movzbl -0x1d(%rbp),%ecx
cmp    %ecx,%eax
jne    118c <amr_file_read_frame+0x6c>
jmp    1191 <amr_file_read_frame+0x71>
jmp    1140 <amr_file_read_frame+0x20>
mov    -0x29(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     11e1 <amr_file_read_frame+0xc1>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <amr_file_read_frame+0xc8>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amr_file_read_frame>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xf(%rsp),%r12
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %rax,%rax
jne    119c <amr_file_read_frame+0x7c>
cmp    %bpl,0xf(%rsp)
jne    1140 <amr_file_read_frame+0x20>
mov    %bpl,(%r15)
add    $0x1,%r15
add    $0xffffffff,%r14d
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    119e <amr_file_read_frame+0x7e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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