#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 ether_header {
  int dummy;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_ethernet_header(struct ether_header *, char const *);
int read(int, char *, int);
int monitor_once(int iffd, const char ifname[]) {
  static char buffer[65535];
  int size = read(iffd, buffer, sizeof(buffer));
  if (size <= 0)
    perror("read");
  else
    print_ethernet_header((struct ether_header *)buffer, ifname);
  return size;
}


x86 assembly (clang, -O0):
<monitor_once>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    0x2f07(%rip),%rsi
mov    $0xffff,%edx
call   1030 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1171 <monitor_once+0x41>
lea    0xe99(%rip),%rdi
call   1050 <perror@plt>
jmp    1181 <monitor_once+0x51>
mov    -0x10(%rbp),%rsi
lea    0x2ed4(%rip),%rdi
call   1040 <print_ethernet_header@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monitor_once>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0x2f12(%rip),%rsi
mov    $0xffff,%edx
call   1030 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1167 <monitor_once+0x37>
lea    0x2efb(%rip),%rdi
mov    %r14,%rsi
call   1040 <print_ethernet_header@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe92(%rip),%rdi
call   1050 <perror@plt>
jmp    115d <monitor_once+0x2d>

LLVM IR (-O0):
%struct.ether_header = type { i32 }
@monitor_once.buffer = internal global [65535 x i8] zeroinitializer
@.str = [5 x i8] c"read\00"
define i32 @monitor_once(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = call i32 @read(i32 %6, i8* getelementptr inbounds ([65535 x i8], [65535 x i8]* @monitor_once.buffer, i64 0, i64 0), i32 65535)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sle i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @print_ethernet_header(%struct.ether_header* bitcast ([65535 x i8]* @monitor_once.buffer to %struct.ether_header*), i8* %13)
br label %15
15: ; preds = %12, %10
%16 = load i32, i32* %5
ret i32 %16
}

LLVM IR (-O2):
%struct.ether_header = type { i32 }
@monitor_once.buffer = internal global [65535 x i8] zeroinitializer
@.str = [5 x i8] c"read\00"
define i32 @monitor_once(i32 %0, i8* %1) {
%3 = tail call i32 @read(i32 %0, i8* getelementptr inbounds ([65535 x i8], [65535 x i8]* @monitor_once.buffer, i64 0, i64 0), i32 65535)
%4 = icmp slt i32 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %9
7: ; preds = %2
%8 = tail call i32 @print_ethernet_header(%struct.ether_header* bitcast ([65535 x i8]* @monitor_once.buffer to %struct.ether_header*), i8* %1)
br label %9
9: ; preds = %7, %5
ret i32 %3
}