#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 /*<<< orphan*/ flip4(unsigned int const *, unsigned int *, size_t);
int write(int, int const *, int);
ssize_t write_int4_array(int f, const int *i, size_t n) {
  ssize_t 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    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <flip4@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <flip4@plt>
cmpl   $0x0,-0x1c(%rbp)
jg     1184 <write_int4_array+0x64>
movl   $0x0,-0x4(%rbp)
jmp    1192 <write_int4_array+0x72>
mov    -0x1c(%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    %rdx,%r14
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    %r14,%rdx
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, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i64 %2, i64* %7
%9 = load i32*, i32** %6
%10 = load i32*, i32** %6
%11 = load i64, i64* %7
%12 = call i32 @flip4(i32* %9, i32* %10, i64 %11)
%13 = load i32, i32* %5
%14 = load i32*, i32** %6
%15 = load i64, i64* %7
%16 = mul i64 4, %15
%17 = trunc i64 %16 to i32
%18 = call i32 @write(i32 %13, i32* %14, i32 %17)
store i32 %18, i32* %8
%19 = load i32*, i32** %6
%20 = load i32*, i32** %6
%21 = load i64, i64* %7
%22 = call i32 @flip4(i32* %19, i32* %20, i64 %21)
%23 = load i32, i32* %8
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %3
store i32 0, i32* %4
br label %29
26: ; preds = %3
%27 = load i32, i32* %8
%28 = sdiv i32 %27, 4
store i32 %28, i32* %4
br label %29
29: ; preds = %26, %25
%30 = load i32, i32* %4
ret i32 %30
}

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