#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 */
struct ifreq {
  int ifr_ifindex;
};
typedef int /*<<< orphan*/ ifr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SIOCGIFNAME;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SudirribeInterface(int, int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ memset(struct ifreq *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void Sudirribe(int dl_sock) {
  int ip_sock;
  struct ifreq ifr;
  if ((ip_sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    fprintf(stderr, "lwmaster: unable to open sudirription socket [%s]\n",
            strerror(errno));
    exit(1);
  }
  memset(&ifr, 0, sizeof(ifr));
  ifr.ifr_ifindex = 1;
  while (ioctl(ip_sock, SIOCGIFNAME, &ifr) == 0) {
    SudirribeInterface(dl_sock, ip_sock, ifr.ifr_ifindex);
    ifr.ifr_ifindex++;
  }
}


x86 assembly (clang, -O0):
<Sudirribe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11d6 <Sudirribe+0x66>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe39(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jne    1228 <Sudirribe+0xb8>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <SudirribeInterface@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ed <Sudirribe+0x7d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Sudirribe>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     11fd <Sudirribe+0x8d>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movl   $0x1,(%rsp)
mov    0x2e18(%rip),%r15
mov    (%r15),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
jne    11f2 <Sudirribe+0x82>
mov    %rsp,%r14
nopl   (%rax)
mov    (%rsp),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1070 <SudirribeInterface@plt>
addl   $0x1,(%rsp)
mov    (%r15),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
je     11d0 <Sudirribe+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc4(%rip),%rax
mov    (%rax),%ebx
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xde5(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.ifreq = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [51 x i8] c"lwmaster: unable to open sudirription socket [%s]\0A\00"
@errno = global i32 0
@SIOCGIFNAME = global i32 0
define void @Sudirribe(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.ifreq
store i32 %0, i32* %2
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = call i32 @memset(%struct.ifreq* %4, i32 0, i32 4)
%17 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
store i32 1, i32* %17
br label %18
18: ; preds = %23, %15
%19 = load i32, i32* %3
%20 = load i32, i32* @SIOCGIFNAME
%21 = call i64 @ioctl(i32 %19, i32 %20, %struct.ifreq* %4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %18
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @SudirribeInterface(i32 %24, i32 %25, i32 %27)
%29 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i32 0, i32 0
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %29
br label %18
32: ; preds = %18
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str = [51 x i8] c"lwmaster: unable to open sudirription socket [%s]\0A\00"
@errno = global i32 0
@SIOCGIFNAME = global i32 0
define void @Sudirribe(i32 %0) {
%2 = alloca %struct.ifreq
%3 = bitcast %struct.ifreq* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = call i32 @memset(%struct.ifreq* %2, i32 0, i32 4)
%16 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %2, i64 0, i32 0
store i32 1, i32* %16
%17 = load i32, i32* @SIOCGIFNAME
%18 = call i64 @ioctl(i32 %6, i32 %17, %struct.ifreq* %2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %14, %20
%21 = load i32, i32* %16
%22 = call i32 @SudirribeInterface(i32 %0, i32 %6, i32 %21)
%23 = load i32, i32* %16
%24 = add nsw i32 %23, 1
store i32 %24, i32* %16
%25 = load i32, i32* @SIOCGIFNAME
%26 = call i64 @ioctl(i32 %6, i32 %25, %struct.ifreq* %2)
%27 = icmp eq i64 %26, 0
br i1 %27, label %20, label %28
28: ; preds = %20, %14
ret void
}