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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *malloc(size_t);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/ *, size_t);
int /*<<< orphan*/ stderr;
int digi_to_wave(uint8_t **source, uint8_t **destination, size_t snd_length,
                 uint32_t sample_rate) {
  if ((*destination = malloc(snd_length * sizeof(uint8_t))) == NULL) {
    fprintf(stderr,
            "Error: could not allocate memory to hold wave audio data.\n");
    return 0;
  }
  memcpy(*destination, *source, snd_length);
  return snd_length;
}


x86 assembly (clang, -O0):
<digi_to_wave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    1186 <digi_to_wave+0x56>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a4 <digi_to_wave+0x74>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digi_to_wave>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x0(,%rdx,4),%rdi
call   1050 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1163 <digi_to_wave+0x33>
mov    (%r14),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
jmp    117a <digi_to_wave+0x4a>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
call   1030 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [59 x i8] c"Error: could not allocate memory to hold wave audio data.\0A\00"
define i32 @digi_to_wave(i32** nocapture %0, i32** nocapture writeonly %1, i64 %2, i32 %3) {
%5 = shl i64 %2, 2
%6 = tail call i32* @malloc(i64 %5)
store i32* %6, i32** %1
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
br label %15
11: ; preds = %4
%12 = load i32*, i32** %0
%13 = tail call i32 @memcpy(i32* %6, i32* %12, i64 %2)
%14 = trunc i64 %2 to i32
br label %15
15: ; preds = %11, %8
%16 = phi i32 [ 0, %8 ], [ %14, %11 ]
ret i32 %16
}