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

/* Variables and functions */
int /*<<< orphan*/ add_char_to_string(char, struct string_w_size *);
int /*<<< orphan*/ reverse_string(struct string_w_size *);
void print_int_to_string(int value, struct string_w_size *str) {
  char print_index[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  while (value > 0) {
    int subtractValue = (value / 10) * 10;
    int printValue = value - subtractValue;
    add_char_to_string(print_index[printValue], str);
    value = value / 10;
  }
  reverse_string(str);
}


x86 assembly (clang, -O0):
<print_int_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x1a(%rbp)
mov    0xec7(%rip),%ax
mov    %ax,-0x12(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1190 <print_int_to_string+0x70>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
imul   $0xa,%eax,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
mov    -0x1a(%rbp,%rax,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <add_char_to_string@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1145 <print_int_to_string+0x25>
mov    -0x10(%rbp),%rdi
call   1030 <reverse_string@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_int_to_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
test   %edi,%edi
jle    1172 <print_int_to_string+0x52>
mov    $0xcccccccd,%r14d
lea    0xec3(%rip),%r15
nopl   (%rax)
mov    %edi,%ebx
imul   %r14,%rbx
shr    $0x23,%rbx
mov    %rbx,%rax
add    %rbx,%rax
lea    (%rax,%rax,4),%rax
movslq %edi,%r13
mov    %r13,%rcx
sub    %rax,%rcx
movsbl (%rcx,%r15,1),%edi
mov    %r12,%rsi
call   1040 <add_char_to_string@plt>
mov    %ebx,%edi
cmp    $0x9,%r13d
ja     1140 <print_int_to_string+0x20>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <reverse_string@plt>

LLVM IR (-O0):
%struct.string_w_size = type { i32 }
@__const.print_int_to_string.print_index = [10 x i8] c"0123456789"
define void @print_int_to_string(i32 %0, %struct.string_w_size* %1) {
%3 = alloca i32
%4 = alloca %struct.string_w_size*
%5 = alloca [10 x i8]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store %struct.string_w_size* %1, %struct.string_w_size** %4
%8 = bitcast [10 x i8]* %5 to i8*
br label %9
9: ; preds = %12, %2
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = load i32, i32* %3
%14 = sdiv i32 %13, 10
%15 = mul nsw i32 %14, 10
store i32 %15, i32* %6
%16 = load i32, i32* %3
%17 = load i32, i32* %6
%18 = sub nsw i32 %16, %17
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = load %struct.string_w_size*, %struct.string_w_size** %4
%24 = call i32 @add_char_to_string(i8 signext %22, %struct.string_w_size* %23)
%25 = load i32, i32* %3
%26 = sdiv i32 %25, 10
store i32 %26, i32* %3
br label %9
27: ; preds = %9
%28 = load %struct.string_w_size*, %struct.string_w_size** %4
%29 = call i32 @reverse_string(%struct.string_w_size* %28)
ret void
}

LLVM IR (-O2):
%struct.string_w_size = type { i32 }
@__const.print_int_to_string.print_index = [10 x i8] c"0123456789"
define void @print_int_to_string(i32 %0, %struct.string_w_size* %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %14
4: ; preds = %2, %4
%5 = phi i32 [ %6, %4 ], [ %0, %2 ]
%6 = udiv i32 %5, 10
%7 = mul nsw i32 %6, -10
%8 = add nsw i32 %7, %5
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [10 x i8], [10 x i8]* @__const.print_int_to_string.print_index, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @add_char_to_string(i8 signext %11, %struct.string_w_size* %1)
%13 = icmp ult i32 %5, 10
br i1 %13, label %14, label %4
14: ; preds = %4, %2
%15 = tail call i32 @reverse_string(%struct.string_w_size* %1)
ret void
}