#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 /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ hecmw_write_bin_value(unsigned char *, int, int /*<<< orphan*/ *);
int hecmw_write_bin_int_arr(int *x, int n, FILE *fp) {
  long xx;
  int i;
  for (i = 0; i < n; i++, x++) {
    xx = *x;
    if (hecmw_write_bin_value((unsigned char *)&xx, sizeof(long), fp) != 0)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<hecmw_write_bin_int_arr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1188 <hecmw_write_bin_int_arr+0x78>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x8,%esi
call   1030 <hecmw_write_bin_value@plt>
cmp    $0x0,%rax
je     1169 <hecmw_write_bin_int_arr+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    118f <hecmw_write_bin_int_arr+0x7f>
jmp    116e <hecmw_write_bin_int_arr+0x5e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    112a <hecmw_write_bin_int_arr+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hecmw_write_bin_int_arr>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    1168 <hecmw_write_bin_int_arr+0x58>
mov    %rdx,%r14
mov    %rdi,%r13
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0x8(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq 0x0(%r13,%rbx,4),%rax
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
mov    $0x8,%esi
mov    %r14,%rdx
call   1030 <hecmw_write_bin_value@plt>
test   %rax,%rax
jne    116c <hecmw_write_bin_int_arr+0x5c>
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1140 <hecmw_write_bin_int_arr+0x30>
xor    %eax,%eax
jmp    1171 <hecmw_write_bin_int_arr+0x61>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @hecmw_write_bin_int_arr(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 0, i32* %9
br label %10
10: ; preds = %24, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = sext i32 %16 to i64
store i64 %17, i64* %8
%18 = bitcast i64* %8 to i8*
%19 = load i32*, i32** %7
%20 = call i64 @hecmw_write_bin_value(i8* %18, i32 8, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 -1, i32* %4
br label %30
23: ; preds = %14
br label %24
24: ; preds = %23
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
store i32 %26, i32* %9
%27 = load i32*, i32** %5
%28 = getelementptr inbounds i32, i32* %27, i32 1
store i32* %28, i32** %5
br label %10
29: ; preds = %10
store i32 0, i32* %4
br label %30
30: ; preds = %29, %22
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @hecmw_write_bin_int_arr(i32* nocapture %0, i32 %1, i32* %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %18
7: ; preds = %3, %14
%8 = phi i32 [ %15, %14 ], [ 0, %3 ]
%9 = phi i32* [ %16, %14 ], [ %0, %3 ]
%10 = load i32, i32* %9
%11 = sext i32 %10 to i64
store i64 %11, i64* %4
%12 = call i64 @hecmw_write_bin_value(i8* %5, i32 8, i32* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %7
%15 = add nuw nsw i32 %8, 1
%16 = getelementptr inbounds i32, i32* %9, i64 1
%17 = icmp eq i32 %15, %1
br i1 %17, label %18, label %7
18: ; preds = %7, %14, %3
%19 = phi i32 [ 0, %3 ], [ 0, %14 ], [ -1, %7 ]
ret i32 %19
}