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

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_PRIORITY;
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, unsigned int *,
               int *);
int /*<<< orphan*/ perror(char *);
unsigned int get_priority(int sd) {
  unsigned int prio = 0;
  socklen_t optlen = sizeof(prio);
  int rc;
  rc = getsockopt(sd, SOL_SOCKET, SO_PRIORITY, &prio, &optlen);
  if (rc < 0)
    perror("getsockopt(SO_PRIORITY)");
  return prio;
}


x86 assembly (clang, -O0):
<get_priority>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    0x2ea4(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
lea    -0xc(%rbp),%r8
call   1030 <getsockopt@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1174 <get_priority+0x54>
lea    0xe91(%rip),%rdi
call   1040 <perror@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_priority>:
push   %rax
movl   $0x0,(%rsp)
movl   $0x4,0x4(%rsp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
mov    0x2eb0(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
lea    0x4(%rsp),%r8
call   1030 <getsockopt@plt>
test   %eax,%eax
js     1158 <get_priority+0x38>
mov    (%rsp),%eax
pop    %rcx
ret
lea    0xea1(%rip),%rdi
call   1040 <perror@plt>
jmp    1153 <get_priority+0x33>

LLVM IR (-O0):
@SOL_SOCKET = global i32 0
@SO_PRIORITY = global i32 0
@.str = [24 x i8] c"getsockopt(SO_PRIORITY)\00"
define i32 @get_priority(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 4, i32* %4
%6 = load i32, i32* %2
%7 = load i32, i32* @SOL_SOCKET
%8 = load i32, i32* @SO_PRIORITY
%9 = call i32 @getsockopt(i32 %6, i32 %7, i32 %8, i32* %3, i32* %4)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load i32, i32* %3
ret i32 %15
}

LLVM IR (-O2):
@SOL_SOCKET = global i32 0
@SO_PRIORITY = global i32 0
@.str = [24 x i8] c"getsockopt(SO_PRIORITY)\00"
define i32 @get_priority(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = load i32, i32* @SOL_SOCKET
%7 = load i32, i32* @SO_PRIORITY
%8 = call i32 @getsockopt(i32 %0, i32 %6, i32 %7, i32* %2, i32* %3)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = load i32, i32* %2
ret i32 %13
}