#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 Chabu_ByteBuffer_Data {
  int dummy;
};
typedef int length;

/* Variables and functions */
int /*<<< orphan*/ Chabu_ByteBuffer_putIntBe(struct Chabu_ByteBuffer_Data *,
                                             int);
int Chabu_ByteBuffer_remaining(struct Chabu_ByteBuffer_Data *);
int /*<<< orphan*/
Chabu_ByteBuffer_xferAllPossible(struct Chabu_ByteBuffer_Data *,
                                 struct Chabu_ByteBuffer_Data *);
int /*<<< orphan*/ appendPadding(struct Chabu_ByteBuffer_Data *, int);
void Chabu_ByteBuffer_putStringFromBuffer(
    struct Chabu_ByteBuffer_Data *data,
    struct Chabu_ByteBuffer_Data *stringBuffer) {
  int length = Chabu_ByteBuffer_remaining(stringBuffer);
  Chabu_ByteBuffer_putIntBe(data, length);
  Chabu_ByteBuffer_xferAllPossible(data, stringBuffer);
  appendPadding(data, (((length) + 3) & ~3) - length);
}


x86 assembly (clang, -O0):
<Chabu_ByteBuffer_putStringFromBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <Chabu_ByteBuffer_remaining@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <Chabu_ByteBuffer_putIntBe@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <Chabu_ByteBuffer_xferAllPossible@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x3,%esi
and    $0xfffffffc,%esi
sub    -0x14(%rbp),%esi
call   1040 <appendPadding@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Chabu_ByteBuffer_putStringFromBuffer>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <Chabu_ByteBuffer_remaining@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <Chabu_ByteBuffer_putIntBe@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <Chabu_ByteBuffer_xferAllPossible@plt>
lea    0x3(%rbx),%esi
and    $0xfffffffc,%esi
sub    %ebx,%esi
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <appendPadding@plt>

LLVM IR (-O0):
%struct.Chabu_ByteBuffer_Data = type { i32 }
define void @Chabu_ByteBuffer_putStringFromBuffer(%struct.Chabu_ByteBuffer_Data* %0, %struct.Chabu_ByteBuffer_Data* %1) {
%3 = alloca %struct.Chabu_ByteBuffer_Data*
%4 = alloca %struct.Chabu_ByteBuffer_Data*
%5 = alloca i32
store %struct.Chabu_ByteBuffer_Data* %0, %struct.Chabu_ByteBuffer_Data** %3
store %struct.Chabu_ByteBuffer_Data* %1, %struct.Chabu_ByteBuffer_Data** %4
%6 = load %struct.Chabu_ByteBuffer_Data*, %struct.Chabu_ByteBuffer_Data** %4
%7 = call i32 @Chabu_ByteBuffer_remaining(%struct.Chabu_ByteBuffer_Data* %6)
store i32 %7, i32* %5
%8 = load %struct.Chabu_ByteBuffer_Data*, %struct.Chabu_ByteBuffer_Data** %3
%9 = load i32, i32* %5
%10 = call i32 @Chabu_ByteBuffer_putIntBe(%struct.Chabu_ByteBuffer_Data* %8, i32 %9)
%11 = load %struct.Chabu_ByteBuffer_Data*, %struct.Chabu_ByteBuffer_Data** %3
%12 = load %struct.Chabu_ByteBuffer_Data*, %struct.Chabu_ByteBuffer_Data** %4
%13 = call i32 @Chabu_ByteBuffer_xferAllPossible(%struct.Chabu_ByteBuffer_Data* %11, %struct.Chabu_ByteBuffer_Data* %12)
%14 = load %struct.Chabu_ByteBuffer_Data*, %struct.Chabu_ByteBuffer_Data** %3
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 3
%17 = and i32 %16, -4
%18 = load i32, i32* %5
%19 = sub nsw i32 %17, %18
%20 = call i32 @appendPadding(%struct.Chabu_ByteBuffer_Data* %14, i32 %19)
ret void
}

LLVM IR (-O2):
%struct.Chabu_ByteBuffer_Data = type { i32 }
define void @Chabu_ByteBuffer_putStringFromBuffer(%struct.Chabu_ByteBuffer_Data* %0, %struct.Chabu_ByteBuffer_Data* %1) {
%3 = tail call i32 @Chabu_ByteBuffer_remaining(%struct.Chabu_ByteBuffer_Data* %1)
%4 = tail call i32 @Chabu_ByteBuffer_putIntBe(%struct.Chabu_ByteBuffer_Data* %0, i32 %3)
%5 = tail call i32 @Chabu_ByteBuffer_xferAllPossible(%struct.Chabu_ByteBuffer_Data* %0, %struct.Chabu_ByteBuffer_Data* %1)
%6 = add nsw i32 %3, 3
%7 = and i32 %6, -4
%8 = sub nsw i32 %7, %3
%9 = tail call i32 @appendPadding(%struct.Chabu_ByteBuffer_Data* %0, i32 %8)
ret void
}