#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*/ uint16_t;

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


x86 assembly (clang, -O0):
<read_digi_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9d(%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    119e <read_digi_buffer+0x6e>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c6 <read_digi_buffer+0x96>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    0x2e35(%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_digi_buffer>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ea6(%rip),%r15
mov    (%r15),%ecx
mov    $0x1,%edx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    (%rbx),%rbx
lea    0x0(,%rbx,8),%rdi
call   1050 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1183 <read_digi_buffer+0x53>
mov    (%r15),%ecx
mov    %rax,%rdi
mov    $0x8,%esi
mov    %rbx,%rdx
call   1030 <fread@plt>
xor    %eax,%eax
jmp    119d <read_digi_buffer+0x6d>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%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 = [62 x i8] c"Error: could not allocate memory for digitised sound effect.\0A\00"
define i32 @read_digi_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 ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %25
18: ; preds = %2
%19 = load i64**, i64*** %5
%20 = load i64*, i64** %19
%21 = load i64*, i64** %4
%22 = load i64, i64* %21
%23 = load i32, i32* @stdin
%24 = call i32 @fread(i64* %20, i32 8, i64 %22, i32 %23)
store i32 0, i32* %3
br label %25
25: ; preds = %18, %15
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [62 x i8] c"Error: could not allocate memory for digitised sound effect.\0A\00"
define i32 @read_digi_buffer(i64* %0, i64** nocapture writeonly %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 ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %15
12: ; preds = %2
%13 = load i32, i32* @stdin
%14 = tail call i32 @fread(i64* %7, i32 8, i64 %5, i32 %13)
br label %15
15: ; preds = %12, %9
%16 = phi i32 [ 1, %9 ], [ 0, %12 ]
ret i32 %16
}