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

/* Variables and functions */
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_PRIORITY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ log_message(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int if_setsockopt_priority(int *sd) {
  int ret;
  int priority = 6;
  if (*sd < 0)
    return -1;
  ret = setsockopt(*sd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
  if (ret < 0) {
    log_message(LOG_INFO, "cant set SO_PRIORITY IP option. errno=%d (%m)",
                errno);
    close(*sd);
    *sd = -1;
  }
  return *sd;
}


x86 assembly (clang, -O0):
<if_setsockopt_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x6,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jge    115c <if_setsockopt_priority+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <if_setsockopt_priority+0x9c>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c3 <if_setsockopt_priority+0x93>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
lea    0xe57(%rip),%rsi
call   1050 <log_message@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<if_setsockopt_priority>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
movl   $0x6,0x4(%rsp)
mov    (%rdi),%edi
mov    $0xffffffff,%ebp
test   %edi,%edi
js     119e <if_setsockopt_priority+0x6e>
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
js     1173 <if_setsockopt_priority+0x43>
mov    (%rbx),%ebp
jmp    119e <if_setsockopt_priority+0x6e>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
lea    0xe74(%rip),%rsi
call   1050 <log_message@plt>
mov    (%rbx),%edi
call   1040 <close@plt>
movl   $0xffffffff,(%rbx)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_PRIORITY = global i32 0
@LOG_INFO = global i32 0
@.str = [46 x i8] c"cant set SO_PRIORITY IP option. errno=%d (%m)\00"
@errno = global i32 0
define i32 @if_setsockopt_priority(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 6, i32* %5
%6 = load i32*, i32** %3
%7 = load i32, i32* %6
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %29
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = load i32, i32* @SOL_SOCKET
%14 = load i32, i32* @SO_PRIORITY
%15 = call i32 @setsockopt(i32 %12, i32 %13, i32 %14, i32* %5, i32 4)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %10
%19 = load i32, i32* @LOG_INFO
%20 = load i32, i32* @errno
%21 = call i32 @log_message(i32 %19, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32*, i32** %3
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = load i32*, i32** %3
store i32 -1, i32* %25
br label %26
26: ; preds = %18, %10
%27 = load i32*, i32** %3
%28 = load i32, i32* %27
store i32 %28, i32* %2
br label %29
29: ; preds = %26, %9
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_PRIORITY = global i32 0
@LOG_INFO = global i32 0
@.str = [46 x i8] c"cant set SO_PRIORITY IP option. errno=%d (%m)\00"
@errno = global i32 0
define i32 @if_setsockopt_priority(i32* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 6, i32* %2
%4 = load i32, i32* %0
%5 = icmp slt i32 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %1
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_PRIORITY
%9 = call i32 @setsockopt(i32 %4, i32 %7, i32 %8, i32* %2, i32 4)
%10 = icmp slt i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = load i32, i32* %0
br label %19
13: ; preds = %6
%14 = load i32, i32* @LOG_INFO
%15 = load i32, i32* @errno
%16 = call i32 @log_message(i32 %14, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %0
%18 = call i32 @close(i32 %17)
store i32 -1, i32* %0
br label %19
19: ; preds = %13, %11, %1
%20 = phi i32 [ -1, %1 ], [ %12, %11 ], [ -1, %13 ]
ret i32 %20
}