#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 ip_mreq {
  int /*<<< orphan*/ imr_interface;
  int /*<<< orphan*/ imr_multiaddr;
};
typedef int /*<<< orphan*/ imr;

/* Variables and functions */
scalar_t__ EADDRNOTAVAIL;
int /*<<< orphan*/ IPPROTO_IP;
int /*<<< orphan*/ IP_DROP_MEMBERSHIP;
int /*<<< orphan*/ err(int, char *, char const *, char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, struct ip_mreq *,
               int);
int /*<<< orphan*/ strlcpy(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ warnx(char *, char const *, char *, int /*<<< orphan*/);
void test_drop_multi(int sock, const char *socktype, struct ip_mreq imr,
                     int flags) {
  char buf[128];
  int ret;
  ret = setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, &imr, sizeof(imr));
  if (ret < 0) {
    strlcpy(buf, inet_ntoa(imr.imr_multiaddr), 128);
    err(-1,
        "FAIL: setsockopt(%s, IPPROTO_IP, IP_DROP_MEMBERSHIP "
        "%s, %s)",
        socktype, buf, inet_ntoa(imr.imr_interface));
  }
  if (ret == 0 && (flags & 0x00000000)) {
    strlcpy(buf, inet_ntoa(imr.imr_multiaddr), 128);
    warnx("WARN: setsockopt(%s, IPPROTO_IP, IP_DROP_MEMBERSHIP "
          "%s, %s) returned 0",
          socktype, buf, inet_ntoa(imr.imr_interface));
  }
  ret = setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, &imr, sizeof(imr));
  if (ret == 0) {
    strlcpy(buf, inet_ntoa(imr.imr_multiaddr), 128);
    err(-1,
        "FAIL: setsockopt(%s, IPPROTO_IP, IP_DROP_MEMBERSHIP "
        "%s, %s) returned 0",
        socktype, buf, inet_ntoa(imr.imr_interface));
  }
  if (ret < 0 && errno != EADDRNOTAVAIL) {
    strlcpy(buf, inet_ntoa(imr.imr_multiaddr), 128);
    err(-1,
        "FAIL: setsockopt(%s, IPPROTO_IP, IP_DROP_MEMBERSHIP "
        "%s, %s)",
        socktype, buf, inet_ntoa(imr.imr_interface));
  }
}


x86 assembly (clang, -O0):
<test_drop_multi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdx,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jge    120c <test_drop_multi+0xbc>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0xc0(%rbp),%rdi
mov    %eax,%esi
mov    $0x80,%edx
call   1070 <strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0xb8(%rbp),%rdx
mov    -0xb0(%rbp),%rcx
mov    %eax,%r8d
mov    $0xffffffff,%edi
lea    0xdf9(%rip),%rsi
call   1060 <err@plt>
cmpl   $0x0,-0xa4(%rbp)
jne    128e <test_drop_multi+0x13e>
mov    -0x1c(%rbp),%eax
and    $0x0,%eax
cmp    $0x0,%eax
je     128e <test_drop_multi+0x13e>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0xd8(%rbp),%rdi
mov    %eax,%esi
mov    $0x80,%edx
call   1070 <strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0xd0(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0xd0(%rbp),%rsi
mov    -0xc8(%rbp),%rdx
mov    %eax,%ecx
lea    0xdb3(%rip),%rdi
call   1050 <warnx@plt>
mov    -0xc(%rbp),%edi
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
mov    0x2d27(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jne    1331 <test_drop_multi+0x1e1>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0xf0(%rbp),%rdi
mov    %eax,%esi
mov    $0x80,%edx
call   1070 <strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0xe8(%rbp),%rdx
mov    -0xe0(%rbp),%rcx
mov    %eax,%r8d
mov    $0xffffffff,%edi
lea    0xd57(%rip),%rsi
call   1060 <err@plt>
cmpl   $0x0,-0xa4(%rbp)
jge    13c4 <test_drop_multi+0x274>
mov    0x2c8b(%rip),%rax
mov    (%rax),%rax
mov    0x2c99(%rip),%rcx
cmp    (%rcx),%rax
je     13c4 <test_drop_multi+0x274>
lea    -0xa0(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x108(%rbp),%rdi
mov    %eax,%esi
mov    $0x80,%edx
call   1070 <strlcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x100(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x100(%rbp),%rdx
mov    -0xf8(%rbp),%rcx
mov    %eax,%r8d
mov    $0xffffffff,%edi
lea    0xc41(%rip),%rsi
call   1060 <err@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_drop_multi>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
mov    %rdx,0x8(%rsp)
mov    0x2e80(%rip),%r12
mov    (%r12),%esi
mov    0x2e5d(%rip),%rbx
mov    (%rbx),%edx
lea    0x8(%rsp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
jns    11c1 <test_drop_multi+0x81>
mov    0xc(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x80,%edx
call   1060 <strlcpy@plt>
mov    0x8(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xe52(%rip),%rsi
mov    $0xffffffff,%edi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %eax,%r8d
call   1050 <err@plt>
mov    (%r12),%esi
mov    (%rbx),%edx
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
je     11fe <test_drop_multi+0xbe>
jns    1241 <test_drop_multi+0x101>
mov    0x2dea(%rip),%rax
mov    (%rax),%rax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%rax
je     1241 <test_drop_multi+0x101>
lea    0xe04(%rip),%rbp
jmp    1205 <test_drop_multi+0xc5>
lea    0xe37(%rip),%rbp
mov    0xc(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x80,%edx
call   1060 <strlcpy@plt>
mov    0x8(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    $0xffffffff,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
call   1050 <err@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ip_mreq = type { i32, i32 }
@IPPROTO_IP = global i32 0
@IP_DROP_MEMBERSHIP = global i32 0
@.str = [60 x i8] c"FAIL: setsockopt(%s, IPPROTO_IP, IP_DROP_MEMBERSHIP %s, %s)\00"
@.str.1 = [71 x i8] c"WARN: setsockopt(%s, IPPROTO_IP, IP_DROP_MEMBERSHIP %s, %s) returned 0\00"
@.str.2 = [71 x i8] c"FAIL: setsockopt(%s, IPPROTO_IP, IP_DROP_MEMBERSHIP %s, %s) returned 0\00"
@errno = global i64 0
@EADDRNOTAVAIL = global i64 0
define void @test_drop_multi(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca %struct.ip_mreq
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [128 x i8]
%10 = alloca i32
%11 = bitcast %struct.ip_mreq* %5 to i64*
store i64 %2, i64* %11
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %3, i32* %8
%12 = load i32, i32* %6
%13 = load i32, i32* @IPPROTO_IP
%14 = load i32, i32* @IP_DROP_MEMBERSHIP
%15 = call i32 @setsockopt(i32 %12, i32 %13, i32 %14, %struct.ip_mreq* %5, i32 8)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %4
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%20 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i32 @inet_ntoa(i32 %21)
%23 = call i32 @strlcpy(i8* %19, i32 %22, i32 128)
%24 = load i8*, i8** %7
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%26 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @inet_ntoa(i32 %27)
%29 = call i32 @err(i32 -1, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %24, i8* %25, i32 %28)
br label %30
30: ; preds = %18, %4
%31 = load i32, i32* %10
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %49
33: ; preds = %30
%34 = load i32, i32* %8
%35 = and i32 %34, 0
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%39 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i32 0, i32 1
%40 = load i32, i32* %39
%41 = call i32 @inet_ntoa(i32 %40)
%42 = call i32 @strlcpy(i8* %38, i32 %41, i32 128)
%43 = load i8*, i8** %7
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%45 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @inet_ntoa(i32 %46)
%48 = call i32 @warnx(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0), i8* %43, i8* %44, i32 %47)
br label %49
49: ; preds = %37, %33, %30
%50 = load i32, i32* %6
%51 = load i32, i32* @IPPROTO_IP
%52 = load i32, i32* @IP_DROP_MEMBERSHIP
%53 = call i32 @setsockopt(i32 %50, i32 %51, i32 %52, %struct.ip_mreq* %5, i32 8)
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %68
56: ; preds = %49
%57 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%58 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i32 0, i32 1
%59 = load i32, i32* %58
%60 = call i32 @inet_ntoa(i32 %59)
%61 = call i32 @strlcpy(i8* %57, i32 %60, i32 128)
%62 = load i8*, i8** %7
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%64 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i32 0, i32 0
%65 = load i32, i32* %64
%66 = call i32 @inet_ntoa(i32 %65)
%67 = call i32 @err(i32 -1, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0), i8* %62, i8* %63, i32 %66)
br label %68
68: ; preds = %56, %49
%69 = load i32, i32* %10
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %87
71: ; preds = %68
%72 = load i64, i64* @errno
%73 = load i64, i64* @EADDRNOTAVAIL
%74 = icmp ne i64 %72, %73
br i1 %74, label %75, label %87
75: ; preds = %71
%76 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%77 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i32 0, i32 1
%78 = load i32, i32* %77
%79 = call i32 @inet_ntoa(i32 %78)
%80 = call i32 @strlcpy(i8* %76, i32 %79, i32 128)
%81 = load i8*, i8** %7
%82 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%83 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %5, i32 0, i32 0
%84 = load i32, i32* %83
%85 = call i32 @inet_ntoa(i32 %84)
%86 = call i32 @err(i32 -1, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %81, i8* %82, i32 %85)
br label %87
87: ; preds = %75, %71, %68
ret void
}

LLVM IR (-O2):
%struct.ip_mreq = type { i32, i32 }
@IPPROTO_IP = global i32 0
@IP_DROP_MEMBERSHIP = global i32 0
@.str = [60 x i8] c"FAIL: setsockopt(%s, IPPROTO_IP, IP_DROP_MEMBERSHIP %s, %s)\00"
@.str.2 = [71 x i8] c"FAIL: setsockopt(%s, IPPROTO_IP, IP_DROP_MEMBERSHIP %s, %s) returned 0\00"
@errno = global i64 0
@EADDRNOTAVAIL = global i64 0
define void @test_drop_multi(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to %struct.ip_mreq*
%7 = alloca [128 x i8]
store i64 %2, i64* %5
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* @IPPROTO_IP
%10 = load i32, i32* @IP_DROP_MEMBERSHIP
%11 = call i32 @setsockopt(i32 %0, i32 %9, i32 %10, %struct.ip_mreq* %6, i32 8)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %4
%14 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %6, i64 0, i32 1
%15 = load i32, i32* %14
%16 = call i32 @inet_ntoa(i32 %15)
%17 = call i32 @strlcpy(i8* %8, i32 %16, i32 128)
%18 = bitcast i64* %5 to i32*
%19 = load i32, i32* %18
%20 = call i32 @inet_ntoa(i32 %19)
%21 = call i32 @err(i32 -1, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %8, i32 %20)
br label %22
22: ; preds = %13, %4
%23 = load i32, i32* @IPPROTO_IP
%24 = load i32, i32* @IP_DROP_MEMBERSHIP
%25 = call i32 @setsockopt(i32 %0, i32 %23, i32 %24, %struct.ip_mreq* %6, i32 8)
%26 = icmp eq i32 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %22
%28 = icmp slt i32 %25, 0
br i1 %28, label %29, label %43
29: ; preds = %27
%30 = load i64, i64* @errno
%31 = load i64, i64* @EADDRNOTAVAIL
%32 = icmp eq i64 %30, %31
br i1 %32, label %43, label %33
33: ; preds = %29, %22
%34 = phi i8* [ getelementptr inbounds ([71 x i8], [71 x i8]* @.str.2, i64 0, i64 0), %22 ], [ getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), %29 ]
%35 = getelementptr inbounds %struct.ip_mreq, %struct.ip_mreq* %6, i64 0, i32 1
%36 = load i32, i32* %35
%37 = call i32 @inet_ntoa(i32 %36)
%38 = call i32 @strlcpy(i8* %8, i32 %37, i32 128)
%39 = bitcast i64* %5 to i32*
%40 = load i32, i32* %39
%41 = call i32 @inet_ntoa(i32 %40)
%42 = call i32 @err(i32 -1, i8* %34, i8* %1, i8* %8, i32 %41)
br label %43
43: ; preds = %33, %29, %27
ret void
}