#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 */
scalar_t__ binary_exponential_buffer_data(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_string_to_binary_exponential_buffer(
    void *dest, struct binary_exponential_buffer *b) {
  unsigned int i = 0;
  unsigned char *str = (unsigned char *)dest;
  while (*str) {
    binary_exponential_buffer_increment(b, 1);
    ((unsigned char *)binary_exponential_buffer_data(
        b))[binary_exponential_buffer_size(b) - 1] = *str;
    i++;
    str++;
  }
}


x86 assembly (clang, -O0):
<add_string_to_binary_exponential_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b5 <add_string_to_binary_exponential_buffer+0x85>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <binary_exponential_buffer_data@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <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    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114f <add_string_to_binary_exponential_buffer+0x1f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_string_to_binary_exponential_buffer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     1184 <add_string_to_binary_exponential_buffer+0x54>
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
movzbl -0x1(%rbx),%ebp
mov    %r14,%rdi
call   1050 <binary_exponential_buffer_data@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <binary_exponential_buffer_size@plt>
cltq
mov    %bpl,-0x1(%rax,%r15,1)
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
jne    1150 <add_string_to_binary_exponential_buffer+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.binary_exponential_buffer = type { i32 }
define void @add_string_to_binary_exponential_buffer(i8* nocapture %0, %struct.binary_exponential_buffer* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %2, %5
%6 = phi i8* [ %15, %5 ], [ %0, %2 ]
%7 = tail call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %1, i32 1)
%8 = load i8, i8* %6
%9 = tail call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %1)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %1)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
store i8 %8, i8* %14
%15 = getelementptr inbounds i8, i8* %6, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %5
18: ; preds = %5, %2
ret void
}