#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ ECONNRESET;
scalar_t__ EPIPE;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char, double, ...);
int write(int, char *, int const);
int send_packet(char *path_low_order_data, char *path_high_order_data,
                int client, int first_half_file) {
  const int PACKET_LEN = 32768;
  char low_order_buffer[PACKET_LEN];
  char high_order_buffer[PACKET_LEN];
  FILE *low_order_datafile;
  FILE *high_order_datafile;
  int N_bytes_sent = 0;
  struct timeval start_tv;
  struct timeval end_tv;
  double start_time;
  double end_time;
  double duration;
  int i = 0;
  int seek_position = 0;
  int count_pixel0 = 0;
  char last_pixel = -1;
  int last_stamp = -1;
  int stamp = 0;
  int lost_packet_check = 1;
  if (first_half_file == 0)
    seek_position = PACKET_LEN;
  gettimeofday(&start_tv, NULL);
  low_order_datafile = fopen(path_low_order_data, "rb");
  fseek(low_order_datafile, seek_position, SEEK_SET);
  fread(low_order_buffer, sizeof(char), PACKET_LEN, low_order_datafile);
  fclose(low_order_datafile);
  N_bytes_sent = write(client, low_order_buffer, PACKET_LEN);
  if (N_bytes_sent != PACKET_LEN)
    return N_bytes_sent;
  high_order_datafile = fopen(path_high_order_data, "rb");
  fseek(high_order_datafile, seek_position, SEEK_SET);
  fread(high_order_buffer, sizeof(char), PACKET_LEN, high_order_datafile);
  fclose(high_order_datafile);
  N_bytes_sent = write(client, high_order_buffer, PACKET_LEN);
  if (errno == EPIPE) {
    errno = ECONNRESET;
    return -1;
  }
  if (N_bytes_sent != PACKET_LEN)
    return N_bytes_sent;
  for (i = 0; i < PACKET_LEN; i += 4) {
    if (high_order_buffer[i] == 0)
      count_pixel0++;
    if (0 == 1) {
      if (last_pixel != (char)(-1) &&
          (high_order_buffer[i] - last_pixel) + 256 % 256 != 1) {
        printf("Skipped from pixel %x to %x\n", last_pixel,
               high_order_buffer[i]);
      }
    }
    last_pixel = high_order_buffer[i];
  }
  gettimeofday(&end_tv, NULL);
  start_time = start_tv.tv_sec + start_tv.tv_usec * 1e-6;
  end_time = end_tv.tv_sec + end_tv.tv_usec * 1e-6;
  printf("pixel %x at %.3f took %.3f\n", high_order_buffer[0], start_time,
         end_time - start_time);
  return N_bytes_sent;
}


x86 assembly (clang, -O0):
<send_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10090,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movl   $0x8000,-0x24(%rbp)
mov    %rsp,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
movb   $0xff,-0x7d(%rbp)
movl   $0xffffffff,-0x84(%rbp)
ff ff ff
movl   $0x0,-0x88(%rbp)
movl   $0x1,-0x8c(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11e6 <send_packet+0x76>
movl   $0x8000,-0x78(%rbp)
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    -0x10(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x78(%rbp),%esi
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    -0x38(%rbp),%rcx
lea    -0x8090(%rbp),%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
call   1030 <fread@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1c(%rbp),%edi
lea    -0x8090(%rbp),%rsi
mov    $0x8000,%edx
call   1040 <write@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x8000,-0x44(%rbp)
je     1278 <send_packet+0x108>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1410 <send_packet+0x2a0>
mov    -0x18(%rbp),%rdi
lea    0xd85(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x78(%rbp),%esi
mov    0x2d2e(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    -0x40(%rbp),%rcx
lea    -0x10090(%rbp),%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
call   1030 <fread@plt>
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1c(%rbp),%edi
lea    -0x10090(%rbp),%rsi
mov    $0x8000,%edx
call   1040 <write@plt>
mov    %eax,-0x44(%rbp)
mov    0x2cee(%rip),%rax
mov    (%rax),%rax
mov    0x2cec(%rip),%rcx
cmp    (%rcx),%rax
jne    131f <send_packet+0x1af>
mov    0x2ce4(%rip),%rax
mov    (%rax),%rcx
mov    0x2cca(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1410 <send_packet+0x2a0>
cmpl   $0x8000,-0x44(%rbp)
je     1341 <send_packet+0x1d1>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    1410 <send_packet+0x2a0>
movl   $0x0,-0x74(%rbp)
cmpl   $0x8000,-0x74(%rbp)
jge    138f <send_packet+0x21f>
movslq -0x74(%rbp),%rax
movsbl -0x10090(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    1373 <send_packet+0x203>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
movslq -0x74(%rbp),%rax
mov    -0x10090(%rbp,%rax,1),%al
mov    %al,-0x7d(%rbp)
mov    -0x74(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x74(%rbp)
jmp    1348 <send_packet+0x1d8>
lea    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
cvtsi2sdl -0x50(%rbp),%xmm1
cvtsi2sdl -0x4c(%rbp),%xmm0
movsd  0xc52(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
cvtsi2sdl -0x58(%rbp),%xmm1
cvtsi2sdl -0x54(%rbp),%xmm0
movsd  0xc33(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x10090(%rbp),%al
movsd  -0x60(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
subsd  -0x60(%rbp),%xmm1
lea    0xc15(%rip),%rdi
movsbl %al,%esi
mov    $0x2,%al
call   1060 <printf@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x10090,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_packet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10018,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
test   %ecx,%ecx
sete   %bpl
shl    $0xf,%ebp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    0x2e0e(%rip),%r13
mov    0x0(%r13),%edx
mov    %rax,%rdi
mov    %ebp,%esi
call   1080 <fseek@plt>
lea    0x8010(%rsp),%r12
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x8000,%edx
call   1040 <write@plt>
cmp    $0x8000,%eax
jne    12ea <send_packet+0x17a>
lea    0xe01(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    0x0(%r13),%edx
mov    %rax,%rdi
mov    %ebp,%esi
call   1080 <fseek@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x8000,%edx
call   1040 <write@plt>
mov    0x2d6f(%rip),%rcx
mov    (%rcx),%rdx
mov    0x2d6d(%rip),%rsi
cmp    (%rsi),%rdx
jne    1284 <send_packet+0x114>
mov    0x2d69(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rcx)
mov    $0xffffffff,%eax
jmp    12ea <send_packet+0x17a>
cmp    $0x8000,%eax
jne    12ea <send_packet+0x17a>
mov    %rsp,%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
movss  0x8(%rsp),%xmm0
movss  (%rsp),%xmm1
unpcklps %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm0
movss  0xc(%rsp),%xmm1
movss  0x4(%rsp),%xmm2
unpcklps %xmm1,%xmm2
cvtdq2pd %xmm2,%xmm1
mulpd  0xd3e(%rip),%xmm1
addpd  %xmm0,%xmm1
movsbl 0x10(%rsp),%esi
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
subsd  %xmm0,%xmm1
lea    0xd35(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
mov    $0x8000,%eax
add    $0x10018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
@errno = global i64 0
@EPIPE = global i64 0
@ECONNRESET = global i64 0
@.str.1 = [28 x i8] c"pixel %x at %.3f took %.3f\0A\00"
define i32 @send_packet(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca %struct.timeval
%16 = alloca %struct.timeval
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i8
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 32768, i32* %10
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %11
%29 = alloca i8, i64 32768
%30 = alloca i8, i64 32768
store i32 0, i32* %14
store i32 0, i32* %20
store i32 0, i32* %21
store i32 0, i32* %22
store i8 -1, i8* %23
store i32 -1, i32* %24
store i32 0, i32* %25
store i32 1, i32* %26
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %4
store i32 32768, i32* %21
br label %34
34: ; preds = %33, %4
%35 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
%36 = load i8*, i8** %6
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %37, i32** %12
%38 = load i32*, i32** %12
%39 = load i32, i32* %21
%40 = load i32, i32* @SEEK_SET
%41 = call i32 @fseek(i32* %38, i32 %39, i32 %40)
%42 = load i32*, i32** %12
%43 = call i32 @fread(i8* %29, i32 1, i32 32768, i32* %42)
%44 = load i32*, i32** %12
%45 = call i32 @fclose(i32* %44)
%46 = load i32, i32* %8
%47 = call i32 @write(i32 %46, i8* %29, i32 32768)
store i32 %47, i32* %14
%48 = load i32, i32* %14
%49 = icmp ne i32 %48, 32768
br i1 %49, label %50, label %52
50: ; preds = %34
%51 = load i32, i32* %14
store i32 %51, i32* %5
store i32 1, i32* %27
br label %121
52: ; preds = %34
%53 = load i8*, i8** %7
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %54, i32** %13
%55 = load i32*, i32** %13
%56 = load i32, i32* %21
%57 = load i32, i32* @SEEK_SET
%58 = call i32 @fseek(i32* %55, i32 %56, i32 %57)
%59 = load i32*, i32** %13
%60 = call i32 @fread(i8* %30, i32 1, i32 32768, i32* %59)
%61 = load i32*, i32** %13
%62 = call i32 @fclose(i32* %61)
%63 = load i32, i32* %8
%64 = call i32 @write(i32 %63, i8* %30, i32 32768)
store i32 %64, i32* %14
%65 = load i64, i64* @errno
%66 = load i64, i64* @EPIPE
%67 = icmp eq i64 %65, %66
br i1 %67, label %68, label %70
68: ; preds = %52
%69 = load i64, i64* @ECONNRESET
store i64 %69, i64* @errno
store i32 -1, i32* %5
store i32 1, i32* %27
br label %121
70: ; preds = %52
%71 = load i32, i32* %14
%72 = icmp ne i32 %71, 32768
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = load i32, i32* %14
store i32 %74, i32* %5
store i32 1, i32* %27
br label %121
75: ; preds = %70
store i32 0, i32* %20
br label %76
76: ; preds = %94, %75
%77 = load i32, i32* %20
%78 = icmp slt i32 %77, 32768
br i1 %78, label %79, label %97
79: ; preds = %76
%80 = load i32, i32* %20
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %30, i64 %81
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %79
%87 = load i32, i32* %22
%88 = add nsw i32 %87, 1
store i32 %88, i32* %22
br label %89
89: ; preds = %86, %79
%90 = load i32, i32* %20
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %30, i64 %91
%93 = load i8, i8* %92
store i8 %93, i8* %23
br label %94
94: ; preds = %89
%95 = load i32, i32* %20
%96 = add nsw i32 %95, 4
store i32 %96, i32* %20
br label %76
97: ; preds = %76
%98 = call i32 @gettimeofday(%struct.timeval* %16, i32* null)
%99 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%100 = load i32, i32* %99
%101 = sitofp i32 %100 to double
%102 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%103 = load i32, i32* %102
%104 = sitofp i32 %103 to double
%105 = call double @llvm.fmuladd.f64(double %104, double 0x3EB0C6F7A0B5ED8D, double %101)
store double %105, double* %17
%106 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%107 = load i32, i32* %106
%108 = sitofp i32 %107 to double
%109 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%110 = load i32, i32* %109
%111 = sitofp i32 %110 to double
%112 = call double @llvm.fmuladd.f64(double %111, double 0x3EB0C6F7A0B5ED8D, double %108)
store double %112, double* %18
%113 = getelementptr inbounds i8, i8* %30, i64 0
%114 = load i8, i8* %113
%115 = load double, double* %17
%116 = load double, double* %18
%117 = load double, double* %17
%118 = fsub double %116, %117
%119 = call i32 (i8*, i8, double, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8 signext %114, double %115, double %118)
%120 = load i32, i32* %14
store i32 %120, i32* %5
store i32 1, i32* %27
br label %121
121: ; preds = %97, %73, %68, %50
%122 = load i8*, i8** %11
%123 = load i32, i32* %5
ret i32 %123
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [3 x i8] c"rb\00"
@SEEK_SET = global i32 0
@errno = global i64 0
@EPIPE = global i64 0
@ECONNRESET = global i64 0
@.str.1 = [28 x i8] c"pixel %x at %.3f took %.3f\0A\00"
define i32 @send_packet(i8* nocapture %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca [32768 x i8]
%8 = alloca [32768 x i8]
%9 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%10 = getelementptr inbounds [32768 x i8], [32768 x i8]* %7, i64 0, i64 0
%11 = bitcast %struct.timeval* %5 to i8*
%12 = bitcast %struct.timeval* %6 to i8*
%13 = icmp eq i32 %3, 0
%14 = select i1 %13, i32 32768, i32 0
%15 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%16 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @fseek(i32* %16, i32 %14, i32 %17)
%19 = call i32 @fread(i8* %10, i32 1, i32 32768, i32* %16)
%20 = tail call i32 @fclose(i32* %16)
%21 = call i32 @write(i32 %2, i8* %10, i32 32768)
%22 = icmp eq i32 %21, 32768
br i1 %22, label %23, label %59
23: ; preds = %4
%24 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @SEEK_SET
%26 = tail call i32 @fseek(i32* %24, i32 %14, i32 %25)
%27 = call i32 @fread(i8* %9, i32 1, i32 32768, i32* %24)
%28 = tail call i32 @fclose(i32* %24)
%29 = call i32 @write(i32 %2, i8* %9, i32 32768)
%30 = load i64, i64* @errno
%31 = load i64, i64* @EPIPE
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %23
%34 = load i64, i64* @ECONNRESET
store i64 %34, i64* @errno
br label %59
35: ; preds = %23
%36 = icmp eq i32 %29, 32768
br i1 %36, label %37, label %59
37: ; preds = %35
%38 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%44 = load i32, i32* %43
%45 = insertelement <2 x i32> poison, i32 %44, i64 0
%46 = insertelement <2 x i32> %45, i32 %40, i64 1
%47 = sitofp <2 x i32> %46 to <2 x double>
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%49 = load i32, i32* %48
%50 = insertelement <2 x i32> poison, i32 %49, i64 0
%51 = insertelement <2 x i32> %50, i32 %42, i64 1
%52 = sitofp <2 x i32> %51 to <2 x double>
%53 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %52, <2 x double> <double 0x3EB0C6F7A0B5ED8D, double 0x3EB0C6F7A0B5ED8D>, <2 x double> %47)
%54 = load i8, i8* %9
%55 = extractelement <2 x double> %53, i64 0
%56 = extractelement <2 x double> %53, i64 1
%57 = fsub double %55, %56
%58 = tail call i32 (i8*, i8, double, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8 signext %54, double %56, double %57)
br label %59
59: ; preds = %35, %4, %37, %33
%60 = phi i32 [ -1, %33 ], [ 32768, %37 ], [ %21, %4 ], [ %29, %35 ]
ret i32 %60
}