#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 binary_exponential_buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ binary_exponential_buffer_data(struct binary_exponential_buffer *);
int binary_exponential_buffer_element_size(struct binary_exponential_buffer *);
int /*<<< orphan*/
binary_exponential_buffer_increment(struct binary_exponential_buffer *, int);
int binary_exponential_buffer_size(struct binary_exponential_buffer *);
void add_buffer_to_binary_exponential_buffer(
    struct binary_exponential_buffer *src,
    struct binary_exponential_buffer *dest) {
  unsigned int src_size = binary_exponential_buffer_size(src);
  unsigned int i = 0;
  assert(binary_exponential_buffer_element_size(src) == sizeof(unsigned char) &&
         binary_exponential_buffer_element_size(dest) == sizeof(unsigned char));
  while (i < src_size) {
    unsigned char c = ((unsigned char *)binary_exponential_buffer_data(src))[i];
    binary_exponential_buffer_increment(dest, 1);
    ((unsigned char *)binary_exponential_buffer_data(
        dest))[binary_exponential_buffer_size(dest) - 1] = c;
    i++;
  }
}


x86 assembly (clang, -O0):
<add_buffer_to_binary_exponential_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <binary_exponential_buffer_size@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <binary_exponential_buffer_element_size@plt>
movslq %eax,%rcx
xor    %eax,%eax
cmp    $0x1,%rcx
mov    %al,-0x1a(%rbp)
jne    11a3 <add_buffer_to_binary_exponential_buffer+0x53>
mov    -0x10(%rbp),%rdi
call   1040 <binary_exponential_buffer_element_size@plt>
cltq
cmp    $0x1,%rax
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1218 <add_buffer_to_binary_exponential_buffer+0xc8>
mov    -0x8(%rbp),%rdi
call   1070 <binary_exponential_buffer_data@plt>
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    -0x19(%rbp),%al
mov    %al,-0x29(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <binary_exponential_buffer_data@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <binary_exponential_buffer_size@plt>
mov    -0x29(%rbp),%dl
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b0 <add_buffer_to_binary_exponential_buffer+0x60>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_buffer_to_binary_exponential_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
call   1060 <binary_exponential_buffer_size@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <binary_exponential_buffer_element_size@plt>
xor    %edi,%edi
cmp    $0x1,%eax
jne    1188 <add_buffer_to_binary_exponential_buffer+0x38>
mov    %r12,%rdi
call   1040 <binary_exponential_buffer_element_size@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1050 <assert@plt>
test   %ebp,%ebp
je     11dd <add_buffer_to_binary_exponential_buffer+0x8d>
mov    %ebp,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <binary_exponential_buffer_data@plt>
movzbl (%rax,%rbx,1),%r13d
mov    %r12,%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    %r12,%rdi
call   1070 <binary_exponential_buffer_data@plt>
mov    %rax,%rbp
mov    %r12,%rdi
call   1060 <binary_exponential_buffer_size@plt>
cltq
mov    %r13b,-0x1(%rax,%rbp,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11a0 <add_buffer_to_binary_exponential_buffer+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.binary_exponential_buffer = type { i32 }
define void @add_buffer_to_binary_exponential_buffer(%struct.binary_exponential_buffer* %0, %struct.binary_exponential_buffer* %1) {
%3 = alloca %struct.binary_exponential_buffer*
%4 = alloca %struct.binary_exponential_buffer*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
store %struct.binary_exponential_buffer* %0, %struct.binary_exponential_buffer** %3
store %struct.binary_exponential_buffer* %1, %struct.binary_exponential_buffer** %4
%8 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %3
%9 = call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %8)
store i32 %9, i32* %5
store i32 0, i32* %6
%10 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %3
%11 = call i32 @binary_exponential_buffer_element_size(%struct.binary_exponential_buffer* %10)
%12 = sext i32 %11 to i64
%13 = icmp eq i64 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%16 = call i32 @binary_exponential_buffer_element_size(%struct.binary_exponential_buffer* %15)
%17 = sext i32 %16 to i64
%18 = icmp eq i64 %17, 1
br label %19
19: ; preds = %14, %2
%20 = phi i1 [ false, %2 ], [ %18, %14 ]
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
br label %23
23: ; preds = %27, %19
%24 = load i32, i32* %6
%25 = load i32, i32* %5
%26 = icmp ult i32 %24, %25
br i1 %26, label %27, label %48
27: ; preds = %23
%28 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %3
%29 = call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %28)
%30 = inttoptr i64 %29 to i8*
%31 = load i32, i32* %6
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
store i8 %34, i8* %7
%35 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%36 = call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %35, i32 1)
%37 = load i8, i8* %7
%38 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%39 = call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %38)
%40 = inttoptr i64 %39 to i8*
%41 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%42 = call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %41)
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %40, i64 %44
store i8 %37, i8* %45
%46 = load i32, i32* %6
%47 = add i32 %46, 1
store i32 %47, i32* %6
br label %23
48: ; preds = %23
ret void
}

LLVM IR (-O2):
%struct.binary_exponential_buffer = type { i32 }
define void @add_buffer_to_binary_exponential_buffer(%struct.binary_exponential_buffer* %0, %struct.binary_exponential_buffer* %1) {
%3 = tail call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %0)
%4 = tail call i32 @binary_exponential_buffer_element_size(%struct.binary_exponential_buffer* %0)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @binary_exponential_buffer_element_size(%struct.binary_exponential_buffer* %1)
%8 = icmp eq i32 %7, 1
%9 = zext i1 %8 to i32
br label %10
10: ; preds = %6, %2
%11 = phi i32 [ 0, %2 ], [ %9, %6 ]
%12 = tail call i32 @assert(i32 %11)
%13 = icmp eq i32 %3, 0
br i1 %13, label %31, label %14
14: ; preds = %10
%15 = zext i32 %3 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %29, %16 ]
%18 = tail call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %0)
%19 = inttoptr i64 %18 to i8*
%20 = getelementptr inbounds i8, i8* %19, i64 %17
%21 = load i8, i8* %20
%22 = tail call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %1, i32 1)
%23 = tail call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %1)
%24 = inttoptr i64 %23 to i8*
%25 = tail call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %1)
%26 = add nsw i32 %25, -1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 %21, i8* %28
%29 = add nuw nsw i64 %17, 1
%30 = icmp eq i64 %29, %15
br i1 %30, label %31, label %16
31: ; preds = %16, %10
ret void
}