#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__ uint64_t;
struct sockaddr_ll {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ rbuf;
typedef int /*<<< orphan*/ from;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long long, unsigned long long);
int read(int /*<<< orphan*/, char *, int);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int send(int, char *, unsigned int, int);
void mainloop(int s, int iface) {
  char packet[4096], rbuf[4096];
  unsigned int plen = 1024;
  int ret, i;
  struct sockaddr_ll from;
  socklen_t slen = sizeof(from);
  union {
    uint64_t uint;
    char c[8];
  } clock;
  static uint64_t t;
  ret = recvfrom(s, rbuf, sizeof(rbuf), 0, (struct sockaddr *)&from, &slen);
  if (ret < 0) {
    perror("recvfrom");
    exit(1);
  }
  clock.c[7] = rbuf[16];
  clock.c[6] = rbuf[17];
  clock.c[5] = rbuf[18];
  clock.c[4] = rbuf[19];
  clock.c[3] = rbuf[20];
  clock.c[2] = rbuf[21];
  clock.c[1] = rbuf[22];
  clock.c[0] = rbuf[23];
  printf("Clockdelta: %lld   Clock: %llu           \r",
         (long long)(clock.uint - t), (unsigned long long)(clock.uint));
  t = clock.uint;
  memcpy(packet, "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x04\x75\xc6\xd7\xc1\x88\xb5\x00",
         15);
  for (i = 0; i < 4; i++) {
    ret = read(0, (packet + 15), 128 * 2 * 24 / 8);
    if (ret != 128 * 2 * 24 / 8) {
      perror("read");
      exit(1);
    }
    plen = 15 + 128 * 2 * 24 / 8;
    ret = send(s, packet, plen, 0x0);
    if (ret < 0) {
      perror("sendto");
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<mainloop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x400,-0x2014(%rbp)
movl   $0x4,-0x2024(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x2010(%rbp),%rsi
lea    -0x2020(%rbp),%r8
mov    $0x1000,%edx
xor    %ecx,%ecx
lea    -0x2024(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x2018(%rbp)
cmpl   $0x0,-0x2018(%rbp)
jge    11e2 <mainloop+0x72>
lea    0xe2d(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x2000(%rbp),%al
mov    %al,-0x2029(%rbp)
mov    -0x1fff(%rbp),%al
mov    %al,-0x202a(%rbp)
mov    -0x1ffe(%rbp),%al
mov    %al,-0x202b(%rbp)
mov    -0x1ffd(%rbp),%al
mov    %al,-0x202c(%rbp)
mov    -0x1ffc(%rbp),%al
mov    %al,-0x202d(%rbp)
mov    -0x1ffb(%rbp),%al
mov    %al,-0x202e(%rbp)
mov    -0x1ffa(%rbp),%al
mov    %al,-0x202f(%rbp)
mov    -0x1ff9(%rbp),%al
mov    %al,-0x2030(%rbp)
mov    -0x2030(%rbp),%rsi
sub    0x2e10(%rip),%rsi
mov    -0x2030(%rbp),%rdx
lea    0xdab(%rip),%rdi
call   1040 <printf@plt>
mov    -0x2030(%rbp),%rax
mov    %rax,0x2def(%rip)
lea    -0x1010(%rbp),%rdi
lea    0xdc1(%rip),%rsi
mov    $0xf,%edx
call   1060 <memcpy@plt>
movl   $0x0,-0x201c(%rbp)
cmpl   $0x4,-0x201c(%rbp)
jge    1346 <mainloop+0x1d6>
lea    -0x1010(%rbp),%rsi
add    $0xf,%rsi
xor    %edi,%edi
mov    $0x300,%edx
call   1050 <read@plt>
mov    %eax,-0x2018(%rbp)
cmpl   $0x300,-0x2018(%rbp)
je     12e3 <mainloop+0x173>
lea    0xd60(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x30f,-0x2014(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    -0x2014(%rbp),%edx
xor    %ecx,%ecx
call   1030 <send@plt>
mov    %eax,-0x2018(%rbp)
cmpl   $0x0,-0x2018(%rbp)
jge    132d <mainloop+0x1bd>
lea    0xd1b(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1332 <mainloop+0x1c2>
mov    -0x201c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x201c(%rbp)
jmp    1293 <mainloop+0x123>
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mainloop>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2010,%rsp
mov    %edi,%ebp
movl   $0x4,0x4(%rsp)
lea    0x1010(%rsp),%rsi
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1070 <recvfrom@plt>
test   %eax,%eax
js     12cb <mainloop+0x15b>
mov    0x1020(%rsp),%rbx
bswap  %rbx
mov    %rbx,%rsi
sub    0x2ea0(%rip),%rsi
lea    0xe42(%rip),%rdi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    %rbx,0x2e8a(%rip)
lea    0xe63(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0xf,%edx
call   1060 <memcpy@plt>
lea    0x1f(%rsp),%r14
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x300,%edx
call   1050 <read@plt>
cmp    $0x300,%eax
jne    12b9 <mainloop+0x149>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x30f,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
test   %eax,%eax
js     12c2 <mainloop+0x152>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x300,%edx
call   1050 <read@plt>
cmp    $0x300,%eax
jne    12b9 <mainloop+0x149>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x30f,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
test   %eax,%eax
js     12c2 <mainloop+0x152>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x300,%edx
call   1050 <read@plt>
cmp    $0x300,%eax
jne    12b9 <mainloop+0x149>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x30f,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
test   %eax,%eax
js     12c2 <mainloop+0x152>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x300,%edx
call   1050 <read@plt>
cmp    $0x300,%eax
jne    12b9 <mainloop+0x149>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x30f,%edx
xor    %ecx,%ecx
call   1030 <send@plt>
test   %eax,%eax
js     12c2 <mainloop+0x152>
add    $0x2010,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd74(%rip),%rdi
jmp    12d2 <mainloop+0x162>
lea    0xd70(%rip),%rdi
jmp    12d2 <mainloop+0x162>
lea    0xd2e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_ll = type { i32 }
%union.anon = type { i64 }
%struct.sockaddr = type { i32 }
@mainloop.t = internal global i64 0
@.str = [9 x i8] c"recvfrom\00"
@.str.1 = [43 x i8] c"Clockdelta: %lld Clock: %llu \0D\00"
@.str.2 = [16 x i8] c"\FF\FF\FF\FF\FF\FF\00\04u\C6\D7\C1\88\B5\00\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [7 x i8] c"sendto\00"
define void @mainloop(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4096 x i8]
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_ll
%11 = alloca i32
%12 = alloca %union.anon
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 1024, i32* %7
store i32 4, i32* %11
%13 = load i32, i32* %3
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%15 = bitcast %struct.sockaddr_ll* %10 to %struct.sockaddr*
%16 = call i32 @recvfrom(i32 %13, i8* %14, i32 4096, i32 0, %struct.sockaddr* %15, i32* %11)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 16
%24 = load i8, i8* %23
%25 = bitcast %union.anon* %12 to [8 x i8]*
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %25, i64 0, i64 7
store i8 %24, i8* %26
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 17
%28 = load i8, i8* %27
%29 = bitcast %union.anon* %12 to [8 x i8]*
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %29, i64 0, i64 6
store i8 %28, i8* %30
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 18
%32 = load i8, i8* %31
%33 = bitcast %union.anon* %12 to [8 x i8]*
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %33, i64 0, i64 5
store i8 %32, i8* %34
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 19
%36 = load i8, i8* %35
%37 = bitcast %union.anon* %12 to [8 x i8]*
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %37, i64 0, i64 4
store i8 %36, i8* %38
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 20
%40 = load i8, i8* %39
%41 = bitcast %union.anon* %12 to [8 x i8]*
%42 = getelementptr inbounds [8 x i8], [8 x i8]* %41, i64 0, i64 3
store i8 %40, i8* %42
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 21
%44 = load i8, i8* %43
%45 = bitcast %union.anon* %12 to [8 x i8]*
%46 = getelementptr inbounds [8 x i8], [8 x i8]* %45, i64 0, i64 2
store i8 %44, i8* %46
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 22
%48 = load i8, i8* %47
%49 = bitcast %union.anon* %12 to [8 x i8]*
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %49, i64 0, i64 1
store i8 %48, i8* %50
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 23
%52 = load i8, i8* %51
%53 = bitcast %union.anon* %12 to [8 x i8]*
%54 = getelementptr inbounds [8 x i8], [8 x i8]* %53, i64 0, i64 0
store i8 %52, i8* %54
%55 = bitcast %union.anon* %12 to i64*
%56 = load i64, i64* %55
%57 = load i64, i64* @mainloop.t
%58 = sub nsw i64 %56, %57
%59 = bitcast %union.anon* %12 to i64*
%60 = load i64, i64* %59
%61 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i64 %58, i64 %60)
%62 = bitcast %union.anon* %12 to i64*
%63 = load i64, i64* %62
store i64 %63, i64* @mainloop.t
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%65 = call i32 @memcpy(i8* %64, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 15)
store i32 0, i32* %9
br label %66
66: ; preds = %89, %22
%67 = load i32, i32* %9
%68 = icmp slt i32 %67, 4
br i1 %68, label %69, label %92
69: ; preds = %66
%70 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%71 = getelementptr inbounds i8, i8* %70, i64 15
%72 = call i32 @read(i32 0, i8* %71, i32 768)
store i32 %72, i32* %8
%73 = load i32, i32* %8
%74 = icmp ne i32 %73, 768
br i1 %74, label %75, label %78
75: ; preds = %69
%76 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %69
store i32 783, i32* %7
%79 = load i32, i32* %3
%80 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%81 = load i32, i32* %7
%82 = call i32 @send(i32 %79, i8* %80, i32 %81, i32 0)
store i32 %82, i32* %8
%83 = load i32, i32* %8
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %78
%86 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %78
br label %89
89: ; preds = %88
%90 = load i32, i32* %9
%91 = add nsw i32 %90, 1
store i32 %91, i32* %9
br label %66
92: ; preds = %66
ret void
}

LLVM IR (-O2):
%struct.sockaddr_ll = type { i32 }
%struct.sockaddr = type { i32 }
@mainloop.t = internal unnamed_addr global i64 0
@.str = [9 x i8] c"recvfrom\00"
@.str.1 = [43 x i8] c"Clockdelta: %lld Clock: %llu \0D\00"
@.str.2 = [16 x i8] c"\FF\FF\FF\FF\FF\FF\00\04u\C6\D7\C1\88\B5\00\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [7 x i8] c"sendto\00"
define void @mainloop(i32 %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = alloca [4096 x i8]
%5 = alloca %struct.sockaddr_ll
%6 = alloca i32
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.sockaddr_ll* %5 to i8*
%10 = bitcast i32* %6 to i8*
store i32 4, i32* %6
%11 = bitcast %struct.sockaddr_ll* %5 to %struct.sockaddr*
%12 = call i32 @recvfrom(i32 %0, i8* %8, i32 4096, i32 0, %struct.sockaddr* %11, i32* %6)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 16
%19 = load i8, i8* %18
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 17
%21 = load i8, i8* %20
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 18
%23 = load i8, i8* %22
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 19
%25 = load i8, i8* %24
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 20
%27 = load i8, i8* %26
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 21
%29 = load i8, i8* %28
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 22
%31 = load i8, i8* %30
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 23
%33 = load i8, i8* %32
%34 = zext i8 %19 to i64
%35 = shl nuw i64 %34, 56
%36 = zext i8 %21 to i64
%37 = shl nuw nsw i64 %36, 48
%38 = or i64 %37, %35
%39 = zext i8 %23 to i64
%40 = shl nuw nsw i64 %39, 40
%41 = or i64 %38, %40
%42 = zext i8 %25 to i64
%43 = shl nuw nsw i64 %42, 32
%44 = or i64 %41, %43
%45 = zext i8 %27 to i64
%46 = shl nuw nsw i64 %45, 24
%47 = or i64 %44, %46
%48 = zext i8 %29 to i64
%49 = shl nuw nsw i64 %48, 16
%50 = zext i8 %31 to i64
%51 = shl nuw nsw i64 %50, 8
%52 = or i64 %47, %49
%53 = zext i8 %33 to i64
%54 = or i64 %52, %51
%55 = or i64 %54, %53
%56 = load i64, i64* @mainloop.t
%57 = sub nsw i64 %55, %56
%58 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i64 %57, i64 %55)
store i64 %55, i64* @mainloop.t
%59 = call i32 @memcpy(i8* %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 15)
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 15
%61 = call i32 @read(i32 0, i8* %60, i32 768)
%62 = icmp eq i32 %61, 768
br i1 %62, label %85, label %82
63: ; preds = %85
%64 = call i32 @read(i32 0, i8* %60, i32 768)
%65 = icmp eq i32 %64, 768
br i1 %65, label %66, label %82
66: ; preds = %63
%67 = call i32 @send(i32 %0, i8* %7, i32 783, i32 0)
%68 = icmp slt i32 %67, 0
br i1 %68, label %88, label %69
69: ; preds = %66
%70 = call i32 @read(i32 0, i8* %60, i32 768)
%71 = icmp eq i32 %70, 768
br i1 %71, label %72, label %82
72: ; preds = %69
%73 = call i32 @send(i32 %0, i8* %7, i32 783, i32 0)
%74 = icmp slt i32 %73, 0
br i1 %74, label %88, label %75
75: ; preds = %72
%76 = call i32 @read(i32 0, i8* %60, i32 768)
%77 = icmp eq i32 %76, 768
br i1 %77, label %78, label %82
78: ; preds = %75
%79 = call i32 @send(i32 %0, i8* %7, i32 783, i32 0)
%80 = icmp slt i32 %79, 0
br i1 %80, label %88, label %81
81: ; preds = %78
ret void
82: ; preds = %75, %69, %63, %17
%83 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%84 = call i32 @exit(i32 1)
unreachable
85: ; preds = %17
%86 = call i32 @send(i32 %0, i8* %7, i32 783, i32 0)
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %63
88: ; preds = %78, %72, %66, %85
%89 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
}