#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*/ RIFF_ReadChunkInfo(int /*<<< orphan*/ *, int, int *, int *,
                                      int *);
int /*<<< orphan*/ fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
void *malloc(int);
void *RIFF_ReadInChunk(FILE *fd, int ofs, int *size) {
  int cc1, cc2, sz;
  void *buf;
  RIFF_ReadChunkInfo(fd, ofs, &cc1, &sz, &cc2);
  if (size)
    *size = sz;
  buf = malloc(sz + 1024);
  fseek(fd, ofs + 8, 0);
  fread(buf, 1, sz + 1024, fd);
  return (buf);
}


x86 assembly (clang, -O0):
<RIFF_ReadInChunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x1c(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1060 <RIFF_ReadChunkInfo@plt>
cmpq   $0x0,-0x18(%rbp)
je     117f <RIFF_ReadInChunk+0x3f>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%edi
add    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x8,%esi
xor    %edx,%edx
call   1050 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
add    $0x400,%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RIFF_ReadInChunk>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xc(%rsp),%rdx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
call   1060 <RIFF_ReadChunkInfo@plt>
mov    0x4(%rsp),%edi
test   %rbx,%rbx
je     116f <RIFF_ReadInChunk+0x2f>
mov    %edi,(%rbx)
add    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
add    $0x8,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1050 <fseek@plt>
mov    $0x400,%edx
add    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @RIFF_ReadInChunk(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%11 = load i32*, i32** %4
%12 = load i32, i32* %5
%13 = call i32 @RIFF_ReadChunkInfo(i32* %11, i32 %12, i32* %7, i32* %9, i32* %8)
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i32, i32* %9
%18 = load i32*, i32** %6
store i32 %17, i32* %18
br label %19
19: ; preds = %16, %3
%20 = load i32, i32* %9
%21 = add nsw i32 %20, 1024
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %10
%23 = load i32*, i32** %4
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 8
%26 = call i32 @fseek(i32* %23, i32 %25, i32 0)
%27 = load i8*, i8** %10
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1024
%30 = load i32*, i32** %4
%31 = call i32 @fread(i8* %27, i32 1, i32 %29, i32* %30)
%32 = load i8*, i8** %10
ret i8* %32
}

LLVM IR (-O2):
define noalias i8* @RIFF_ReadInChunk(i32* %0, i32 %1, i32* writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = call i32 @RIFF_ReadChunkInfo(i32* %0, i32 %1, i32* %4, i32* %6, i32* %5)
%11 = icmp eq i32* %2, null
%12 = load i32, i32* %6
br i1 %11, label %14, label %13
13: ; preds = %3
store i32 %12, i32* %2
br label %14
14: ; preds = %3, %13
%15 = add nsw i32 %12, 1024
%16 = call i8* @malloc(i32 %15)
%17 = add nsw i32 %1, 8
%18 = call i32 @fseek(i32* %0, i32 %17, i32 0)
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1024
%21 = call i32 @fread(i8* %16, i32 1, i32 %20, i32* %0)
ret i8* %16
}