#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*/ socklen_t;

/* Variables and functions */
int SOL_SOCKET;
int SO_BINDTODEVICE;
int SO_MARK;
int next_setsockopt(int, int, int, void const *, int /*<<< orphan*/);
int /*<<< orphan*/ set_next_setsockopt();
int setsockopt(int sockfd, int level, int optname, const void *optval,
               socklen_t optlen) {
  set_next_setsockopt();
  if (level == SOL_SOCKET && (optname == SO_MARK || optname == SO_BINDTODEVICE))
    return 0;
  return next_setsockopt(sockfd, level, optname, optval, optlen);
}


x86 assembly (clang, -O0):
<setsockopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <set_next_setsockopt@plt>
mov    -0xc(%rbp),%eax
mov    0x2e9e(%rip),%rcx
cmp    (%rcx),%eax
jne    1182 <setsockopt+0x62>
mov    -0x10(%rbp),%eax
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%eax
je     1176 <setsockopt+0x56>
mov    -0x10(%rbp),%eax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%eax
jne    1182 <setsockopt+0x62>
movl   $0x0,-0x4(%rbp)
jmp    119b <setsockopt+0x7b>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   1030 <next_setsockopt@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setsockopt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r12d
xor    %eax,%eax
call   1040 <set_next_setsockopt@plt>
mov    0x2ea5(%rip),%rax
cmp    %ebx,(%rax)
jne    115d <setsockopt+0x3d>
mov    0x2e92(%rip),%rax
cmp    %ebp,(%rax)
je     1177 <setsockopt+0x57>
mov    0x2e77(%rip),%rax
cmp    %ebp,(%rax)
je     1177 <setsockopt+0x57>
mov    %r12d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r15,%rcx
mov    %r14d,%r8d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <next_setsockopt@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_MARK = global i32 0
@SO_BINDTODEVICE = global i32 0
define i32 @setsockopt(i32 %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%12 = call i32 (...) @set_next_setsockopt()
%13 = load i32, i32* %8
%14 = load i32, i32* @SOL_SOCKET
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %5
%17 = load i32, i32* %9
%18 = load i32, i32* @SO_MARK
%19 = icmp eq i32 %17, %18
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i32, i32* %9
%22 = load i32, i32* @SO_BINDTODEVICE
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20, %16
store i32 0, i32* %6
br label %32
25: ; preds = %20, %5
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = load i8*, i8** %10
%30 = load i32, i32* %11
%31 = call i32 @next_setsockopt(i32 %26, i32 %27, i32 %28, i8* %29, i32 %30)
store i32 %31, i32* %6
br label %32
32: ; preds = %25, %24
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_MARK = global i32 0
@SO_BINDTODEVICE = global i32 0
define i32 @setsockopt(i32 %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = tail call i32 (...) @set_next_setsockopt()
%7 = load i32, i32* @SOL_SOCKET
%8 = icmp eq i32 %7, %1
br i1 %8, label %9, label %15
9: ; preds = %5
%10 = load i32, i32* @SO_MARK
%11 = icmp eq i32 %10, %2
%12 = load i32, i32* @SO_BINDTODEVICE
%13 = icmp eq i32 %12, %2
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %17, label %15
15: ; preds = %9, %5
%16 = tail call i32 @next_setsockopt(i32 %0, i32 %1, i32 %2, i8* %3, i32 %4)
br label %17
17: ; preds = %9, %15
%18 = phi i32 [ %16, %15 ], [ 0, %9 ]
ret i32 %18
}