#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 */
scalar_t__ calloc(size_t, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
long fread(short *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(short *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sh2fl(long, short *, float *, int, int);
int /*<<< orphan*/ sh2fl_alt(long, short *, float *, short);
int /*<<< orphan*/ stderr;
float *load_samples(FILE *fp, long no_samples) {
  short *buf;
  float *sig;
  if ((buf = (short *)calloc((size_t)no_samples, sizeof(short))) == NULL) {
    fprintf(stderr, "cannot allocate enough memory to buffer samples!\n");
    exit(-1);
  }
  if (fread(buf, sizeof(short), (size_t)no_samples, fp) != no_samples) {
    fprintf(stderr, "could not read all samples!\n");
    exit(-1);
  }
  rewind(fp);
  if ((sig = (float *)calloc((size_t)no_samples, sizeof(float))) == NULL) {
    fprintf(stderr, "cannot allocate enough memory to buffer samples!\n");
    exit(-1);
  }
  (1 ? sh2fl_alt(no_samples, buf, sig, (short)0xFFFF)
     : sh2fl(no_samples, buf, sig, 16, 1));
  free(buf);
  return (sig);
}


x86 assembly (clang, -O0):
<load_samples>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11bb <load_samples+0x4b>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x2,%esi
call   1040 <fread@plt>
cmp    -0x10(%rbp),%rax
je     11fa <load_samples+0x8a>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    123e <load_samples+0xce>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    $0xffffffff,%ecx
call   1080 <sh2fl_alt@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_samples>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
mov    $0x2,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11f2 <load_samples+0x82>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x2,%esi
mov    %r12,%rdx
mov    %r15,%rcx
call   1040 <fread@plt>
cmp    %r12,%rax
jne    1204 <load_samples+0x94>
mov    %r15,%rdi
call   1050 <rewind@plt>
mov    %r12,%rdi
mov    $0x4,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     11f2 <load_samples+0x82>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
mov    $0xffffffff,%ecx
call   1080 <sh2fl_alt@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
jmp    1214 <load_samples+0xa4>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [50 x i8] c"cannot allocate enough memory to buffer samples!\0A\00"
@.str.1 = [29 x i8] c"could not read all samples!\0A\00"
define float* @load_samples(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i16*
%6 = alloca float*
store i32* %0, i32** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = call i64 @calloc(i64 %7, i32 2)
%9 = inttoptr i64 %8 to i16*
store i16* %9, i16** %5
%10 = icmp eq i16* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = load i16*, i16** %5
%17 = load i64, i64* %4
%18 = load i32*, i32** %3
%19 = call i64 @fread(i16* %16, i32 2, i64 %17, i32* %18)
%20 = load i64, i64* %4
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %15
%27 = load i32*, i32** %3
%28 = call i32 @rewind(i32* %27)
%29 = load i64, i64* %4
%30 = call i64 @calloc(i64 %29, i32 4)
%31 = inttoptr i64 %30 to float*
store float* %31, float** %6
%32 = icmp eq float* %31, null
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %26
%38 = load i64, i64* %4
%39 = load i16*, i16** %5
%40 = load float*, float** %6
%41 = call i32 @sh2fl_alt(i64 %38, i16* %39, float* %40, i16 signext -1)
%42 = load i16*, i16** %5
%43 = call i32 @free(i16* %42)
%44 = load float*, float** %6
ret float* %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"cannot allocate enough memory to buffer samples!\0A\00"
@.str.1 = [29 x i8] c"could not read all samples!\0A\00"
define float* @load_samples(i32* nocapture %0, i64 %1) {
%3 = tail call i64 @calloc(i64 %1, i32 2)
%4 = inttoptr i64 %3 to i16*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = tail call i64 @fread(i16* %4, i32 2, i64 %1, i32* %0)
%12 = icmp eq i64 %11, %1
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %10
%18 = tail call i32 @rewind(i32* %0)
%19 = tail call i64 @calloc(i64 %1, i32 4)
%20 = inttoptr i64 %19 to float*
%21 = icmp eq i64 %19, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @exit(i32 -1)
unreachable
26: ; preds = %17
%27 = tail call i32 @sh2fl_alt(i64 %1, i16* %4, float* %20, i16 signext -1)
%28 = tail call i32 @free(i16* %4)
ret float* %20
}