#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 atoi(char *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ is_little_endian();
int /*<<< orphan*/ printf(char *, double, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Usage: ./raw2dat [rawfile] [freq(default 48000Hz)]\n");
    return 0;
  }
  FILE *fp = fopen(argv[1], "rb");
  double line = 0;
  double freq = (argc > 2) ? atoi(argv[2]) : 48000;
  int c;
  while ((c = fgetc(fp)) != -1) {
    int d = fgetc(fp);
    if (is_little_endian()) {
      c |= d << 8;
    } else {
      c = c << 8 | d;
    }
    printf("%f %d\n", line / freq, c);
    line++;
  }
  return 0;
}


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)
jge    11a1 <main+0x41>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    127f <main+0x11f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11e0 <main+0x80>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x34(%rbp)
jmp    11ed <main+0x8d>
mov    $0xbb80,%eax
mov    %eax,-0x34(%rbp)
jmp    11ed <main+0x8d>
mov    -0x34(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     1278 <main+0x118>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <is_little_endian@plt>
cmp    $0x0,%rax
je     123c <main+0xdc>
mov    -0x30(%rbp),%eax
shl    $0x8,%eax
or     -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1248 <main+0xe8>
mov    -0x2c(%rbp),%eax
shl    $0x8,%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
mov    -0x2c(%rbp),%esi
lea    0xde3(%rip),%rdi
call   1030 <printf@plt>
movsd  0xd97(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11f9 <main+0x99>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jg     1189 <main+0x29>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1050 <fprintf@plt>
jmp    124c <main+0xec>
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
cmp    $0x2,%ebp
jne    11b0 <main+0x50>
movsd  0xe52(%rip),%xmm0
jmp    11bd <main+0x5d>
mov    0x10(%r14),%rdi
call   1070 <atoi@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r15,%rdi
call   1040 <fgetc@plt>
cmp    $0xffffffff,%eax
je     124c <main+0xec>
mov    %eax,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xe64(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1080 <is_little_endian@plt>
mov    %ebx,%ecx
shl    $0x8,%ecx
or     %ebp,%ecx
shl    $0x8,%ebp
or     %ebx,%ebp
test   %rax,%rax
cmovne %ecx,%ebp
movsd  0x8(%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0xdd1(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11f0 <main+0x90>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [52 x i8] c"Usage: ./raw2dat [rawfile] [freq(default 48000Hz)]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [7 x i8] c"%f %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %60
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
store double 0.000000e+00, double* %7
%21 = load i32, i32* %4
%22 = icmp sgt i32 %21, 2
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
br label %29
28: ; preds = %16
br label %29
29: ; preds = %28, %23
%30 = phi i32 [ %27, %23 ], [ 48000, %28 ]
%31 = sitofp i32 %30 to double
store double %31, double* %8
br label %32
32: ; preds = %51, %29
%33 = load i32*, i32** %6
%34 = call i32 @fgetc(i32* %33)
store i32 %34, i32* %9
%35 = icmp ne i32 %34, -1
br i1 %35, label %36, label %59
36: ; preds = %32
%37 = load i32*, i32** %6
%38 = call i32 @fgetc(i32* %37)
store i32 %38, i32* %10
%39 = call i64 (...) @is_little_endian()
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i32, i32* %10
%43 = shl i32 %42, 8
%44 = load i32, i32* %9
%45 = or i32 %44, %43
store i32 %45, i32* %9
br label %51
46: ; preds = %36
%47 = load i32, i32* %9
%48 = shl i32 %47, 8
%49 = load i32, i32* %10
%50 = or i32 %48, %49
store i32 %50, i32* %9
br label %51
51: ; preds = %46, %41
%52 = load double, double* %7
%53 = load double, double* %8
%54 = fdiv double %52, %53
%55 = load i32, i32* %9
%56 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %54, i32 %55)
%57 = load double, double* %7
%58 = fadd double %57, 1.000000e+00
store double %58, double* %7
br label %32
59: ; preds = %32
store i32 0, i32* %3
br label %60
60: ; preds = %59, %13
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [52 x i8] c"Usage: ./raw2dat [rawfile] [freq(default 48000Hz)]\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [7 x i8] c"%f %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
br label %37
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %0, 2
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = sitofp i32 %15 to double
br label %17
17: ; preds = %7, %12
%18 = phi double [ %16, %12 ], [ 4.800000e+04, %7 ]
%19 = tail call i32 @fgetc(i32* %10)
%20 = icmp eq i32 %19, -1
br i1 %20, label %37, label %21
21: ; preds = %17, %21
%22 = phi i32 [ %35, %21 ], [ %19, %17 ]
%23 = phi double [ %34, %21 ], [ 0.000000e+00, %17 ]
%24 = tail call i32 @fgetc(i32* %10)
%25 = tail call i64 (...) @is_little_endian()
%26 = icmp eq i64 %25, 0
%27 = shl i32 %24, 8
%28 = or i32 %27, %22
%29 = shl i32 %22, 8
%30 = or i32 %24, %29
%31 = select i1 %26, i32 %30, i32 %28
%32 = fdiv double %23, %18
%33 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %32, i32 %31)
%34 = fadd double %23, 1.000000e+00
%35 = tail call i32 @fgetc(i32* %10)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %21
37: ; preds = %21, %17, %4
ret i32 0
}