#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*/ flip4(unsigned int const *, unsigned int *, int);
int write(int, int const *, int);
int write_int4_array(int f, const int *i, int n) {
  int nwritten;
  flip4((const unsigned int *)i, (unsigned int *)i, n);
  nwritten = write(f, i, 4 * n);
  flip4((const unsigned int *)i, (unsigned int *)i, n);
  if (nwritten <= 0)
    return 0;
  else
    return nwritten / 4;
}


x86 assembly (clang, -O0):
<write_int4_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <flip4@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
shl    $0x2,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <flip4@plt>
cmpl   $0x0,-0x18(%rbp)
jg     117d <write_int4_array+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    118b <write_int4_array+0x6b>
mov    -0x18(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_int4_array>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <flip4@plt>
lea    0x0(,%r14,4),%edx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <flip4@plt>
test   %r15d,%r15d
jle    116f <write_int4_array+0x4f>
lea    0x3(%r15),%eax
test   %r15d,%r15d
cmovns %r15d,%eax
sar    $0x2,%eax
jmp    1171 <write_int4_array+0x51>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_int4_array(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 = load i32*, i32** %6
%11 = load i32, i32* %7
%12 = call i32 @flip4(i32* %9, i32* %10, i32 %11)
%13 = load i32, i32* %5
%14 = load i32*, i32** %6
%15 = load i32, i32* %7
%16 = mul nsw i32 4, %15
%17 = call i32 @write(i32 %13, i32* %14, i32 %16)
store i32 %17, i32* %8
%18 = load i32*, i32** %6
%19 = load i32*, i32** %6
%20 = load i32, i32* %7
%21 = call i32 @flip4(i32* %18, i32* %19, i32 %20)
%22 = load i32, i32* %8
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %3
store i32 0, i32* %4
br label %28
25: ; preds = %3
%26 = load i32, i32* %8
%27 = sdiv i32 %26, 4
store i32 %27, i32* %4
br label %28
28: ; preds = %25, %24
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @write_int4_array(i32 %0, i32* %1, i32 %2) {
%4 = tail call i32 @flip4(i32* %1, i32* %1, i32 %2)
%5 = shl nsw i32 %2, 2
%6 = tail call i32 @write(i32 %0, i32* %1, i32 %5)
%7 = tail call i32 @flip4(i32* %1, i32* %1, i32 %2)
%8 = sdiv i32 %6, 4
%9 = icmp sgt i32 %6, 0
%10 = select i1 %9, i32 %8, i32 0
ret i32 %10
}