#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int int32_t;
typedef scalar_t__ int16_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ MSG_WAITALL;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ floor(int);
int /*<<< orphan*/ fwrite(scalar_t__ *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ recv(int, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int sock;
  struct sockaddr_in addr;
  int32_t bufferIn[256];
  int16_t bufferOut[256];
  int32_t freq, corr, rate;
  int i;
  if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    return 1;
  }
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr("192.168.1.4");
  addr.sin_port = htons(1001);
  if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("connect");
    return 1;
  }
  rate = 1;
  rate |= 1 << 31;
  send(sock, (char *)&rate, 4, 0);
  freq = 5000000;
  corr = 25;
  freq = (int)floor(freq * (1.0 + corr * 1.0e-6) + 0.5);
  send(sock, (char *)&freq, 4, 0);
  while (1) {
    recv(sock, bufferIn, 1024, MSG_WAITALL);
    for (i = 0; i < 256; ++i) {
      bufferOut[i] = (int16_t)(bufferIn[i] >> 10);
    }
    fwrite(bufferOut, 1, 512, stdout);
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1206 <main+0x56>
lea    0xe23(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b3 <main+0x203>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xdf6(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x3e9,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1271 <main+0xc1>
lea    0xdcb(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13b3 <main+0x203>
movl   $0x1,-0xc2c(%rbp)
mov    -0xc2c(%rbp),%eax
or     $0x80000000,%eax
mov    %eax,-0xc2c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xc2c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
movl   $0x4c4b40,-0xc24(%rbp)
movl   $0x19,-0xc28(%rbp)
cvtsi2sdl -0xc24(%rbp),%xmm0
ff
cvtsi2sdl -0xc28(%rbp),%xmm1
ff
movsd  0xd3a(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xd36(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd16(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   10c0 <floor@plt>
mov    %eax,-0xc24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xc24(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    0x2c9c(%rip),%rax
mov    (%rax),%ecx
mov    $0x400,%edx
call   1030 <recv@plt>
movl   $0x0,-0xc30(%rbp)
cmpl   $0x100,-0xc30(%rbp)
jge    1381 <main+0x1d1>
movslq -0xc30(%rbp),%rax
mov    -0x420(%rbp,%rax,4),%eax
sar    $0xa,%eax
movslq %eax,%rcx
movslq -0xc30(%rbp),%rax
mov    %rcx,-0xc20(%rbp,%rax,8)
ff
mov    -0xc30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc30(%rbp)
jmp    133a <main+0x18a>
lea    -0xc20(%rbp),%rdi
mov    0x2c41(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
mov    $0x200,%edx
call   10b0 <fwrite@plt>
mov    0x2c29(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
jmp    1313 <main+0x163>
mov    -0x4(%rbp),%eax
add    $0xc30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc20,%rsp
mov    0x2e22(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     1360 <main+0x1b0>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
lea    0xe04(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0x3e9,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     1369 <main+0x1b9>
movl   $0x80000001,0x8(%rsp)
80
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    $0x4c4bbd,%edi
call   10c0 <floor@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    0x2d4b(%rip),%r12
lea    0x20(%rsp),%r14
mov    0x2d4f(%rip),%rbx
lea    0x420(%rsp),%r15
nopl   0x0(%rax)
mov    (%r12),%ecx
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1030 <recv@plt>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
movq   0x20(%rsp,%rax,4),%xmm0
movq   0x28(%rsp,%rax,4),%xmm1
psrad  $0xa,%xmm0
psrad  $0xa,%xmm1
pxor   %xmm2,%xmm2
pcmpgtd %xmm0,%xmm2
punpckldq %xmm2,%xmm0
pxor   %xmm2,%xmm2
pcmpgtd %xmm1,%xmm2
punpckldq %xmm2,%xmm1
movdqa %xmm0,0x420(%rsp,%rax,8)
movdqa %xmm1,0x430(%rsp,%rax,8)
movq   0x30(%rsp,%rax,4),%xmm0
movq   0x38(%rsp,%rax,4),%xmm1
psrad  $0xa,%xmm0
psrad  $0xa,%xmm1
pxor   %xmm2,%xmm2
pcmpgtd %xmm0,%xmm2
punpckldq %xmm2,%xmm0
pxor   %xmm2,%xmm2
pcmpgtd %xmm1,%xmm2
punpckldq %xmm2,%xmm1
movdqa %xmm0,0x440(%rsp,%rax,8)
movdqa %xmm1,0x450(%rsp,%rax,8)
add    $0x8,%rax
cmp    $0x100,%rax
jne    12b0 <main+0x100>
mov    (%rbx),%ecx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
call   10b0 <fwrite@plt>
mov    (%rbx),%edi
call   1080 <fflush@plt>
jmp    1290 <main+0xe0>
lea    0xc99(%rip),%rdi
jmp    1370 <main+0x1c0>
lea    0xca3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
add    $0xc20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [12 x i8] c"192.168.1.4\00"
@.str.2 = [8 x i8] c"connect\00"
@MSG_WAITALL = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [256 x i32]
%9 = alloca [256 x 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* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %80
20: ; preds = %2
%21 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %22, i32* %23
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = call i32 @htons(i32 1001)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* %6
%30 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%31 = call i64 @connect(i32 %29, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %20
%34 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %80
35: ; preds = %20
store i32 1, i32* %12
%36 = load i32, i32* %12
%37 = or i32 %36, -2147483648
store i32 %37, i32* %12
%38 = load i32, i32* %6
%39 = bitcast i32* %12 to i8*
%40 = call i32 @send(i32 %38, i8* %39, i32 4, i32 0)
store i32 5000000, i32* %10
store i32 25, i32* %11
%41 = load i32, i32* %10
%42 = sitofp i32 %41 to double
%43 = load i32, i32* %11
%44 = sitofp i32 %43 to double
%45 = call double @llvm.fmuladd.f64(double %44, double 0x3EB0C6F7A0B5ED8D, double 1.000000e+00)
%46 = call double @llvm.fmuladd.f64(double %42, double %45, double 5.000000e-01)
%47 = fptosi double %46 to i32
%48 = call i64 @floor(i32 %47)
%49 = trunc i64 %48 to i32
store i32 %49, i32* %10
%50 = load i32, i32* %6
%51 = bitcast i32* %10 to i8*
%52 = call i32 @send(i32 %50, i8* %51, i32 4, i32 0)
br label %53
53: ; preds = %35, %74
%54 = load i32, i32* %6
%55 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 0
%56 = load i32, i32* @MSG_WAITALL
%57 = call i32 @recv(i32 %54, i32* %55, i32 1024, i32 %56)
store i32 0, i32* %13
br label %58
58: ; preds = %71, %53
%59 = load i32, i32* %13
%60 = icmp slt i32 %59, 256
br i1 %60, label %61, label %74
61: ; preds = %58
%62 = load i32, i32* %13
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = ashr i32 %65, 10
%67 = sext i32 %66 to i64
%68 = load i32, i32* %13
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [256 x i64], [256 x i64]* %9, i64 0, i64 %69
store i64 %67, i64* %70
br label %71
71: ; preds = %61
%72 = load i32, i32* %13
%73 = add nsw i32 %72, 1
store i32 %73, i32* %13
br label %58
74: ; preds = %58
%75 = getelementptr inbounds [256 x i64], [256 x i64]* %9, i64 0, i64 0
%76 = load i32, i32* @stdout
%77 = call i32 @fwrite(i64* %75, i32 1, i32 512, i32 %76)
%78 = load i32, i32* @stdout
%79 = call i32 @fflush(i32 %78)
br label %53
80: ; preds = %33, %18
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [12 x i8] c"192.168.1.4\00"
@.str.2 = [8 x i8] c"connect\00"
@MSG_WAITALL = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i32]
%5 = alloca [256 x i64]
%6 = alloca i32
%7 = alloca i32
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast [256 x i32]* %4 to i8*
%10 = bitcast [256 x i64]* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %80
19: ; preds = %2
%20 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @inet_addr(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = call i32 @htons(i32 1001)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i64 @connect(i32 %15, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %19
%31 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %80
32: ; preds = %19
store i32 -2147483647, i32* %7
%33 = call i32 @send(i32 %15, i8* %12, i32 4, i32 0)
%34 = call i64 @floor(i32 5000125)
%35 = trunc i64 %34 to i32
store i32 %35, i32* %6
%36 = call i32 @send(i32 %15, i8* %11, i32 4, i32 0)
%37 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 0
%38 = getelementptr inbounds [256 x i64], [256 x i64]* %5, i64 0, i64 0
br label %39
39: ; preds = %75, %32
%40 = load i32, i32* @MSG_WAITALL
%41 = call i32 @recv(i32 %15, i32* %37, i32 1024, i32 %40)
br label %42
42: ; preds = %42, %39
%43 = phi i64 [ 0, %39 ], [ %73, %42 ]
%44 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %43
%45 = bitcast i32* %44 to <2 x i32>*
%46 = load <2 x i32>, <2 x i32>* %45
%47 = getelementptr inbounds i32, i32* %44, i64 2
%48 = bitcast i32* %47 to <2 x i32>*
%49 = load <2 x i32>, <2 x i32>* %48
%50 = ashr <2 x i32> %46, <i32 10, i32 10>
%51 = ashr <2 x i32> %49, <i32 10, i32 10>
%52 = sext <2 x i32> %50 to <2 x i64>
%53 = sext <2 x i32> %51 to <2 x i64>
%54 = getelementptr inbounds [256 x i64], [256 x i64]* %5, i64 0, i64 %43
%55 = bitcast i64* %54 to <2 x i64>*
store <2 x i64> %52, <2 x i64>* %55
%56 = getelementptr inbounds i64, i64* %54, i64 2
%57 = bitcast i64* %56 to <2 x i64>*
store <2 x i64> %53, <2 x i64>* %57
%58 = or i64 %43, 4
%59 = getelementptr inbounds [256 x i32], [256 x i32]* %4, i64 0, i64 %58
%60 = bitcast i32* %59 to <2 x i32>*
%61 = load <2 x i32>, <2 x i32>* %60
%62 = getelementptr inbounds i32, i32* %59, i64 2
%63 = bitcast i32* %62 to <2 x i32>*
%64 = load <2 x i32>, <2 x i32>* %63
%65 = ashr <2 x i32> %61, <i32 10, i32 10>
%66 = ashr <2 x i32> %64, <i32 10, i32 10>
%67 = sext <2 x i32> %65 to <2 x i64>
%68 = sext <2 x i32> %66 to <2 x i64>
%69 = getelementptr inbounds [256 x i64], [256 x i64]* %5, i64 0, i64 %58
%70 = bitcast i64* %69 to <2 x i64>*
store <2 x i64> %67, <2 x i64>* %70
%71 = getelementptr inbounds i64, i64* %69, i64 2
%72 = bitcast i64* %71 to <2 x i64>*
store <2 x i64> %68, <2 x i64>* %72
%73 = add nuw nsw i64 %43, 8
%74 = icmp eq i64 %73, 256
br i1 %74, label %75, label %42
75: ; preds = %42
%76 = load i32, i32* @stdout
%77 = call i32 @fwrite(i64* %38, i32 1, i32 512, i32 %76)
%78 = load i32, i32* @stdout
%79 = call i32 @fflush(i32 %78)
br label %39
80: ; preds = %30, %17
ret i32 1
}