#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*/ sopriocheck;
typedef int /*<<< orphan*/ soprio;
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_PRIORITY;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int *);
int /*<<< orphan*/ perror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ stderr;
int set_socket_priority(int sockfd, int soprio) {
  int sopriocheck = 0;
  socklen_t sopriolen;
  if (soprio == 0)
    return 0;
  if (setsockopt(sockfd, SOL_SOCKET, SO_PRIORITY, &soprio, sizeof(soprio)) !=
      0) {
    perror("WARN: setting SO_PRIORITY failed");
    return 0;
  }
  sopriolen = sizeof(sopriocheck);
  getsockopt(sockfd, SOL_SOCKET, SO_PRIORITY, &sopriocheck, &sopriolen);
  if (soprio != sopriocheck) {
    fprintf(stderr, "warning: socket prio failed: %d != %d\n", soprio,
            sopriocheck);
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_socket_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116b <set_socket_priority+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    1214 <set_socket_priority+0xd4>
mov    -0x8(%rbp),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     11b1 <set_socket_priority+0x71>
lea    0xe60(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1214 <set_socket_priority+0xd4>
movl   $0x4,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <getsockopt@plt>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     120d <set_socket_priority+0xcd>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe25(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1214 <set_socket_priority+0xd4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_socket_priority>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,0x8(%rsp)
movl   $0x0,0x4(%rsp)
test   %esi,%esi
je     11c4 <set_socket_priority+0x84>
mov    %edi,%ebx
mov    0x2e7e(%rip),%r14
mov    (%r14),%esi
mov    0x2e84(%rip),%r15
mov    (%r15),%edx
lea    0x8(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jne    11d0 <set_socket_priority+0x90>
movl   $0x4,0xc(%rsp)
mov    (%r14),%esi
mov    (%r15),%edx
lea    0x4(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %ebx,%edi
call   1040 <getsockopt@plt>
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
cmp    %ecx,%edx
je     11c4 <set_socket_priority+0x84>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe29(%rip),%rdi
call   1060 <perror@plt>
jmp    11c4 <set_socket_priority+0x84>

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_PRIORITY = global i32 0
@.str = [33 x i8] c"WARN: setting SO_PRIORITY failed\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"warning: socket prio failed: %d != %d\0A\00"
define i32 @set_socket_priority(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %6
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 0, i32* %3
br label %33
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i32, i32* @SOL_SOCKET
%14 = load i32, i32* @SO_PRIORITY
%15 = call i64 @setsockopt(i32 %12, i32 %13, i32 %14, i32* %5, i32 4)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %33
19: ; preds = %11
store i32 4, i32* %7
%20 = load i32, i32* %4
%21 = load i32, i32* @SOL_SOCKET
%22 = load i32, i32* @SO_PRIORITY
%23 = call i32 @getsockopt(i32 %20, i32 %21, i32 %22, i32* %6, i32* %7)
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %32
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %30)
store i32 0, i32* %3
br label %33
32: ; preds = %19
store i32 0, i32* %3
br label %33
33: ; preds = %32, %27, %17, %10
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_PRIORITY = global i32 0
@.str = [33 x i8] c"WARN: setting SO_PRIORITY failed\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"warning: socket prio failed: %d != %d\0A\00"
define i32 @set_socket_priority(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %1, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = bitcast i32* %5 to i8*
%8 = icmp eq i32 %1, 0
br i1 %8, label %26, label %9
9: ; preds = %2
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32, i32* @SO_PRIORITY
%12 = call i64 @setsockopt(i32 %0, i32 %10, i32 %11, i32* %3, i32 4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %26
16: ; preds = %9
store i32 4, i32* %5
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_PRIORITY
%19 = call i32 @getsockopt(i32 %0, i32 %17, i32 %18, i32* %4, i32* %5)
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = icmp eq i32 %20, %21
br i1 %22, label %26, label %23
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21)
br label %26
26: ; preds = %16, %2, %23, %14
ret i32 0
}