#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ aud_readinit(char *, int *, int *, int *);
int aud_writeinit(int, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ fread(char *, unsigned long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(unsigned long);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, unsigned long);
int main(int argc, char **argv) {
  char *filename;
  FILE *file;
  char *buffer;
  unsigned long file_length;
  int sample_rate;
  int sample_size;
  int channels;
  int audout_fd;
  if (argc != 2) {
    fprintf(stderr, "%s expects exactly one argument. %d found.\n", argv[0],
            argc - 1);
    exit(1);
  }
  filename = argv[1];
  if (aud_readinit(filename, &sample_rate, &sample_size, &channels) < 0) {
    perror("Error while attempting to read the audio file");
    exit(EXIT_FAILURE);
  }
  audout_fd = aud_writeinit(sample_rate, sample_size, channels);
  if (audout_fd < 0) {
    perror("Error while attempting to play the audio file");
    exit(EXIT_FAILURE);
  }
  file = fopen(filename, "rb");
  if (file == NULL) {
    fprintf(stderr,
            "An error happend while attempting to open %s for reading.\n",
            filename);
    perror("");
    exit(EXIT_FAILURE);
  }
  fseek(file, 0, SEEK_END);
  file_length = ftell(file);
  fseek(file, 0, SEEK_SET);
  buffer = (char *)malloc(file_length + 1);
  if (buffer == NULL) {
    perror("Memory error");
    exit(EXIT_FAILURE);
  }
  fread(buffer, file_length, 1, file);
  fclose(file);
  write(audout_fd, buffer, file_length * sizeof(char));
  free(buffer);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     121e <main+0x4e>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
call   1070 <aud_readinit@plt>
cmp    $0x0,%rax
jge    1263 <main+0x93>
lea    0xddc(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
call   10e0 <aud_writeinit@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1298 <main+0xc8>
lea    0xdd5(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12ec <main+0x11c>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xd52(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2cf1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2cb8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1357 <main+0x187>
lea    0xd82(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x40(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
shl    $0x0,%rdx
call   1050 <write@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c26(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    12c9 <main+0xf9>
mov    0x8(%rsi),%rbp
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbp,%rdi
call   1070 <aud_readinit@plt>
test   %rax,%rax
js     12f2 <main+0x122>
mov    0x14(%rsp),%edi
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
call   10e0 <aud_writeinit@plt>
test   %eax,%eax
js     12fb <main+0x12b>
mov    %eax,%r14d
lea    0xe5e(%rip),%rsi
mov    %rbp,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1304 <main+0x134>
mov    %rax,%rbx
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rbx,%rdi
call   1090 <ftell@plt>
mov    %rax,%r15
mov    0x2d6d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
lea    0x1(%r15),%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1327 <main+0x157>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1050 <write@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%ecx
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
add    $0xffffffff,%ecx
lea    0xd1f(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd33(%rip),%rdi
jmp    132e <main+0x15e>
lea    0xd58(%rip),%rdi
jmp    132e <main+0x15e>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xd06(%rip),%rdi
jmp    132e <main+0x15e>
lea    0xd98(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"%s expects exactly one argument. %d found.\0A\00"
@.str.1 = [46 x i8] c"Error while attempting to read the audio file\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [46 x i8] c"Error while attempting to play the audio file\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [59 x i8] c"An error happend while attempting to open %s for reading.\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [13 x i8] c"Memory error\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 1
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = call i64 @aud_readinit(i8* %29, i32* %10, i32* %11, i32* %12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %25
%37 = load i32, i32* %10
%38 = load i32, i32* %11
%39 = load i32, i32* %12
%40 = call i32 @aud_writeinit(i32 %37, i32 %38, i32 %39)
store i32 %40, i32* %13
%41 = load i32, i32* %13
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %36
%48 = load i8*, i8** %6
%49 = call i32* @fopen(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %49, i32** %7
%50 = load i32*, i32** %7
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %59
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %6
%55 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i8* %54)
%56 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %47
%60 = load i32*, i32** %7
%61 = load i32, i32* @SEEK_END
%62 = call i32 @fseek(i32* %60, i32 0, i32 %61)
%63 = load i32*, i32** %7
%64 = call i64 @ftell(i32* %63)
store i64 %64, i64* %9
%65 = load i32*, i32** %7
%66 = load i32, i32* @SEEK_SET
%67 = call i32 @fseek(i32* %65, i32 0, i32 %66)
%68 = load i64, i64* %9
%69 = add i64 %68, 1
%70 = call i64 @malloc(i64 %69)
%71 = inttoptr i64 %70 to i8*
store i8* %71, i8** %8
%72 = load i8*, i8** %8
%73 = icmp eq i8* %72, null
br i1 %73, label %74, label %78
74: ; preds = %59
%75 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %59
%79 = load i8*, i8** %8
%80 = load i64, i64* %9
%81 = load i32*, i32** %7
%82 = call i32 @fread(i8* %79, i64 %80, i32 1, i32* %81)
%83 = load i32*, i32** %7
%84 = call i32 @fclose(i32* %83)
%85 = load i32, i32* %13
%86 = load i8*, i8** %8
%87 = load i64, i64* %9
%88 = mul i64 %87, 1
%89 = call i32 @write(i32 %85, i8* %86, i64 %88)
%90 = load i8*, i8** %8
%91 = call i32 @free(i8* %90)
%92 = load i32, i32* @EXIT_SUCCESS
ret i32 %92
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"%s expects exactly one argument. %d found.\0A\00"
@.str.1 = [46 x i8] c"Error while attempting to read the audio file\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [46 x i8] c"Error while attempting to play the audio file\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [59 x i8] c"An error happend while attempting to open %s for reading.\0A\00"
@.str.5 = [1 x i8] zeroinitializer
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.6 = [13 x i8] c"Memory error\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = add nsw i32 %0, -1
%14 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @aud_readinit(i8* %18, i32* %3, i32* %4, i32* %5)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = call i32 @aud_writeinit(i32 %26, i32 %27, i32 %28)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %25
%32 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %25
%36 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%41 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %35
%45 = load i32, i32* @SEEK_END
%46 = call i32 @fseek(i32* %36, i32 0, i32 %45)
%47 = call i64 @ftell(i32* %36)
%48 = load i32, i32* @SEEK_SET
%49 = call i32 @fseek(i32* %36, i32 0, i32 %48)
%50 = add i64 %47, 1
%51 = call i64 @malloc(i64 %50)
%52 = inttoptr i64 %51 to i8*
%53 = icmp eq i64 %51, 0
br i1 %53, label %54, label %58
54: ; preds = %44
%55 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %44
%59 = call i32 @fread(i8* %52, i64 %47, i32 1, i32* %36)
%60 = call i32 @fclose(i32* %36)
%61 = call i32 @write(i32 %29, i8* %52, i64 %47)
%62 = call i32 @free(i8* %52)
%63 = load i32, i32* @EXIT_SUCCESS
ret i32 %63
}