#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int sock_fanout_read_ring(int, char *);
int /*<<< orphan*/ stderr;
int sock_fanout_read(int fds[], char *rings[], const int expect[]) {
  int ret[2];
  ret[0] = sock_fanout_read_ring(fds[0], rings[0]);
  ret[1] = sock_fanout_read_ring(fds[1], rings[1]);
  fprintf(stderr, "info: count=%d,%d, expect=%d,%d\n", ret[0], ret[1],
          expect[0], expect[1]);
  if ((!(ret[0] == expect[0] && ret[1] == expect[1])) &&
      (!(ret[0] == expect[1] && ret[1] == expect[0]))) {
    fprintf(stderr, "ERROR: incorrect queue lengths\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<sock_fanout_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1040 <sock_fanout_read_ring@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <sock_fanout_read_ring@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8d
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%r9d
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jne    11ab <sock_fanout_read+0x8b>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    0x4(%rcx),%eax
je     11ed <sock_fanout_read+0xcd>
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    0x4(%rcx),%eax
jne    11ca <sock_fanout_read+0xaa>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
je     11ed <sock_fanout_read+0xcd>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f4 <sock_fanout_read+0xd4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_fanout_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    (%rdi),%edi
mov    (%rsi),%rsi
call   1040 <sock_fanout_read_ring@plt>
mov    %eax,%r12d
mov    0x4(%rbx),%edi
mov    0x8(%rbp),%rsi
call   1040 <sock_fanout_read_ring@plt>
mov    %eax,%r15d
mov    0x2e89(%rip),%rbx
mov    (%rbx),%edi
mov    0x0(%r13),%r8d
mov    0x4(%r13),%r9d
lea    0xe98(%rip),%rsi
xor    %r14d,%r14d
mov    %r12d,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%r13),%eax
mov    0x4(%r13),%ecx
cmp    %eax,%r12d
jne    1189 <sock_fanout_read+0x69>
cmp    %ecx,%r15d
je     11a9 <sock_fanout_read+0x89>
cmp    %ecx,%r12d
jne    1193 <sock_fanout_read+0x73>
cmp    %eax,%r15d
je     11a9 <sock_fanout_read+0x89>
mov    (%rbx),%edi
lea    0xe85(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"info: count=%d,%d, expect=%d,%d\0A\00"
@.str.1 = [32 x i8] c"ERROR: incorrect queue lengths\0A\00"
define i32 @sock_fanout_read(i32* %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca [2 x i32]
store i32* %0, i32** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
%9 = load i32*, i32** %5
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @sock_fanout_read_ring(i32 %11, i8* %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
store i32 %15, i32* %16
%17 = load i32*, i32** %5
%18 = getelementptr inbounds i32, i32* %17, i64 1
%19 = load i32, i32* %18
%20 = load i8**, i8*** %6
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @sock_fanout_read_ring(i32 %19, i8* %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
store i32 %23, i32* %24
%25 = load i32, i32* @stderr
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%29 = load i32, i32* %28
%30 = load i32*, i32** %7
%31 = getelementptr inbounds i32, i32* %30, i64 0
%32 = load i32, i32* %31
%33 = load i32*, i32** %7
%34 = getelementptr inbounds i32, i32* %33, i64 1
%35 = load i32, i32* %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %29, i32 %32, i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%38 = load i32, i32* %37
%39 = load i32*, i32** %7
%40 = getelementptr inbounds i32, i32* %39, i64 0
%41 = load i32, i32* %40
%42 = icmp eq i32 %38, %41
br i1 %42, label %43, label %50
43: ; preds = %3
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%45 = load i32, i32* %44
%46 = load i32*, i32** %7
%47 = getelementptr inbounds i32, i32* %46, i64 1
%48 = load i32, i32* %47
%49 = icmp eq i32 %45, %48
br i1 %49, label %67, label %50
50: ; preds = %43, %3
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%52 = load i32, i32* %51
%53 = load i32*, i32** %7
%54 = getelementptr inbounds i32, i32* %53, i64 1
%55 = load i32, i32* %54
%56 = icmp eq i32 %52, %55
br i1 %56, label %57, label %64
57: ; preds = %50
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%59 = load i32, i32* %58
%60 = load i32*, i32** %7
%61 = getelementptr inbounds i32, i32* %60, i64 0
%62 = load i32, i32* %61
%63 = icmp eq i32 %59, %62
br i1 %63, label %67, label %64
64: ; preds = %57, %50
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %68
67: ; preds = %57, %43
store i32 0, i32* %4
br label %68
68: ; preds = %67, %64
%69 = load i32, i32* %4
ret i32 %69
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"info: count=%d,%d, expect=%d,%d\0A\00"
@.str.1 = [32 x i8] c"ERROR: incorrect queue lengths\0A\00"
define i32 @sock_fanout_read(i32* nocapture %0, i8** nocapture %1, i32* nocapture %2) {
%4 = load i32, i32* %0
%5 = load i8*, i8** %1
%6 = tail call i32 @sock_fanout_read_ring(i32 %4, i8* %5)
%7 = getelementptr inbounds i32, i32* %0, i64 1
%8 = load i32, i32* %7
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @sock_fanout_read_ring(i32 %8, i8* %10)
%12 = load i32, i32* @stderr
%13 = load i32, i32* %2
%14 = getelementptr inbounds i32, i32* %2, i64 1
%15 = load i32, i32* %14
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %11, i32 %13, i32 %15)
%17 = load i32, i32* %2
%18 = icmp eq i32 %6, %17
%19 = load i32, i32* %14
%20 = icmp eq i32 %11, %19
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %29, label %22
22: ; preds = %3
%23 = icmp eq i32 %6, %19
%24 = icmp eq i32 %11, %17
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %3, %22, %26
%30 = phi i32 [ 1, %26 ], [ 0, %22 ], [ 0, %3 ]
ret i32 %30
}