#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*/ bzero(int *, int);
int read(int, int *, int);
int /*<<< orphan*/ si_swapl(int *);
int si_receive_n_ints(int fd, int n, int *data) {
  int len, i;
  int ret;
  len = n * sizeof(int);
  if (fd < 0) {
    bzero(data, len);
    return 0;
  }
  if ((ret = read(fd, data, len)) != len)
    return -1;
  for (i = 0; i < n; i++)
    si_swapl(&data[i]);
  return 0;
}


x86 assembly (clang, -O0):
<si_receive_n_ints>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    116f <si_receive_n_ints+0x3f>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <bzero@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <si_receive_n_ints+0xa2>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    -0x1c(%rbp),%eax
je     1196 <si_receive_n_ints+0x66>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <si_receive_n_ints+0xa2>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cb <si_receive_n_ints+0x9b>
mov    -0x18(%rbp),%rdi
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1050 <si_swapl@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119d <si_receive_n_ints+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<si_receive_n_ints>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r15d
lea    0x0(,%r15,4),%ebp
test   %edi,%edi
js     1184 <si_receive_n_ints+0x54>
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <read@plt>
mov    $0xffffffff,%r14d
cmp    %ebp,%eax
jne    1191 <si_receive_n_ints+0x61>
xor    %r14d,%r14d
test   %r15d,%r15d
jle    1191 <si_receive_n_ints+0x61>
mov    %r15d,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <si_swapl@plt>
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
jne    1170 <si_receive_n_ints+0x40>
jmp    1191 <si_receive_n_ints+0x61>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <bzero@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @si_receive_n_ints(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
store i32 %14, i32* %8
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i32*, i32** %7
%19 = load i32, i32* %8
%20 = call i32 @bzero(i32* %18, i32 %19)
store i32 0, i32* %4
br label %44
21: ; preds = %3
%22 = load i32, i32* %5
%23 = load i32*, i32** %7
%24 = load i32, i32* %8
%25 = call i32 @read(i32 %22, i32* %23, i32 %24)
store i32 %25, i32* %10
%26 = load i32, i32* %8
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %21
store i32 -1, i32* %4
br label %44
29: ; preds = %21
store i32 0, i32* %9
br label %30
30: ; preds = %40, %29
%31 = load i32, i32* %9
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %43
34: ; preds = %30
%35 = load i32*, i32** %7
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = call i32 @si_swapl(i32* %38)
br label %40
40: ; preds = %34
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %30
43: ; preds = %30
store i32 0, i32* %4
br label %44
44: ; preds = %43, %28, %17
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
define i32 @si_receive_n_ints(i32 %0, i32 %1, i32* %2) {
%4 = shl i32 %1, 2
%5 = icmp slt i32 %0, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @bzero(i32* %2, i32 %4)
br label %21
8: ; preds = %3
%9 = tail call i32 @read(i32 %0, i32* %2, i32 %4)
%10 = icmp eq i32 %9, %4
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %21
13: ; preds = %11
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %19, %15 ]
%17 = getelementptr inbounds i32, i32* %2, i64 %16
%18 = tail call i32 @si_swapl(i32* %17)
%19 = add nuw nsw i64 %16, 1
%20 = icmp eq i64 %19, %14
br i1 %20, label %21, label %15
21: ; preds = %15, %11, %8, %6
%22 = phi i32 [ 0, %6 ], [ -1, %8 ], [ 0, %11 ], [ 0, %15 ]
ret i32 %22
}