#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*/
add_string_to_binary_exponential_buffer(void *,
                                        struct binary_exponential_buffer *);
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_with_null_terminator(
    void *dest, struct binary_exponential_buffer *b) {
  add_string_to_binary_exponential_buffer(dest, b);
  binary_exponential_buffer_increment(b, 1);
  ((unsigned char *)binary_exponential_buffer_data(
      b))[binary_exponential_buffer_size(b) - 1] = 0;
}


x86 assembly (clang, -O0):
<add_string_to_binary_exponential_buffer_with_null_terminator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <add_string_to_binary_exponential_buffer@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    -0x10(%rbp),%rdi
call   1060 <binary_exponential_buffer_data@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <binary_exponential_buffer_size@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_string_to_binary_exponential_buffer_with_null_terminator>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1050 <add_string_to_binary_exponential_buffer@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    %rbx,%rdi
call   1060 <binary_exponential_buffer_data@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <binary_exponential_buffer_size@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.binary_exponential_buffer = type { i32 }
define void @add_string_to_binary_exponential_buffer_with_null_terminator(i8* %0, %struct.binary_exponential_buffer* %1) {
%3 = alloca i8*
%4 = alloca %struct.binary_exponential_buffer*
store i8* %0, i8** %3
store %struct.binary_exponential_buffer* %1, %struct.binary_exponential_buffer** %4
%5 = load i8*, i8** %3
%6 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%7 = call i32 @add_string_to_binary_exponential_buffer(i8* %5, %struct.binary_exponential_buffer* %6)
%8 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%9 = call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %8, i32 1)
%10 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%11 = call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %10)
%12 = inttoptr i64 %11 to i8*
%13 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%14 = call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
store i8 0, i8* %17
ret void
}

LLVM IR (-O2):
%struct.binary_exponential_buffer = type { i32 }
define void @add_string_to_binary_exponential_buffer_with_null_terminator(i8* %0, %struct.binary_exponential_buffer* %1) {
%3 = tail call i32 @add_string_to_binary_exponential_buffer(i8* %0, %struct.binary_exponential_buffer* %1)
%4 = tail call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %1, i32 1)
%5 = tail call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %1)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %1)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
store i8 0, i8* %10
ret void
}