#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 */
struct EncodedData {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ encode_big_endian_integer(unsigned int, int,
                                             struct EncodedData *);
void encode_little_endian_integer(unsigned int value, int num_bits,
                                  struct EncodedData *result) {
  int i;
  for (i = 0; i < num_bits / 8; ++i) {
    encode_big_endian_integer(value & 0xFF, 8, result);
    value >>= 8;
  }
}


x86 assembly (clang, -O0):
<encode_little_endian_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    1175 <encode_little_endian_integer+0x65>
mov    -0x4(%rbp),%edi
and    $0xff,%edi
mov    -0x10(%rbp),%rdx
mov    $0x8,%esi
call   1030 <encode_big_endian_integer@plt>
mov    -0x4(%rbp),%eax
shr    $0x8,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <encode_little_endian_integer+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_little_endian_integer>:
push   %rbp
push   %r14
push   %rbx
lea    0x7(%rsi),%ebx
test   %esi,%esi
cmovns %esi,%ebx
cmp    $0x8,%esi
jl     1149 <encode_little_endian_integer+0x39>
mov    %rdx,%r14
mov    %edi,%ebp
sar    $0x3,%ebx
nopl   0x0(%rax)
movzbl %bpl,%edi
mov    $0x8,%esi
mov    %r14,%rdx
call   1030 <encode_big_endian_integer@plt>
shr    $0x8,%ebp
add    $0xffffffff,%ebx
jne    1130 <encode_little_endian_integer+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.EncodedData = type { i32 }
define void @encode_little_endian_integer(i32 %0, i32 %1, %struct.EncodedData* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.EncodedData*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store %struct.EncodedData* %2, %struct.EncodedData** %6
store i32 0, i32* %7
br label %8
8: ; preds = %20, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = sdiv i32 %10, 8
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = load i32, i32* %4
%15 = and i32 %14, 255
%16 = load %struct.EncodedData*, %struct.EncodedData** %6
%17 = call i32 @encode_big_endian_integer(i32 %15, i32 8, %struct.EncodedData* %16)
%18 = load i32, i32* %4
%19 = lshr i32 %18, 8
store i32 %19, i32* %4
br label %20
20: ; preds = %13
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
br label %8
23: ; preds = %8
ret void
}

LLVM IR (-O2):
%struct.EncodedData = type { i32 }
define void @encode_little_endian_integer(i32 %0, i32 %1, %struct.EncodedData* %2) {
%4 = sdiv i32 %1, 8
%5 = icmp sgt i32 %1, 7
br i1 %5, label %6, label %14
6: ; preds = %3, %6
%7 = phi i32 [ %12, %6 ], [ 0, %3 ]
%8 = phi i32 [ %11, %6 ], [ %0, %3 ]
%9 = and i32 %8, 255
%10 = tail call i32 @encode_big_endian_integer(i32 %9, i32 8, %struct.EncodedData* %2)
%11 = lshr i32 %8, 8
%12 = add nuw nsw i32 %7, 1
%13 = icmp eq i32 %12, %4
br i1 %13, label %14, label %6
14: ; preds = %6, %3
ret void
}