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


x86 assembly (clang, -O0):
<amr_file_read_first_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     117b <amr_file_read_first_frame+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <amr_file_read_first_frame+0xb8>
mov    -0x28(%rbp),%rax
movzbl (%rax),%edi
call   1040 <amr_frame_calc_size@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     11e1 <amr_file_read_first_frame+0xb1>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <amr_file_read_first_frame+0xb8>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amr_file_read_first_frame>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rcx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11ac <amr_file_read_first_frame+0x7c>
movzbl (%r12),%edi
call   1040 <amr_frame_calc_size@plt>
mov    %eax,(%r15)
mov    (%r12),%al
mov    %al,(%r14)
add    $0x1,%r14
mov    (%r15),%edx
add    $0xffffffff,%edx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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