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

/* Variables and functions */
int /*<<< orphan*/ FIONREAD;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
int synchnet(int peer) {
  int i, j = 0;
  char rbuf[(65464 + 4)];
  struct sockaddr_storage from;
  socklen_t fromlen;
  while (1) {
    (void)ioctl(peer, FIONREAD, &i);
    if (i) {
      j++;
      fromlen = sizeof from;
      (void)recvfrom(peer, rbuf, sizeof(rbuf), 0, (struct sockaddr *)&from,
                     &fromlen);
    } else {
      return (j);
    }
  }
}


x86 assembly (clang, -O0):
<synchnet>:
push   %rbp
mov    %rsp,%rbp
sub    $0xffe0,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
cmpl   $0x0,-0x8(%rbp)
je     1190 <synchnet+0x70>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x4,-0xffdc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xffd0(%rbp),%rsi
lea    -0xffd8(%rbp),%r8
mov    $0xffbc,%edx
xor    %ecx,%ecx
lea    -0xffdc(%rbp),%r9
call   1040 <recvfrom@plt>
jmp    119c <synchnet+0x7c>
mov    -0xc(%rbp),%eax
add    $0xffe0,%rsp
pop    %rbp
ret
jmp    1135 <synchnet+0x15>

x86 assembly (clang, -O2):
<synchnet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xffd8,%rsp
mov    %edi,%ebx
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
cmpl   $0x0,(%rsp)
je     119d <synchnet+0x7d>
xor    %ebp,%ebp
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x4(%rsp),%r12
mov    %rsp,%r13
xchg   %ax,%ax
add    $0x1,%ebp
movl   $0x4,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xffbc,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1040 <recvfrom@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r13,%rdx
call   1030 <ioctl@plt>
cmpl   $0x0,(%rsp)
jne    1160 <synchnet+0x40>
jmp    119f <synchnet+0x7f>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0xffd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@FIONREAD = global i32 0
define i32 @synchnet(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [65468 x i8]
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %8
8: ; preds = %1, %23
%9 = load i32, i32* %2
%10 = load i32, i32* @FIONREAD
%11 = call i32 @ioctl(i32 %9, i32 %10, i32* %3)
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %8
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
store i32 4, i32* %7
%17 = load i32, i32* %2
%18 = getelementptr inbounds [65468 x i8], [65468 x i8]* %5, i64 0, i64 0
%19 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%20 = call i32 @recvfrom(i32 %17, i8* %18, i32 65468, i32 0, %struct.sockaddr* %19, i32* %7)
br label %23
21: ; preds = %8
%22 = load i32, i32* %4
ret i32 %22
23: ; preds = %14
br label %8
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@FIONREAD = global i32 0
define i32 @synchnet(i32 %0) {
%2 = alloca i32
%3 = alloca [65468 x i8]
%4 = alloca %struct.sockaddr_storage
%5 = alloca i32
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds [65468 x i8], [65468 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.sockaddr_storage* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = load i32, i32* @FIONREAD
%11 = call i32 @ioctl(i32 %0, i32 %10, i32* %2)
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %1
%15 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr*
br label %16
16: ; preds = %14, %16
%17 = phi i32 [ 0, %14 ], [ %18, %16 ]
%18 = add nuw nsw i32 %17, 1
store i32 4, i32* %5
%19 = call i32 @recvfrom(i32 %0, i8* %7, i32 65468, i32 0, %struct.sockaddr* %15, i32* %5)
%20 = load i32, i32* @FIONREAD
%21 = call i32 @ioctl(i32 %0, i32 %20, i32* %2)
%22 = load i32, i32* %2
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %16
24: ; preds = %16, %1
%25 = phi i32 [ 0, %1 ], [ %18, %16 ]
ret i32 %25
}