#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 /*<<< orphan*/ two;
struct sockaddr {
  int /*<<< orphan*/ sa_family;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ one;

/* Variables and functions */
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_IP;
int /*<<< orphan*/ SOL_SOCKET;
int SO_PEEK_OFF;
int bind(int, struct sockaddr *, int /*<<< orphan*/);
scalar_t__ close(int);
int /*<<< orphan*/ do_rx(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void do_main(struct sockaddr *addr, socklen_t alen) {
  int fd, ret, one = 1, two = 2;
  fd = socket(addr->sa_family, SOCK_DGRAM, 0);
  if (fd == -1)
    error(1, errno, "socket rx");
  ret = bind(fd, addr, alen);
  if (ret)
    error(1, errno, "bind rx");
  if (setsockopt(fd, SOL_IP, 23, &one, sizeof(one)))
    error(1, errno, "setsockopt csum");
  if (setsockopt(fd, SOL_SOCKET, SO_PEEK_OFF, &two, sizeof(two)))
    error(1, errno, "setsockopt peek_off");
  do_rx(fd, true);
  do_rx(fd, false);
  if (close(fd))
    error(1, errno, "close");
}


x86 assembly (clang, -O0):
<do_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11ba <do_main+0x5a>
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe4b(%rip),%rdx
call   1070 <error@plt>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11f0 <do_main+0x90>
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe1f(%rip),%rdx
call   1070 <error@plt>
mov    -0x10(%rbp),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    $0x17,%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     1234 <do_main+0xd4>
mov    0x2da7(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xde3(%rip),%rdx
call   1070 <error@plt>
mov    -0x10(%rbp),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
mov    0x2d71(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     127c <do_main+0x11c>
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xdab(%rip),%rdx
call   1070 <error@plt>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1040 <do_rx@plt>
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1040 <do_rx@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     12bf <do_main+0x15f>
mov    0x2d1c(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xd7c(%rip),%rdx
call   1070 <error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
movl   $0x1,0xc(%rsp)
movl   $0x2,0x8(%rsp)
mov    (%rdi),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11b1 <do_main+0x51>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    0xe59(%rip),%rdx
mov    $0x1,%edi
call   1070 <error@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1060 <bind@plt>
test   %eax,%eax
je     11dc <do_main+0x7c>
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    0xe38(%rip),%rdx
mov    $0x1,%edi
call   1070 <error@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x17,%edx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
je     121b <do_main+0xbb>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
lea    0xe01(%rip),%rdx
mov    $0x1,%edi
call   1070 <error@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
mov    0x2d8d(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
je     125e <do_main+0xfe>
mov    0x2d7d(%rip),%rax
mov    (%rax),%esi
lea    0xdce(%rip),%rdx
mov    $0x1,%edi
call   1070 <error@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1040 <do_rx@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <do_rx@plt>
mov    %ebx,%edi
call   1050 <close@plt>
test   %rax,%rax
je     1299 <do_main+0x139>
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
lea    0xda7(%rip),%rdx
mov    $0x1,%edi
call   1070 <error@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@SOCK_DGRAM = global i32 0
@errno = global i32 0
@.str = [10 x i8] c"socket rx\00"
@.str.1 = [8 x i8] c"bind rx\00"
@SOL_IP = global i32 0
@.str.2 = [16 x i8] c"setsockopt csum\00"
@SOL_SOCKET = global i32 0
@SO_PEEK_OFF = global i32 0
@.str.3 = [20 x i8] c"setsockopt peek_off\00"
@.str.4 = [6 x i8] c"close\00"
define void @do_main(%struct.sockaddr* %0, i32 %1) {
%3 = alloca %struct.sockaddr*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %3
store i32 %1, i32* %4
store i32 1, i32* %7
store i32 2, i32* %8
%9 = load %struct.sockaddr*, %struct.sockaddr** %3
%10 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @SOCK_DGRAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @errno
%18 = call i32 @error(i32 1, i32 %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %2
%20 = load i32, i32* %5
%21 = load %struct.sockaddr*, %struct.sockaddr** %3
%22 = load i32, i32* %4
%23 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load i32, i32* @errno
%28 = call i32 @error(i32 1, i32 %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %26, %19
%30 = load i32, i32* %5
%31 = load i32, i32* @SOL_IP
%32 = call i64 @setsockopt(i32 %30, i32 %31, i32 23, i32* %7, i32 4)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* @errno
%36 = call i32 @error(i32 1, i32 %35, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %34, %29
%38 = load i32, i32* %5
%39 = load i32, i32* @SOL_SOCKET
%40 = load i32, i32* @SO_PEEK_OFF
%41 = call i64 @setsockopt(i32 %38, i32 %39, i32 %40, i32* %8, i32 4)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %37
%44 = load i32, i32* @errno
%45 = call i32 @error(i32 1, i32 %44, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %43, %37
%47 = load i32, i32* %5
%48 = call i32 @do_rx(i32 %47, i32 1)
%49 = load i32, i32* %5
%50 = call i32 @do_rx(i32 %49, i32 0)
%51 = load i32, i32* %5
%52 = call i64 @close(i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %46
%55 = load i32, i32* @errno
%56 = call i32 @error(i32 1, i32 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %54, %46
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@SOCK_DGRAM = global i32 0
@errno = global i32 0
@.str = [10 x i8] c"socket rx\00"
@.str.1 = [8 x i8] c"bind rx\00"
@SOL_IP = global i32 0
@.str.2 = [16 x i8] c"setsockopt csum\00"
@SOL_SOCKET = global i32 0
@SO_PEEK_OFF = global i32 0
@.str.3 = [20 x i8] c"setsockopt peek_off\00"
@.str.4 = [6 x i8] c"close\00"
define void @do_main(%struct.sockaddr* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 2, i32* %4
%7 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @errno
%14 = tail call i32 @error(i32 1, i32 %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %2
%16 = tail call i32 @bind(i32 %10, %struct.sockaddr* %0, i32 %1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* @errno
%20 = tail call i32 @error(i32 1, i32 %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %18, %15
%22 = load i32, i32* @SOL_IP
%23 = call i64 @setsockopt(i32 %10, i32 %22, i32 23, i32* %3, i32 4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i32, i32* @errno
%27 = call i32 @error(i32 1, i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %25, %21
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_PEEK_OFF
%31 = call i64 @setsockopt(i32 %10, i32 %29, i32 %30, i32* %4, i32 4)
%32 = icmp eq i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = load i32, i32* @errno
%35 = call i32 @error(i32 1, i32 %34, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %33, %28
%37 = call i32 @do_rx(i32 %10, i32 1)
%38 = call i32 @do_rx(i32 %10, i32 0)
%39 = call i64 @close(i32 %10)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %36
%42 = load i32, i32* @errno
%43 = call i32 @error(i32 1, i32 %42, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %41, %36
ret void
}