#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(short *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
void main() {
  short d;
  int data;
  FILE *fp;
  fp = fopen("test.raw", "wb");
  while (!feof(stdin)) {
    scanf("%d", &data);
    d = (short)((data - 2048) * 32);
    fwrite(&d, 1, sizeof(short), fp);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1040 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1192 <main+0x42>
jmp    11cd <main+0x7d>
lea    0xe73(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
sub    $0x800,%eax
shl    $0x5,%eax
mov    %ax,-0x2(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x2(%rbp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
call   1070 <fwrite@plt>
jmp    116f <main+0x1f>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9c(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    0x2e6e(%rip),%r13
mov    0x0(%r13),%edi
call   1040 <feof@plt>
test   %eax,%eax
jne    11d9 <main+0x89>
lea    0xe7e(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xa(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
shl    $0x5,%eax
mov    %ax,0xa(%rsp)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    0x0(%r13),%edi
call   1040 <feof@plt>
test   %eax,%eax
je     11a0 <main+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.raw\00"
@.str.1 = [3 x i8] c"wb\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define void @main() {
%1 = alloca i16
%2 = alloca i32
%3 = alloca i32*
%4 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
br label %5
5: ; preds = %10, %0
%6 = load i32, i32* @stdin
%7 = call i32 @feof(i32 %6)
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = sub nsw i32 %12, 2048
%14 = mul nsw i32 %13, 32
%15 = trunc i32 %14 to i16
store i16 %15, i16* %1
%16 = load i32*, i32** %3
%17 = call i32 @fwrite(i16* %1, i32 1, i32 2, i32* %16)
br label %5
18: ; preds = %5
%19 = load i32*, i32** %3
%20 = call i32 @fclose(i32* %19)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.raw\00"
@.str.1 = [3 x i8] c"wb\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%d\00"
define void @main() {
%1 = alloca i16
%2 = alloca i32
%3 = bitcast i16* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @feof(i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %0, %9
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = trunc i32 %11 to i16
%13 = shl i16 %12, 5
store i16 %13, i16* %1
%14 = call i32 @fwrite(i16* %1, i32 1, i32 2, i32* %5)
%15 = load i32, i32* @stdin
%16 = call i32 @feof(i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %9, label %18
18: ; preds = %9, %0
%19 = call i32 @fclose(i32* %5)
ret void
}