#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_END;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *dummy_get_raw_pcm(char *p, int *bytes_read) {
  long lSize;
  char *pcm_buf;
  size_t result;
  FILE *fp_pcm;
  fp_pcm = fopen(p, "rb");
  if (fp_pcm == NULL) {
    printf("File error");
    exit(1);
  }
  fseek(fp_pcm, 0, SEEK_END);
  lSize = ftell(fp_pcm);
  rewind(fp_pcm);
  pcm_buf = (char *)malloc(sizeof(char) * lSize);
  if (pcm_buf == NULL) {
    printf("Memory error");
    exit(2);
  }
  result = fread(pcm_buf, 1, lSize, fp_pcm);
  if (result != lSize) {
    printf("Reading error");
    exit(3);
  }
  *bytes_read = (int)lSize;
  return pcm_buf;
}


x86 assembly (clang, -O0):
<dummy_get_raw_pcm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c5 <dummy_get_raw_pcm+0x45>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1223 <dummy_get_raw_pcm+0xa3>
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1261 <dummy_get_raw_pcm+0xe1>
lea    0xdc9(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dummy_get_raw_pcm>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe6e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11ff <dummy_get_raw_pcm+0x7f>
mov    %rax,%rbx
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <rewind@plt>
mov    %r15d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1215 <dummy_get_raw_pcm+0x95>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    %r15,%rax
jne    122b <dummy_get_raw_pcm+0xab>
mov    %r15d,(%r14)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xde9(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [11 x i8] c"File error\00"
@SEEK_END = global i32 0
@.str.2 = [13 x i8] c"Memory error\00"
@.str.3 = [14 x i8] c"Reading error\00"
define i8* @dummy_get_raw_pcm(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load i32*, i32** %8
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32*, i32** %8
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %17, i32 0, i32 %18)
%20 = load i32*, i32** %8
%21 = call i64 @ftell(i32* %20)
store i64 %21, i64* %5
%22 = load i32*, i32** %8
%23 = call i32 @rewind(i32* %22)
%24 = load i64, i64* %5
%25 = mul i64 1, %24
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %16
%32 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 2)
unreachable
34: ; preds = %16
%35 = load i8*, i8** %6
%36 = load i64, i64* %5
%37 = load i32*, i32** %8
%38 = call i64 @fread(i8* %35, i32 1, i64 %36, i32* %37)
store i64 %38, i64* %7
%39 = load i64, i64* %7
%40 = load i64, i64* %5
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %45
42: ; preds = %34
%43 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @exit(i32 3)
unreachable
45: ; preds = %34
%46 = load i64, i64* %5
%47 = trunc i64 %46 to i32
%48 = load i32*, i32** %4
store i32 %47, i32* %48
%49 = load i8*, i8** %6
ret i8* %49
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [11 x i8] c"File error\00"
@SEEK_END = global i32 0
@.str.2 = [13 x i8] c"Memory error\00"
@.str.3 = [14 x i8] c"Reading error\00"
define i8* @dummy_get_raw_pcm(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %3, i32 0, i32 %9)
%11 = tail call i64 @ftell(i32* %3)
%12 = tail call i32 @rewind(i32* %3)
%13 = trunc i64 %11 to i32
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = icmp eq i64 %14, 0
br i1 %16, label %17, label %20
17: ; preds = %8
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 2)
unreachable
20: ; preds = %8
%21 = tail call i64 @fread(i8* %15, i32 1, i64 %11, i32* %3)
%22 = icmp eq i64 %21, %11
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i32 @exit(i32 3)
unreachable
26: ; preds = %20
store i32 %13, i32* %1
ret i8* %15
}