#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*/ SEEK_SET;
int /*<<< orphan*/ SaveWAV(unsigned char *, long, int /*<<< orphan*/ *);
scalar_t__ _IsWAV(int /*<<< orphan*/ *);
int fread(unsigned char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
scalar_t__ malloc(long);
int /*<<< orphan*/ printf(char *, ...);
int pcm2wav(FILE *in, long inlen, FILE *out, long outlen) {
  unsigned char *ptr;
  int c;
  if (_IsWAV(in)) {
    return 1;
  }
  if ((ptr = (unsigned char *)malloc(inlen)) == NULL) {
    printf("\n\nError: Memoria insuficiente.\n");
    return 4;
  }
  fseek(in, 0, SEEK_SET);
  if ((c = fread(ptr, 1, inlen, in)) != inlen) {
    printf("\n\nError: %d %d No se pudo leer el archivo.\n", c, inlen);
    free(ptr);
    return 3;
  }
  if (!SaveWAV(ptr, inlen, out)) {
    printf("...Error\n");
    free(ptr);
    return 2;
  }
  free(ptr);
  return 0;
}


x86 assembly (clang, -O0):
<pcm2wav>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <_IsWAV@plt>
cmp    $0x0,%rax
je     11a7 <pcm2wav+0x37>
movl   $0x1,-0x4(%rbp)
jmp    1288 <pcm2wav+0x118>
mov    -0x18(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11d8 <pcm2wav+0x68>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    1288 <pcm2wav+0x118>
mov    -0x10(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x34(%rbp)
cltq
cmp    -0x18(%rbp),%rax
je     123b <pcm2wav+0xcb>
mov    -0x34(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x3,-0x4(%rbp)
jmp    1288 <pcm2wav+0x118>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <SaveWAV@plt>
cmp    $0x0,%eax
jne    1278 <pcm2wav+0x108>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x2,-0x4(%rbp)
jmp    1288 <pcm2wav+0x118>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pcm2wav>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
call   1070 <_IsWAV@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
je     11af <pcm2wav+0x2f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r12,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     120b <pcm2wav+0x8b>
mov    %rax,%r14
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1050 <fread@plt>
movslq %eax,%rcx
cmp    %r12,%rcx
jne    121e <pcm2wav+0x9e>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   10a0 <SaveWAV@plt>
test   %eax,%eax
je     1243 <pcm2wav+0xc3>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11a3 <pcm2wav+0x23>
lea    0xe23(%rip),%rdi
call   1040 <puts@plt>
mov    $0x4,%eax
jmp    11a3 <pcm2wav+0x23>
lea    0xddb(%rip),%rdi
mov    %eax,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x3,%eax
jmp    11a3 <pcm2wav+0x23>
lea    0xde2(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x2,%eax
jmp    11a3 <pcm2wav+0x23>

LLVM IR (-O0):
@.str = [32 x i8] c"\0A\0AError: Memoria insuficiente.\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [44 x i8] c"\0A\0AError: %d %d No se pudo leer el archivo.\0A\00"
@.str.2 = [10 x i8] c"...Error\0A\00"
define i32 @pcm2wav(i32* %0, i64 %1, i32* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i32* %0, i32** %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i64 %3, i64* %9
%12 = load i32*, i32** %6
%13 = call i64 @_IsWAV(i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 1, i32* %5
br label %53
16: ; preds = %4
%17 = load i64, i64* %7
%18 = call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %10
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 4, i32* %5
br label %53
23: ; preds = %16
%24 = load i32*, i32** %6
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseek(i32* %24, i32 0, i32 %25)
%27 = load i8*, i8** %10
%28 = load i64, i64* %7
%29 = load i32*, i32** %6
%30 = call i32 @fread(i8* %27, i32 1, i64 %28, i32* %29)
store i32 %30, i32* %11
%31 = sext i32 %30 to i64
%32 = load i64, i64* %7
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %40
34: ; preds = %23
%35 = load i32, i32* %11
%36 = load i64, i64* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %35, i64 %36)
%38 = load i8*, i8** %10
%39 = call i32 @free(i8* %38)
store i32 3, i32* %5
br label %53
40: ; preds = %23
%41 = load i8*, i8** %10
%42 = load i64, i64* %7
%43 = load i32*, i32** %8
%44 = call i32 @SaveWAV(i8* %41, i64 %42, i32* %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %40
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%48 = load i8*, i8** %10
%49 = call i32 @free(i8* %48)
store i32 2, i32* %5
br label %53
50: ; preds = %40
%51 = load i8*, i8** %10
%52 = call i32 @free(i8* %51)
store i32 0, i32* %5
br label %53
53: ; preds = %50, %46, %34, %21, %15
%54 = load i32, i32* %5
ret i32 %54
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str.1 = [44 x i8] c"\0A\0AError: %d %d No se pudo leer el archivo.\0A\00"
@str = [9 x i8] c"...Error\00"
@str.3 = [31 x i8] c"\0A\0AError: Memoria insuficiente.\00"
define i32 @pcm2wav(i32* %0, i64 %1, i32* %2, i64 %3) {
%5 = tail call i64 @_IsWAV(i32* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %30
7: ; preds = %4
%8 = tail call i64 @malloc(i64 %1)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.3, i64 0, i64 0))
br label %30
13: ; preds = %7
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %0, i32 0, i32 %14)
%16 = tail call i32 @fread(i8* %9, i32 1, i64 %1, i32* %0)
%17 = sext i32 %16 to i64
%18 = icmp eq i64 %17, %1
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %16, i64 %1)
%21 = tail call i32 @free(i8* %9)
br label %30
22: ; preds = %13
%23 = tail call i32 @SaveWAV(i8* %9, i64 %1, i32* %2)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @free(i8* %9)
br label %30
28: ; preds = %22
%29 = tail call i32 @free(i8* %9)
br label %30
30: ; preds = %4, %28, %25, %19, %11
%31 = phi i32 [ 4, %11 ], [ 3, %19 ], [ 0, %28 ], [ 2, %25 ], [ 1, %4 ]
ret i32 %31
}