#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_unsigned_int_to_binary_exponential_buffer(
    unsigned int unsigned_d, struct binary_exponential_buffer *buffer) {
  unsigned int leading_zero = 1;
  unsigned int base = 1000000000;
  unsigned int digit = 0;
  if (unsigned_d == 0) {
    binary_exponential_buffer_increment(buffer, 1);
    ((unsigned char *)binary_exponential_buffer_data(
        buffer))[binary_exponential_buffer_size(buffer) - 1] =
        (unsigned char)'0';
  }
  while (base) {
    digit = unsigned_d / base;
    if (digit) {
      binary_exponential_buffer_increment(buffer, 1);
      ((unsigned char *)binary_exponential_buffer_data(
          buffer))[binary_exponential_buffer_size(buffer) - 1] =
          (unsigned char)('0' + (int)digit);
      leading_zero = 0;
    } else {
      if (!leading_zero) {
        binary_exponential_buffer_increment(buffer, 1);
        ((unsigned char *)binary_exponential_buffer_data(
            buffer))[binary_exponential_buffer_size(buffer) - 1] =
            (unsigned char)('0' + (int)digit);
      }
    }
    unsigned_d = unsigned_d - (base * digit);
    base /= 10;
  }
}


x86 assembly (clang, -O0):
<add_unsigned_int_to_binary_exponential_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x3b9aca00,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1192 <add_unsigned_int_to_binary_exponential_buffer+0x62>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
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    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    1197 <add_unsigned_int_to_binary_exponential_buffer+0x67>
cmpl   $0x0,-0x18(%rbp)
je     1272 <add_unsigned_int_to_binary_exponential_buffer+0x142>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x18(%rbp)
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1201 <add_unsigned_int_to_binary_exponential_buffer+0xd1>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x31(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <binary_exponential_buffer_data@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <binary_exponential_buffer_size@plt>
mov    -0x31(%rbp),%dl
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movl   $0x0,-0x14(%rbp)
jmp    124f <add_unsigned_int_to_binary_exponential_buffer+0x11f>
cmpl   $0x0,-0x14(%rbp)
jne    124a <add_unsigned_int_to_binary_exponential_buffer+0x11a>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x41(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <binary_exponential_buffer_data@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <binary_exponential_buffer_size@plt>
mov    -0x41(%rbp),%dl
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    124f <add_unsigned_int_to_binary_exponential_buffer+0x11f>
mov    -0x4(%rbp),%eax
mov    -0x18(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x18(%rbp)
jmp    1197 <add_unsigned_int_to_binary_exponential_buffer+0x67>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_unsigned_int_to_binary_exponential_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
test   %edi,%edi
jne    116b <add_unsigned_int_to_binary_exponential_buffer+0x3b>
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    %r14,%rdi
call   1050 <binary_exponential_buffer_data@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <binary_exponential_buffer_size@plt>
cltq
movb   $0x30,-0x1(%rax,%rbx,1)
mov    $0x1,%ecx
mov    $0x3b9aca00,%ebx
mov    $0xcccccccd,%r13d
jmp    11c4 <add_unsigned_int_to_binary_exponential_buffer+0x94>
nopl   (%rax)
mov    %eax,%r12d
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
add    $0x30,%r12b
mov    %r14,%rdi
call   1050 <binary_exponential_buffer_data@plt>
mov    %rax,%rbp
mov    %r14,%rdi
call   1040 <binary_exponential_buffer_size@plt>
cltq
mov    %r12b,-0x1(%rax,%rbp,1)
xor    %ecx,%ecx
mov    %ebx,%eax
imul   %r13,%rax
shr    $0x23,%rax
mov    %r15d,%ebp
cmp    $0x9,%ebx
mov    %eax,%ebx
jbe    11ec <add_unsigned_int_to_binary_exponential_buffer+0xbc>
mov    %ebp,%eax
xor    %edx,%edx
div    %ebx
mov    %edx,%r15d
cmp    %ebp,%ebx
jbe    1180 <add_unsigned_int_to_binary_exponential_buffer+0x50>
test   %ecx,%ecx
mov    $0x1,%ecx
jne    11b0 <add_unsigned_int_to_binary_exponential_buffer+0x80>
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <binary_exponential_buffer_increment@plt>
mov    $0x30,%r12b
jmp    1194 <add_unsigned_int_to_binary_exponential_buffer+0x64>
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_unsigned_int_to_binary_exponential_buffer(i32 %0, %struct.binary_exponential_buffer* %1) {
%3 = alloca i32
%4 = alloca %struct.binary_exponential_buffer*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store %struct.binary_exponential_buffer* %1, %struct.binary_exponential_buffer** %4
store i32 1, i32* %5
store i32 1000000000, i32* %6
store i32 0, i32* %7
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%12 = call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %11, i32 1)
%13 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%14 = call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %13)
%15 = inttoptr i64 %14 to i8*
%16 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%17 = call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %16)
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
store i8 48, i8* %20
br label %21
21: ; preds = %10, %2
br label %22
22: ; preds = %63, %21
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %71
25: ; preds = %22
%26 = load i32, i32* %3
%27 = load i32, i32* %6
%28 = udiv i32 %26, %27
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %45
31: ; preds = %25
%32 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%33 = call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %32, i32 1)
%34 = load i32, i32* %7
%35 = add nsw i32 48, %34
%36 = trunc i32 %35 to i8
%37 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%38 = call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %37)
%39 = inttoptr i64 %38 to i8*
%40 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%41 = call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %40)
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %39, i64 %43
store i8 %36, i8* %44
store i32 0, i32* %5
br label %63
45: ; preds = %25
%46 = load i32, i32* %5
%47 = icmp ne i32 %46, 0
br i1 %47, label %62, label %48
48: ; preds = %45
%49 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%50 = call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %49, i32 1)
%51 = load i32, i32* %7
%52 = add nsw i32 48, %51
%53 = trunc i32 %52 to i8
%54 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%55 = call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %54)
%56 = inttoptr i64 %55 to i8*
%57 = load %struct.binary_exponential_buffer*, %struct.binary_exponential_buffer** %4
%58 = call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %57)
%59 = sub nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %56, i64 %60
store i8 %53, i8* %61
br label %62
62: ; preds = %48, %45
br label %63
63: ; preds = %62, %31
%64 = load i32, i32* %3
%65 = load i32, i32* %6
%66 = load i32, i32* %7
%67 = mul i32 %65, %66
%68 = sub i32 %64, %67
store i32 %68, i32* %3
%69 = load i32, i32* %6
%70 = udiv i32 %69, 10
store i32 %70, i32* %6
br label %22
71: ; preds = %22
ret void
}

LLVM IR (-O2):
%struct.binary_exponential_buffer = type { i32 }
define void @add_unsigned_int_to_binary_exponential_buffer(i32 %0, %struct.binary_exponential_buffer* %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = tail call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %1, i32 1)
%6 = tail call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %1)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %1)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8 48, i8* %11
br label %12
12: ; preds = %4, %2
br label %13
13: ; preds = %12, %36
%14 = phi i32 [ %39, %36 ], [ 1000000000, %12 ]
%15 = phi i32 [ %37, %36 ], [ 1, %12 ]
%16 = phi i32 [ %18, %36 ], [ %0, %12 ]
%17 = udiv i32 %16, %14
%18 = urem i32 %16, %14
%19 = icmp ugt i32 %14, %16
br i1 %19, label %24, label %20
20: ; preds = %13
%21 = tail call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %1, i32 1)
%22 = trunc i32 %17 to i8
%23 = add i8 %22, 48
br label %28
24: ; preds = %13
%25 = icmp eq i32 %15, 0
br i1 %25, label %26, label %36
26: ; preds = %24
%27 = tail call i32 @binary_exponential_buffer_increment(%struct.binary_exponential_buffer* %1, i32 1)
br label %28
28: ; preds = %20, %26
%29 = phi i8 [ 48, %26 ], [ %23, %20 ]
%30 = tail call i64 @binary_exponential_buffer_data(%struct.binary_exponential_buffer* %1)
%31 = inttoptr i64 %30 to i8*
%32 = tail call i32 @binary_exponential_buffer_size(%struct.binary_exponential_buffer* %1)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 %29, i8* %35
br label %36
36: ; preds = %28, %24
%37 = phi i32 [ 1, %24 ], [ 0, %28 ]
%38 = mul nuw i32 %17, %14
%39 = udiv i32 %14, 10
%40 = icmp ult i32 %14, 10
br i1 %40, label %41, label %13
41: ; preds = %36
ret void
}