#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*/ v;
typedef int /*<<< orphan*/ uint32_t;
struct byte_array {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ _byte_array_pack32(struct byte_array *, int /*<<< orphan*/);
int /*<<< orphan*/ ensure_size(struct byte_array *, size_t);
void _byte_array_pack32v(struct byte_array *ba, uint32_t *v, size_t n) {
  ensure_size(ba, n * sizeof(v[0]));
  size_t i;
  for (i = 0; i < n; i++)
    _byte_array_pack32(ba, v[i]);
}


x86 assembly (clang, -O0):
<_byte_array_pack32v>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
shl    $0x2,%rsi
call   1030 <ensure_size@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1180 <_byte_array_pack32v+0x60>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1040 <_byte_array_pack32@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114d <_byte_array_pack32v+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_byte_array_pack32v>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%rdx,4),%rsi
call   1030 <ensure_size@plt>
test   %r12,%r12
je     1165 <_byte_array_pack32v+0x45>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%rbx,4),%esi
mov    %r15,%rdi
call   1040 <_byte_array_pack32@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <_byte_array_pack32v+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.byte_array = type { i32 }
define void @_byte_array_pack32v(%struct.byte_array* %0, i32* %1, i64 %2) {
%4 = alloca %struct.byte_array*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
store %struct.byte_array* %0, %struct.byte_array** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
%8 = load %struct.byte_array*, %struct.byte_array** %4
%9 = load i64, i64* %6
%10 = mul i64 %9, 4
%11 = call i32 @ensure_size(%struct.byte_array* %8, i64 %10)
store i64 0, i64* %7
br label %12
12: ; preds = %23, %3
%13 = load i64, i64* %7
%14 = load i64, i64* %6
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load %struct.byte_array*, %struct.byte_array** %4
%18 = load i32*, i32** %5
%19 = load i64, i64* %7
%20 = getelementptr inbounds i32, i32* %18, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @_byte_array_pack32(%struct.byte_array* %17, i32 %21)
br label %23
23: ; preds = %16
%24 = load i64, i64* %7
%25 = add i64 %24, 1
store i64 %25, i64* %7
br label %12
26: ; preds = %12
ret void
}

LLVM IR (-O2):
%struct.byte_array = type { i32 }
define void @_byte_array_pack32v(%struct.byte_array* %0, i32* nocapture %1, i64 %2) {
%4 = shl i64 %2, 2
%5 = tail call i32 @ensure_size(%struct.byte_array* %0, i64 %4)
%6 = icmp eq i64 %2, 0
br i1 %6, label %14, label %7
7: ; preds = %3, %7
%8 = phi i64 [ %12, %7 ], [ 0, %3 ]
%9 = getelementptr inbounds i32, i32* %1, i64 %8
%10 = load i32, i32* %9
%11 = tail call i32 @_byte_array_pack32(%struct.byte_array* %0, i32 %10)
%12 = add nuw i64 %8, 1
%13 = icmp eq i64 %12, %2
br i1 %13, label %14, label %7
14: ; preds = %7, %3
ret void
}