#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 */

/* Variables and functions */
int /*<<< orphan*/ int_to_str(char *, int, int const, size_t const);
int /*<<< orphan*/ number_of_digits(int const, size_t const);
int /*<<< orphan*/ printf(char *, int const, char *, size_t const);
void test_int_to_str(const int n, const size_t base) {
  char buffer[number_of_digits(n, base) + 1];
  int_to_str(buffer, sizeof buffer, n, base);
  printf("[%d] converts to '%s' in base %zu\n", n, buffer, base);
}


x86 assembly (clang, -O0):
<test_int_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <number_of_digits@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%esi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
call   1040 <int_to_str@plt>
mov    -0x28(%rbp),%rdx
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_int_to_str>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
call   1050 <number_of_digits@plt>
lea    0x1(%rax),%esi
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15d,%edx
mov    %r14,%rcx
call   1040 <int_to_str@plt>
lea    0xe92(%rip),%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <printf@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"[%d] converts to '%s' in base %zu\0A\00"
define void @test_int_to_str(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %3
store i64 %1, i64* %4
%7 = load i32, i32* %3
%8 = load i64, i64* %4
%9 = call i32 @number_of_digits(i32 %7, i64 %8)
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i8, i64 %11
store i64 %11, i64* %6
%14 = trunc i64 %11 to i32
%15 = load i32, i32* %3
%16 = load i64, i64* %4
%17 = call i32 @int_to_str(i8* %13, i32 %14, i32 %15, i64 %16)
%18 = load i32, i32* %3
%19 = load i64, i64* %4
%20 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %18, i8* %13, i64 %19)
%21 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"[%d] converts to '%s' in base %zu\0A\00"
define void @test_int_to_str(i32 %0, i64 %1) {
%3 = tail call i32 @number_of_digits(i32 %0, i64 %1)
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @int_to_str(i8* %6, i32 %4, i32 %0, i64 %1)
%8 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %6, i64 %1)
ret void
}