#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 ssize_t;

/* Variables and functions */
int spliceall(int const, int const, size_t);
ssize_t drain(const int *in, const int *out, size_t nfds, size_t len) {
  for (size_t i = 0; i < nfds; ++i) {
    if (spliceall(in[i], out[i], len) == -1) {
      return -1;
    }
  }
  return len;
}


x86 assembly (clang, -O0):
<drain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1188 <drain+0x78>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x28(%rbp),%rdx
call   1030 <spliceall@plt>
cmp    $0xffffffff,%eax
jne    1172 <drain+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    118f <drain+0x7f>
jmp    1177 <drain+0x67>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1130 <drain+0x20>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drain>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
test   %rdx,%rdx
je     1169 <drain+0x59>
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%r12
mov    (%rdi),%edi
mov    (%rsi),%esi
mov    %r14,%rdx
call   1030 <spliceall@plt>
cmp    $0xffffffff,%eax
je     116e <drain+0x5e>
mov    $0x1,%ecx
mov    %rcx,%rbx
cmp    %rcx,%r13
je     1161 <drain+0x51>
mov    (%r12,%rbx,4),%edi
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdx
call   1030 <spliceall@plt>
lea    0x1(%rbx),%rcx
cmp    $0xffffffff,%eax
jne    1140 <drain+0x30>
cmp    %r13,%rbx
setb   %al
jmp    1170 <drain+0x60>
mov    %r14d,%eax
jmp    117b <drain+0x6b>
mov    $0x1,%al
test   %al,%al
mov    $0xffffffff,%eax
cmove  %r14d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @drain(i32* %0, i32* %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32* %0, i32** %6
store i32* %1, i32** %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i64 0, i64* %10
br label %11
11: ; preds = %29, %4
%12 = load i64, i64* %10
%13 = load i64, i64* %8
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %32
15: ; preds = %11
%16 = load i32*, i32** %6
%17 = load i64, i64* %10
%18 = getelementptr inbounds i32, i32* %16, i64 %17
%19 = load i32, i32* %18
%20 = load i32*, i32** %7
%21 = load i64, i64* %10
%22 = getelementptr inbounds i32, i32* %20, i64 %21
%23 = load i32, i32* %22
%24 = load i64, i64* %9
%25 = call i32 @spliceall(i32 %19, i32 %23, i64 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %15
store i32 -1, i32* %5
br label %35
28: ; preds = %15
br label %29
29: ; preds = %28
%30 = load i64, i64* %10
%31 = add i64 %30, 1
store i64 %31, i64* %10
br label %11
32: ; preds = %11
%33 = load i64, i64* %9
%34 = trunc i64 %33 to i32
store i32 %34, i32* %5
br label %35
35: ; preds = %32, %27
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
define i32 @drain(i32* nocapture %0, i32* nocapture %1, i64 %2, i64 %3) {
%5 = icmp eq i64 %2, 0
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = load i32, i32* %0
%8 = load i32, i32* %1
%9 = tail call i32 @spliceall(i32 %7, i32 %8, i64 %3)
%10 = icmp eq i32 %9, -1
br i1 %10, label %26, label %13
11: ; preds = %4
%12 = trunc i64 %3 to i32
br label %30
13: ; preds = %6, %16
%14 = phi i64 [ %23, %16 ], [ 1, %6 ]
%15 = icmp eq i64 %14, %2
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = getelementptr inbounds i32, i32* %0, i64 %14
%18 = load i32, i32* %17
%19 = getelementptr inbounds i32, i32* %1, i64 %14
%20 = load i32, i32* %19
%21 = tail call i32 @spliceall(i32 %18, i32 %20, i64 %3)
%22 = icmp eq i32 %21, -1
%23 = add nuw i64 %14, 1
br i1 %22, label %24, label %13
24: ; preds = %13, %16
%25 = icmp ult i64 %14, %2
br label %26
26: ; preds = %24, %6
%27 = phi i1 [ true, %6 ], [ %25, %24 ]
%28 = trunc i64 %3 to i32
%29 = select i1 %27, i32 -1, i32 %28
br label %30
30: ; preds = %26, %11
%31 = phi i32 [ %12, %11 ], [ %29, %26 ]
ret i32 %31
}