#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*/ assert(int);
int compare_fds(int nfds, fd_set *lh, fd_set *rh) {
  int i;
  assert(lh != NULL && rh != NULL && nfds > 0);
  for (i = 0; i < nfds; i++) {
    if ((FD_ISSET(i, lh) && !FD_ISSET(i, rh)) ||
        (!FD_ISSET(i, lh) && FD_ISSET(i, rh))) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<compare_fds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x1d(%rbp)
je     115d <compare_fds+0x3d>
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
je     115d <compare_fds+0x3d>
cmpl   $0x0,-0x8(%rbp)
setg   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f4 <compare_fds+0xd4>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     11a9 <compare_fds+0x89>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     11d5 <compare_fds+0xb5>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
jne    11e1 <compare_fds+0xc1>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     11e1 <compare_fds+0xc1>
movl   $0x0,-0x4(%rbp)
jmp    11fb <compare_fds+0xdb>
jmp    11e6 <compare_fds+0xc6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <compare_fds+0x51>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_fds>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r12d
test   %rsi,%rsi
setne  %al
test   %rdx,%rdx
setne  %cl
and    %al,%cl
test   %edi,%edi
setg   %al
and    %cl,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x1,%r15d
test   %r12d,%r12d
jle    11a7 <compare_fds+0x87>
xor    %ebp,%ebp
jmp    1168 <compare_fds+0x48>
nopl   (%rax)
add    $0x1,%ebp
cmp    %ebp,%r12d
je     11a7 <compare_fds+0x87>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1186 <compare_fds+0x66>
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     11a4 <compare_fds+0x84>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
jne    1160 <compare_fds+0x40>
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     1160 <compare_fds+0x40>
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @compare_fds(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32*, i32** %7
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %5
%16 = icmp sgt i32 %15, 0
br label %17
17: ; preds = %14, %11, %3
%18 = phi i1 [ false, %11 ], [ false, %3 ], [ %16, %14 ]
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
store i32 0, i32* %8
br label %21
21: ; preds = %47, %17
%22 = load i32, i32* %8
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %50
25: ; preds = %21
%26 = load i32, i32* %8
%27 = load i32*, i32** %6
%28 = call i64 @FD_ISSET(i32 %26, i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32, i32* %8
%32 = load i32*, i32** %7
%33 = call i64 @FD_ISSET(i32 %31, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %30, %25
%36 = load i32, i32* %8
%37 = load i32*, i32** %6
%38 = call i64 @FD_ISSET(i32 %36, i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %46, label %40
40: ; preds = %35
%41 = load i32, i32* %8
%42 = load i32*, i32** %7
%43 = call i64 @FD_ISSET(i32 %41, i32* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %40, %30
store i32 0, i32* %4
br label %51
46: ; preds = %40, %35
br label %47
47: ; preds = %46
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %21
50: ; preds = %21
store i32 1, i32* %4
br label %51
51: ; preds = %50, %45
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
define i32 @compare_fds(i32 %0, i32* %1, i32* %2) {
%4 = icmp ne i32* %1, null
%5 = icmp ne i32* %2, null
%6 = and i1 %4, %5
%7 = icmp sgt i32 %0, 0
%8 = and i1 %7, %6
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
br i1 %7, label %11, label %27
11: ; preds = %3, %24
%12 = phi i32 [ %25, %24 ], [ 0, %3 ]
%13 = tail call i64 @FD_ISSET(i32 %12, i32* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = tail call i64 @FD_ISSET(i32 %12, i32* %2)
%17 = icmp eq i64 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %15, %11
%19 = tail call i64 @FD_ISSET(i32 %12, i32* %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = tail call i64 @FD_ISSET(i32 %12, i32* %2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18, %21
%25 = add nuw nsw i32 %12, 1
%26 = icmp eq i32 %25, %0
br i1 %26, label %27, label %11
27: ; preds = %21, %15, %24, %3
%28 = phi i32 [ 1, %3 ], [ 1, %24 ], [ 0, %15 ], [ 0, %21 ]
ret i32 %28
}