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

/* Variables and functions */
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ monitor_once(int, char const *);
int /*<<< orphan*/ perror(char *);
scalar_t__ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int packet_capture(int iffd1, int iffd2, const char ifname1[],
                   const char ifname2[]) {
  fd_set rfds, backupfds;
  FD_ZERO(&backupfds);
  FD_SET(iffd1, &backupfds);
  FD_SET(iffd2, &backupfds);
  while (1) {
    rfds = backupfds;
    if (select(((iffd1) < (iffd2) ? (iffd2) : (iffd1)) + 1, &rfds, NULL, NULL,
               NULL) < 0) {
      perror("select");
      return -1;
    }
    if (FD_ISSET(iffd1, &rfds))
      monitor_once(iffd1, ifname1);
    if (FD_ISSET(iffd2, &rfds))
      monitor_once(iffd2, ifname2);
  }
}


x86 assembly (clang, -O0):
<packet_capture>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <FD_SET@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <FD_SET@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b4 <packet_capture+0x54>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11ba <packet_capture+0x5a>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1050 <select@plt>
cmp    $0x0,%rax
jge    11f5 <packet_capture+0x95>
lea    0xe1b(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x4(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1217 <packet_capture+0xb7>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <monitor_once@plt>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1239 <packet_capture+0xd9>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <monitor_once@plt>
jmp    1197 <packet_capture+0x37>

x86 assembly (clang, -O2):
<packet_capture>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r13d
mov    %edi,%ebx
lea    0x4(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1080 <FD_SET@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
call   1080 <FD_SET@plt>
cmp    %r13d,%ebx
mov    %ebx,%r12d
cmovl  %r13d,%r12d
add    $0x1,%r12d
mov    0x4(%rsp),%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r12d,%edi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <select@plt>
test   %rax,%rax
jns    11e4 <packet_capture+0x84>
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbp
jmp    120e <packet_capture+0xae>
nopl   0x0(%rax)
mov    0x4(%rsp),%eax
mov    %eax,(%rsp)
mov    %r12d,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <select@plt>
test   %rax,%rax
js     11c4 <packet_capture+0x64>
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1227 <packet_capture+0xc7>
mov    %ebx,%edi
mov    %r15,%rsi
call   1070 <monitor_once@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     11f0 <packet_capture+0x90>
mov    %r13d,%edi
mov    %r14,%rsi
call   1070 <monitor_once@plt>
jmp    11f0 <packet_capture+0x90>

LLVM IR (-O0):
@.str = [7 x i8] c"select\00"
define i32 @packet_capture(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = call i32 @FD_ZERO(i32* %10)
%12 = load i32, i32* %5
%13 = call i32 @FD_SET(i32 %12, i32* %10)
%14 = load i32, i32* %6
%15 = call i32 @FD_SET(i32 %14, i32* %10)
br label %16
16: ; preds = %4, %48
%17 = load i32, i32* %10
store i32 %17, i32* %9
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i32, i32* %6
br label %25
23: ; preds = %16
%24 = load i32, i32* %5
br label %25
25: ; preds = %23, %21
%26 = phi i32 [ %22, %21 ], [ %24, %23 ]
%27 = add nsw i32 %26, 1
%28 = call i64 @select(i32 %27, i32* %9, i32* null, i32* null, i32* null)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
ret i32 -1
32: ; preds = %25
%33 = load i32, i32* %5
%34 = call i64 @FD_ISSET(i32 %33, i32* %9)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i32, i32* %5
%38 = load i8*, i8** %7
%39 = call i32 @monitor_once(i32 %37, i8* %38)
br label %40
40: ; preds = %36, %32
%41 = load i32, i32* %6
%42 = call i64 @FD_ISSET(i32 %41, i32* %9)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i32, i32* %6
%46 = load i8*, i8** %8
%47 = call i32 @monitor_once(i32 %45, i8* %46)
br label %48
48: ; preds = %44, %40
br label %16
}

LLVM IR (-O2):
@.str = [7 x i8] c"select\00"
define i32 @packet_capture(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %5 to i8*
%8 = bitcast i32* %6 to i8*
%9 = call i32 @FD_ZERO(i32* %6)
%10 = call i32 @FD_SET(i32 %0, i32* %6)
%11 = call i32 @FD_SET(i32 %1, i32* %6)
%12 = icmp slt i32 %0, %1
%13 = select i1 %12, i32 %1, i32 %0
%14 = add nsw i32 %13, 1
%15 = load i32, i32* %6
store i32 %15, i32* %5
%16 = call i64 @select(i32 %14, i32* %5, i32* null, i32* null, i32* null)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %30, %4
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
ret i32 -1
20: ; preds = %4, %30
%21 = call i64 @FD_ISSET(i32 %0, i32* %5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 @monitor_once(i32 %0, i8* %2)
br label %25
25: ; preds = %23, %20
%26 = call i64 @FD_ISSET(i32 %1, i32* %5)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = call i32 @monitor_once(i32 %1, i8* %3)
br label %30
30: ; preds = %28, %25
%31 = load i32, i32* %6
store i32 %31, i32* %5
%32 = call i64 @select(i32 %14, i32* %5, i32* null, i32* null, i32* null)
%33 = icmp slt i64 %32, 0
br i1 %33, label %18, label %20
}