#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 size_t uint8_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fread(size_t *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ fseek(int /*<<< orphan*/, int, int /*<<< orphan*/);
size_t *malloc(size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int read_pcs_buffer(size_t *snd_length, uint8_t **snd_buffer) {
  fread(snd_length, sizeof(uint32_t), 1, stdin);
  if ((*snd_buffer = malloc(*snd_length * sizeof(uint8_t))) == NULL) {
    fprintf(stderr, "Error: could not allocate memory for PC sound effect.\n");
    return 1;
  }
  fseek(stdin, sizeof(uint16_t), SEEK_CUR);
  fread(*snd_buffer, sizeof(uint8_t), *snd_length, stdin);
  return 0;
}


x86 assembly (clang, -O0):
<read_pcs_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11ae <read_pcs_buffer+0x6e>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f2 <read_pcs_buffer+0xb2>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <fseek@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    0x2e01(%rip),%rax
mov    (%rax),%ecx
mov    $0x8,%esi
call   1030 <fread@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pcs_buffer>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e8e(%rip),%r15
mov    (%r15),%ecx
mov    $0x1,%edx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    (%rbx),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11a5 <read_pcs_buffer+0x65>
mov    (%r15),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <fseek@plt>
mov    (%r14),%rdi
mov    (%rbx),%rdx
mov    (%r15),%ecx
mov    $0x8,%esi
call   1030 <fread@plt>
xor    %eax,%eax
jmp    11bf <read_pcs_buffer+0x7f>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [55 x i8] c"Error: could not allocate memory for PC sound effect.\0A\00"
@SEEK_CUR = global i32 0
define i32 @read_pcs_buffer(i64* %0, i64** %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i64**
store i64* %0, i64** %4
store i64** %1, i64*** %5
%6 = load i64*, i64** %4
%7 = load i32, i32* @stdin
%8 = call i32 @fread(i64* %6, i32 4, i64 1, i32 %7)
%9 = load i64*, i64** %4
%10 = load i64, i64* %9
%11 = mul i64 %10, 8
%12 = call i64* @malloc(i64 %11)
%13 = load i64**, i64*** %5
store i64* %12, i64** %13
%14 = icmp eq i64* %12, null
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %28
18: ; preds = %2
%19 = load i32, i32* @stdin
%20 = load i32, i32* @SEEK_CUR
%21 = call i32 @fseek(i32 %19, i32 4, i32 %20)
%22 = load i64**, i64*** %5
%23 = load i64*, i64** %22
%24 = load i64*, i64** %4
%25 = load i64, i64* %24
%26 = load i32, i32* @stdin
%27 = call i32 @fread(i64* %23, i32 8, i64 %25, i32 %26)
store i32 0, i32* %3
br label %28
28: ; preds = %18, %15
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [55 x i8] c"Error: could not allocate memory for PC sound effect.\0A\00"
@SEEK_CUR = global i32 0
define i32 @read_pcs_buffer(i64* %0, i64** nocapture %1) {
%3 = load i32, i32* @stdin
%4 = tail call i32 @fread(i64* %0, i32 4, i64 1, i32 %3)
%5 = load i64, i64* %0
%6 = shl i64 %5, 3
%7 = tail call i64* @malloc(i64 %6)
store i64* %7, i64** %1
%8 = icmp eq i64* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
br label %20
12: ; preds = %2
%13 = load i32, i32* @stdin
%14 = load i32, i32* @SEEK_CUR
%15 = tail call i32 @fseek(i32 %13, i32 4, i32 %14)
%16 = load i64*, i64** %1
%17 = load i64, i64* %0
%18 = load i32, i32* @stdin
%19 = tail call i32 @fread(i64* %16, i32 8, i64 %17, i32 %18)
br label %20
20: ; preds = %12, %9
%21 = phi i32 [ 1, %9 ], [ 0, %12 ]
ret i32 %21
}