#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 ssize_t;

/* Variables and functions */
scalar_t__ EINTR;
int create_raw_socket();
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int recv(int, char **, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(scalar_t__);
int main(int argc, char **argv) {
  int fd = create_raw_socket();
  if (fd < 0) {
    fprintf(stderr, "Error creating raw socket\n");
  } else {
    fprintf(stderr, "created raw socket\n");
  }
  char data[10000];
  short samples[4500];
  int skip = 1456;
  unsigned short lastno = 0;
  unsigned int packetno = 0;
  ssize_t n;
  for (;;) {
    n = recv(fd, &data, sizeof data, 0);
    if (n == -1) {
      if (errno == EINTR)
        continue;
      fprintf(stderr, "Receive error: %s.\n", strerror(errno));
      break;
    }
    fwrite(data + 14, sizeof(unsigned char), n - 14, stdout);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <create_raw_socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1199 <main+0x49>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11b0 <main+0x60>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x5b0,-0x4a64(%rbp)
movw   $0x0,-0x4a66(%rbp)
movl   $0x0,-0x4a6c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x2730(%rbp),%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x4a70(%rbp)
cmpl   $0xffffffff,-0x4a70(%rbp)
jne    124f <main+0xff>
mov    0x2ddb(%rip),%rax
mov    (%rax),%rax
mov    0x2dc9(%rip),%rcx
cmp    (%rcx),%rax
jne    1215 <main+0xc5>
jmp    11cd <main+0x7d>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4a74(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    -0x4a74(%rbp),%edi
mov    %rax,%rdx
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    127b <main+0x12b>
lea    -0x2730(%rbp),%rdi
add    $0xe,%rdi
mov    -0x4a70(%rbp),%edx
sub    $0xe,%edx
mov    0x2d5e(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1060 <fwrite@plt>
jmp    11cd <main+0x7d>
mov    -0x4(%rbp),%eax
add    $0x4a80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2718,%rsp
xor    %eax,%eax
call   1050 <create_raw_socket@plt>
mov    %eax,%ebx
test   %eax,%eax
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rax
lea    0xe98(%rip),%rsi
cmovs  %rax,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe(%rsp),%r14
mov    %rsp,%r15
mov    0x2e3b(%rip),%r13
mov    0x2e2c(%rip),%rbp
mov    0x2e1d(%rip),%r12
jmp    11c6 <main+0x76>
nopl   (%rax)
add    $0xfffffff2,%eax
mov    (%r12),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1060 <fwrite@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x60>
mov    0x0(%r13),%rdi
cmp    0x0(%rbp),%rdi
je     11c6 <main+0x76>
mov    0x2df3(%rip),%rax
mov    (%rax),%ebx
call   1070 <strerror@plt>
lea    0xe34(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x2718,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Error creating raw socket\0A\00"
@.str.1 = [20 x i8] c"created raw socket\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.2 = [20 x i8] c"Receive error: %s.\0A\00"
@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 [10000 x i8]
%8 = alloca [4500 x i16]
%9 = alloca i32
%10 = alloca i16
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (...) @create_raw_socket()
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %16
store i32 1456, i32* %9
store i16 0, i16* %10
store i32 0, i32* %11
br label %23
23: ; preds = %39, %33, %22
%24 = load i32, i32* %6
%25 = bitcast [10000 x i8]* %7 to i8**
%26 = call i32 @recv(i32 %24, i8** %25, i32 10000, i32 0)
store i32 %26, i32* %12
%27 = load i32, i32* %12
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %39
29: ; preds = %23
%30 = load i64, i64* @errno
%31 = load i64, i64* @EINTR
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %34
33: ; preds = %29
br label %23
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = load i64, i64* @errno
%37 = call i8* @strerror(i64 %36)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %46
39: ; preds = %23
%40 = getelementptr inbounds [10000 x i8], [10000 x i8]* %7, i64 0, i64 0
%41 = getelementptr inbounds i8, i8* %40, i64 14
%42 = load i32, i32* %12
%43 = sub nsw i32 %42, 14
%44 = load i32, i32* @stdout
%45 = call i32 @fwrite(i8* %41, i32 1, i32 %43, i32 %44)
br label %23
46: ; preds = %34
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Error creating raw socket\0A\00"
@.str.1 = [20 x i8] c"created raw socket\0A\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.2 = [20 x i8] c"Receive error: %s.\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10000 x i8]
%4 = tail call i32 (...) @create_raw_socket()
%5 = icmp slt i32 %4, 0
%6 = load i32, i32* @stderr
%7 = select i1 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0)
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* %7)
%9 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%10 = bitcast [10000 x i8]* %3 to i8**
%11 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 14
br label %12
12: ; preds = %27, %2
%13 = call i32 @recv(i32 %4, i8** %10, i32 10000, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br i1 %18, label %27, label %19
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i8* @strerror(i64 %16)
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %21)
ret i32 0
23: ; preds = %12
%24 = add nsw i32 %13, -14
%25 = load i32, i32* @stdout
%26 = call i32 @fwrite(i8* %11, i32 1, i32 %24, i32 %25)
br label %27
27: ; preds = %23, %15
br label %12
}