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

/* Variables and functions */
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
scalar_t__ get_bind_to_device(int, char *, int);
unsigned int get_priority(int);
unsigned int get_somark(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *, unsigned int, unsigned int);
int socket(int, int /*<<< orphan*/, int);
int show_sockopts(int family) {
  unsigned int mark, prio;
  char name[16];
  int sd;
  sd = socket(family, SOCK_DGRAM, 17);
  if (sd < 0) {
    perror("socket");
    return 1;
  }
  if (get_bind_to_device(sd, name, sizeof(name)) < 0)
    return 1;
  mark = get_somark(sd);
  prio = get_priority(sd);
  close(sd);
  printf("sd %d: dev %s, mark %u, priority %u\n", sd, name, mark, prio);
  return 0;
}


x86 assembly (clang, -O0):
<show_sockopts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    $0x11,%edx
call   1090 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11b6 <show_sockopts+0x46>
lea    0xe5b(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    121c <show_sockopts+0xac>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1040 <get_bind_to_device@plt>
cmp    $0x0,%rax
jge    11dd <show_sockopts+0x6d>
movl   $0x1,-0x4(%rbp)
jmp    121c <show_sockopts+0xac>
mov    -0x24(%rbp),%edi
call   1030 <get_somark@plt>
mov    %eax,-0xc(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <get_priority@plt>
mov    %eax,-0x10(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
mov    -0x24(%rbp),%esi
lea    -0x20(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xdf7(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_sockopts>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    $0x11,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     11da <show_sockopts+0x6a>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1040 <get_bind_to_device@plt>
test   %rax,%rax
js     11e6 <show_sockopts+0x76>
mov    %ebx,%edi
call   1030 <get_somark@plt>
mov    %eax,%r14d
mov    %ebx,%edi
call   1080 <get_priority@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe41(%rip),%rdi
mov    %rsp,%rdx
mov    %ebx,%esi
mov    %r14d,%ecx
mov    %ebp,%r8d
call   1050 <printf@plt>
xor    %eax,%eax
jmp    11eb <show_sockopts+0x7b>
lea    0xe1f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [37 x i8] c"sd %d: dev %s, mark %u, priority %u\0A\00"
define i32 @show_sockopts(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = load i32, i32* @SOCK_DGRAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 17)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %33
15: ; preds = %1
%16 = load i32, i32* %7
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%18 = call i64 @get_bind_to_device(i32 %16, i8* %17, i32 16)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %2
br label %33
21: ; preds = %15
%22 = load i32, i32* %7
%23 = call i32 @get_somark(i32 %22)
store i32 %23, i32* %4
%24 = load i32, i32* %7
%25 = call i32 @get_priority(i32 %24)
store i32 %25, i32* %5
%26 = load i32, i32* %7
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %7
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %28, i8* %29, i32 %30, i32 %31)
store i32 0, i32* %2
br label %33
33: ; preds = %21, %20, %13
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [37 x i8] c"sd %d: dev %s, mark %u, priority %u\0A\00"
define i32 @show_sockopts(i32 %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @SOCK_DGRAM
%5 = tail call i32 @socket(i32 %0, i32 %4, i32 17)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
9: ; preds = %1
%10 = call i64 @get_bind_to_device(i32 %5, i8* %3, i32 16)
%11 = icmp slt i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = call i32 @get_somark(i32 %5)
%14 = call i32 @get_priority(i32 %5)
%15 = call i32 @close(i32 %5)
%16 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %5, i8* %3, i32 %13, i32 %14)
br label %17
17: ; preds = %9, %12, %7
%18 = phi i32 [ 1, %7 ], [ 0, %12 ], [ 1, %9 ]
ret i32 %18
}