#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 scalar_t__ uint16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
size_t fwrite(scalar_t__ *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
float round(float);
int main(int argc, char *argv[]) {
  FILE *fp;
  size_t cnt;
  size_t off;
  uint16_t samples[1024];
  int i;
  float f;
  if (argc > 2)
    exit(1);
  fp = fopen(argv[1], "r+");
  if (fp == NULL) {
    perror("file open failed");
    exit(1);
  }
  off = 0;
  while (1) {
    cnt = fread(samples, sizeof(uint16_t), 1024, fp);
    if (cnt == 0)
      break;
    for (i = 0; i < cnt; i++) {
      f = (float)samples[i];
      f *= 0.0625;
      f = round(f);
      samples[i] = (uint16_t)f;
    }
    if (fseek(fp, off, SEEK_SET) != 0)
      break;
    cnt = fwrite(samples, sizeof(uint16_t), cnt, fp);
    off += (cnt * 2);
  }
  fclose(fp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11ad <main+0x2d>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e6 <main+0x66>
lea    0xe34(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movq   $0x0,-0x28(%rbp)
lea    -0x2030(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x8,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121c <main+0x9c>
jmp    130c <main+0x18c>
movl   $0x0,-0x2034(%rbp)
movslq -0x2034(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    12b5 <main+0x135>
movslq -0x2034(%rbp),%rax
cvtsi2ssq -0x2030(%rbp,%rax,8),%xmm0
df ff ff
movss  %xmm0,-0x2038(%rbp)
ff
movss  -0x2038(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
movsd  0xd9c(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x2038(%rbp)
ff
movss  -0x2038(%rbp),%xmm0
ff
call   1080 <round@plt>
movss  %xmm0,-0x2038(%rbp)
ff
cvttss2si -0x2038(%rbp),%rcx
ff ff
movslq -0x2034(%rbp),%rax
mov    %rcx,-0x2030(%rbp,%rax,8)
ff
mov    -0x2034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2034(%rbp)
jmp    1226 <main+0xa6>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2d1c(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
cmp    $0x0,%rax
je     12da <main+0x15a>
jmp    130c <main+0x18c>
lea    -0x2030(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x8,%esi
call   10a0 <fwrite@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11ee <main+0x6e>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2008,%rsp
cmp    $0x3,%edi
jl     11a0 <main+0x20>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x8(%rsi),%rdi
lea    0xe59(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11cb <main+0x4b>
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x8,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     12e3 <main+0x163>
mov    %rax,%r13
xor    %r12d,%r12d
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x1,%r13
jne    1210 <main+0x90>
xor    %ebp,%ebp
jmp    126d <main+0xed>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rbx
and    $0xfffffffffffffffe,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
cvtsi2ssq (%rsp,%rbp,8),%xmm0
movss  0xdcf(%rip),%xmm1
mulss  %xmm1,%xmm0
call   10a0 <roundf@plt>
cvttss2si %xmm0,%rax
mov    %rax,(%rsp,%rbp,8)
xorps  %xmm0,%xmm0
cvtsi2ssq 0x8(%rsp,%rbp,8),%xmm0
mulss  0xdab(%rip),%xmm0
call   10a0 <roundf@plt>
cvttss2si %xmm0,%rax
mov    %rax,0x8(%rsp,%rbp,8)
add    $0x2,%rbp
cmp    %rbp,%rbx
jne    1220 <main+0xa0>
test   $0x1,%r13b
je     1292 <main+0x112>
xorps  %xmm0,%xmm0
cvtsi2ssq (%rsp,%rbp,8),%xmm0
mulss  0xd7c(%rip),%xmm0
call   10a0 <roundf@plt>
cvttss2si %xmm0,%rax
mov    %rax,(%rsp,%rbp,8)
mov    0x2d47(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <fseek@plt>
test   %rax,%rax
jne    12e3 <main+0x163>
mov    %r15,%rdi
mov    $0x8,%esi
mov    %r13,%rdx
mov    %r14,%rcx
call   1090 <fwrite@plt>
lea    (%r12,%rax,2),%r12
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1200 <main+0x80>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@.str.1 = [17 x i8] c"file open failed\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca [1024 x i64]
%10 = alloca i32
%11 = alloca float
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @exit(i32 1)
unreachable
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, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %16
store i64 0, i64* %8
br label %27
27: ; preds = %26, %67
%28 = getelementptr inbounds [1024 x i64], [1024 x i64]* %9, i64 0, i64 0
%29 = load i32*, i32** %6
%30 = call i64 @fread(i64* %28, i32 8, i32 1024, i32* %29)
store i64 %30, i64* %7
%31 = load i64, i64* %7
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
br label %76
34: ; preds = %27
store i32 0, i32* %10
br label %35
35: ; preds = %57, %34
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = load i64, i64* %7
%39 = icmp ult i64 %37, %38
br i1 %39, label %40, label %60
40: ; preds = %35
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [1024 x i64], [1024 x i64]* %9, i64 0, i64 %42
%44 = load i64, i64* %43
%45 = sitofp i64 %44 to float
store float %45, float* %11
%46 = load float, float* %11
%47 = fpext float %46 to double
%48 = fmul double %47, 6.250000e-02
%49 = fptrunc double %48 to float
store float %49, float* %11
%50 = load float, float* %11
%51 = call float @round(float %50)
store float %51, float* %11
%52 = load float, float* %11
%53 = fptosi float %52 to i64
%54 = load i32, i32* %10
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1024 x i64], [1024 x i64]* %9, i64 0, i64 %55
store i64 %53, i64* %56
br label %57
57: ; preds = %40
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
store i32 %59, i32* %10
br label %35
60: ; preds = %35
%61 = load i32*, i32** %6
%62 = load i64, i64* %8
%63 = load i32, i32* @SEEK_SET
%64 = call i64 @fseek(i32* %61, i64 %62, i32 %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %60
br label %76
67: ; preds = %60
%68 = getelementptr inbounds [1024 x i64], [1024 x i64]* %9, i64 0, i64 0
%69 = load i64, i64* %7
%70 = load i32*, i32** %6
%71 = call i64 @fwrite(i64* %68, i32 8, i64 %69, i32* %70)
store i64 %71, i64* %7
%72 = load i64, i64* %7
%73 = mul i64 %72, 2
%74 = load i64, i64* %8
%75 = add i64 %74, %73
store i64 %75, i64* %8
br label %27
76: ; preds = %66, %33
%77 = load i32*, i32** %6
%78 = call i32 @fclose(i32* %77)
%79 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@.str.1 = [17 x i8] c"file open failed\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i64]
%4 = bitcast [1024 x i64]* %3 to i8*
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = getelementptr inbounds [1024 x i64], [1024 x i64]* %3, i64 0, i64 0
%15 = call i64 @fread(i64* %14, i32 8, i32 1024, i32* %11)
%16 = icmp eq i64 %15, 0
br i1 %16, label %66, label %20
17: ; preds = %8
%18 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %13, %60
%21 = phi i64 [ %64, %60 ], [ %15, %13 ]
%22 = phi i64 [ %63, %60 ], [ 0, %13 ]
%23 = and i64 %21, 1
%24 = icmp eq i64 %21, 1
br i1 %24, label %46, label %25
25: ; preds = %20
%26 = and i64 %21, -2
br label %27
27: ; preds = %27, %25
%28 = phi i64 [ 0, %25 ], [ %43, %27 ]
%29 = phi i64 [ 0, %25 ], [ %44, %27 ]
%30 = getelementptr inbounds [1024 x i64], [1024 x i64]* %3, i64 0, i64 %28
%31 = load i64, i64* %30
%32 = sitofp i64 %31 to float
%33 = fmul float %32, 6.250000e-02
%34 = tail call float @llvm.round.f32(float %33)
%35 = fptosi float %34 to i64
store i64 %35, i64* %30
%36 = or i64 %28, 1
%37 = getelementptr inbounds [1024 x i64], [1024 x i64]* %3, i64 0, i64 %36
%38 = load i64, i64* %37
%39 = sitofp i64 %38 to float
%40 = fmul float %39, 6.250000e-02
%41 = tail call float @llvm.round.f32(float %40)
%42 = fptosi float %41 to i64
store i64 %42, i64* %37
%43 = add nuw nsw i64 %28, 2
%44 = add i64 %29, 2
%45 = icmp eq i64 %44, %26
br i1 %45, label %46, label %27
46: ; preds = %27, %20
%47 = phi i64 [ 0, %20 ], [ %43, %27 ]
%48 = icmp eq i64 %23, 0
br i1 %48, label %56, label %49
49: ; preds = %46
%50 = getelementptr inbounds [1024 x i64], [1024 x i64]* %3, i64 0, i64 %47
%51 = load i64, i64* %50
%52 = sitofp i64 %51 to float
%53 = fmul float %52, 6.250000e-02
%54 = tail call float @llvm.round.f32(float %53)
%55 = fptosi float %54 to i64
store i64 %55, i64* %50
br label %56
56: ; preds = %46, %49
%57 = load i32, i32* @SEEK_SET
%58 = tail call i64 @fseek(i32* %11, i64 %22, i32 %57)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %56
%61 = call i64 @fwrite(i64* %14, i32 8, i64 %21, i32* %11)
%62 = shl i64 %61, 1
%63 = add i64 %62, %22
%64 = call i64 @fread(i64* %14, i32 8, i32 1024, i32* %11)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %20
66: ; preds = %60, %56, %13
%67 = tail call i32 @fclose(i32* %11)
%68 = tail call i32 @exit(i32 0)
unreachable
}