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

/* Variables and functions */
int PACKET_FANOUT_CPU;
int PACKET_FANOUT_FLAG_DEFRAG;
int PACKET_FANOUT_FLAG_ROLLOVER;
int PACKET_FANOUT_HASH;
scalar_t__ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int sock_fanout_open(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void test_control_group(void) {
  int fds[2];
  fprintf(stderr, "test: control multiple sockets\n");
  fds[0] = sock_fanout_open(PACKET_FANOUT_HASH, 0);
  if (fds[0] == -1) {
    fprintf(stderr, "ERROR: failed to open HASH socket\n");
    exit(1);
  }
  if (sock_fanout_open(PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_DEFRAG, 0) !=
      -1) {
    fprintf(stderr, "ERROR: joined group with wrong flag defrag\n");
    exit(1);
  }
  if (sock_fanout_open(PACKET_FANOUT_HASH | PACKET_FANOUT_FLAG_ROLLOVER, 0) !=
      -1) {
    fprintf(stderr, "ERROR: joined group with wrong flag ro\n");
    exit(1);
  }
  if (sock_fanout_open(PACKET_FANOUT_CPU, 0) != -1) {
    fprintf(stderr, "ERROR: joined group with wrong mode\n");
    exit(1);
  }
  fds[1] = sock_fanout_open(PACKET_FANOUT_HASH, 0);
  if (fds[1] == -1) {
    fprintf(stderr, "ERROR: failed to join group\n");
    exit(1);
  }
  if (close(fds[1]) || close(fds[0])) {
    fprintf(stderr, "ERROR: closing sockets\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<test_control_group>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <sock_fanout_open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1199 <test_control_group+0x59>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x2e37(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1050 <sock_fanout_open@plt>
cmp    $0xffffffff,%eax
je     11da <test_control_group+0x9a>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    0x2dd6(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1050 <sock_fanout_open@plt>
cmp    $0xffffffff,%eax
je     121b <test_control_group+0xdb>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <sock_fanout_open@plt>
cmp    $0xffffffff,%eax
je     1253 <test_control_group+0x113>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <sock_fanout_open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    128f <test_control_group+0x14f>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
jne    12b3 <test_control_group+0x173>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
je     12d2 <test_control_group+0x192>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_control_group>:
push   %r15
push   %r14
push   %rbx
mov    0x2e7c(%rip),%r14
mov    (%r14),%edi
lea    0xeaa(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e76(%rip),%r15
mov    (%r15),%edi
xor    %esi,%esi
call   1050 <sock_fanout_open@plt>
cmp    $0xffffffff,%eax
je     11f5 <test_control_group+0xb5>
mov    %eax,%ebx
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
or     (%r15),%edi
xor    %esi,%esi
call   1050 <sock_fanout_open@plt>
cmp    $0xffffffff,%eax
jne    1201 <test_control_group+0xc1>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
or     (%r15),%edi
xor    %esi,%esi
call   1050 <sock_fanout_open@plt>
cmp    $0xffffffff,%eax
jne    120d <test_control_group+0xcd>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <sock_fanout_open@plt>
cmp    $0xffffffff,%eax
jne    1219 <test_control_group+0xd9>
mov    (%r15),%edi
xor    %esi,%esi
call   1050 <sock_fanout_open@plt>
cmp    $0xffffffff,%eax
je     1225 <test_control_group+0xe5>
mov    %eax,%edi
call   1030 <close@plt>
test   %rax,%rax
jne    11e9 <test_control_group+0xa9>
mov    %ebx,%edi
call   1030 <close@plt>
test   %rax,%rax
jne    11e9 <test_control_group+0xa9>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%r14),%edi
lea    0xee6(%rip),%rsi
jmp    122f <test_control_group+0xef>
mov    (%r14),%edi
lea    0xe21(%rip),%rsi
jmp    122f <test_control_group+0xef>
mov    (%r14),%edi
lea    0xe38(%rip),%rsi
jmp    122f <test_control_group+0xef>
mov    (%r14),%edi
lea    0xe58(%rip),%rsi
jmp    122f <test_control_group+0xef>
mov    (%r14),%edi
lea    0xe74(%rip),%rsi
jmp    122f <test_control_group+0xef>
mov    (%r14),%edi
lea    0xe8d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"test: control multiple sockets\0A\00"
@PACKET_FANOUT_HASH = global i32 0
@.str.1 = [35 x i8] c"ERROR: failed to open HASH socket\0A\00"
@PACKET_FANOUT_FLAG_DEFRAG = global i32 0
@.str.2 = [44 x i8] c"ERROR: joined group with wrong flag defrag\0A\00"
@PACKET_FANOUT_FLAG_ROLLOVER = global i32 0
@.str.3 = [40 x i8] c"ERROR: joined group with wrong flag ro\0A\00"
@PACKET_FANOUT_CPU = global i32 0
@.str.4 = [37 x i8] c"ERROR: joined group with wrong mode\0A\00"
@.str.5 = [29 x i8] c"ERROR: failed to join group\0A\00"
@.str.6 = [24 x i8] c"ERROR: closing sockets\0A\00"
define void @test_control_group() {
%1 = alloca [2 x i32]
%2 = load i32, i32* @stderr
%3 = call i32 @fprintf(i32 %2, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @PACKET_FANOUT_HASH
%5 = call i32 @sock_fanout_open(i32 %4, i32 0)
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
store i32 %5, i32* %6
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i32, i32* @PACKET_FANOUT_HASH
%16 = load i32, i32* @PACKET_FANOUT_FLAG_DEFRAG
%17 = or i32 %15, %16
%18 = call i32 @sock_fanout_open(i32 %17, i32 0)
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = load i32, i32* @PACKET_FANOUT_HASH
%26 = load i32, i32* @PACKET_FANOUT_FLAG_ROLLOVER
%27 = or i32 %25, %26
%28 = call i32 @sock_fanout_open(i32 %27, i32 0)
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %24
%35 = load i32, i32* @PACKET_FANOUT_CPU
%36 = call i32 @sock_fanout_open(i32 %35, i32 0)
%37 = icmp ne i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = load i32, i32* @PACKET_FANOUT_HASH
%44 = call i32 @sock_fanout_open(i32 %43, i32 0)
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
store i32 %44, i32* %45
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%47 = load i32, i32* %46
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %42
%50 = load i32, i32* @stderr
%51 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %42
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%55 = load i32, i32* %54
%56 = call i64 @close(i32 %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %63, label %58
58: ; preds = %53
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%60 = load i32, i32* %59
%61 = call i64 @close(i32 %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %58, %53
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %58
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"test: control multiple sockets\0A\00"
@PACKET_FANOUT_HASH = global i32 0
@.str.1 = [35 x i8] c"ERROR: failed to open HASH socket\0A\00"
@PACKET_FANOUT_FLAG_DEFRAG = global i32 0
@.str.2 = [44 x i8] c"ERROR: joined group with wrong flag defrag\0A\00"
@PACKET_FANOUT_FLAG_ROLLOVER = global i32 0
@.str.3 = [40 x i8] c"ERROR: joined group with wrong flag ro\0A\00"
@PACKET_FANOUT_CPU = global i32 0
@.str.4 = [37 x i8] c"ERROR: joined group with wrong mode\0A\00"
@.str.5 = [29 x i8] c"ERROR: failed to join group\0A\00"
@.str.6 = [24 x i8] c"ERROR: closing sockets\0A\00"
define void @test_control_group() {
%1 = load i32, i32* @stderr
%2 = tail call i32 @fprintf(i32 %1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @PACKET_FANOUT_HASH
%4 = tail call i32 @sock_fanout_open(i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @PACKET_FANOUT_HASH
%12 = load i32, i32* @PACKET_FANOUT_FLAG_DEFRAG
%13 = or i32 %12, %11
%14 = tail call i32 @sock_fanout_open(i32 %13, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = load i32, i32* @PACKET_FANOUT_HASH
%22 = load i32, i32* @PACKET_FANOUT_FLAG_ROLLOVER
%23 = or i32 %22, %21
%24 = tail call i32 @sock_fanout_open(i32 %23, i32 0)
%25 = icmp eq i32 %24, -1
br i1 %25, label %30, label %26
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %20
%31 = load i32, i32* @PACKET_FANOUT_CPU
%32 = tail call i32 @sock_fanout_open(i32 %31, i32 0)
%33 = icmp eq i32 %32, -1
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %30
%39 = load i32, i32* @PACKET_FANOUT_HASH
%40 = tail call i32 @sock_fanout_open(i32 %39, i32 0)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = tail call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %38
%47 = tail call i64 @close(i32 %40)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = tail call i64 @close(i32 %4)
%51 = icmp eq i64 %50, 0
br i1 %51, label %56, label %52
52: ; preds = %49, %46
%53 = load i32, i32* @stderr
%54 = tail call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%55 = tail call i32 @exit(i32 1)
unreachable
56: ; preds = %49
ret void
}