#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*/ sprintf(char *, char *, int);
int strlen(char *);
char *int2str(int number, int size) {
  static char shift_array[10][40];
  static int shift_counter = 0;
  char *s = shift_array[shift_counter];
  shift_counter = (shift_counter + 1) % 10;
  if (size > 20)
    size = 20;
  if (size > 0) {
    sprintf(s, "                    %09d", number);
    return &s[strlen(s) - size];
  } else {
    sprintf(s, "%d", number);
    return s;
  }
}


x86 assembly (clang, -O0):
<int2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movslq 0x309b(%rip),%rcx
lea    0x2f04(%rip),%rax
imul   $0x28,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    0x3083(%rip),%eax
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,0x3072(%rip)
cmpl   $0x14,-0x10(%rbp)
jle    116f <int2str+0x4f>
movl   $0x14,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11b5 <int2str+0x95>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe79(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11d0 <int2str+0xb0>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe56(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int2str>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%edx
mov    0x30a5(%rip),%eax
lea    (%rax,%rax,4),%rcx
lea    0x2f0a(%rip),%rdi
lea    (%rdi,%rcx,8),%rbx
add    $0x1,%eax
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rcx
add    %edi,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,0x3070(%rip)
test   %esi,%esi
jle    118f <int2str+0x6f>
cmp    $0x14,%esi
mov    $0x14,%ebp
cmovb  %esi,%ebp
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
sub    %ebp,%eax
cltq
add    %rax,%rbx
jmp    119e <int2str+0x7e>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@int2str.shift_array = internal global [10 x [40 x i8]] zeroinitializer
@int2str.shift_counter = internal global i32 0
@.str = [25 x i8] c" %09d\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @int2str(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* @int2str.shift_counter
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [10 x [40 x i8]], [10 x [40 x i8]]* @int2str.shift_array, i64 0, i64 %8
%10 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
store i8* %10, i8** %6
%11 = load i32, i32* @int2str.shift_counter
%12 = add nsw i32 %11, 1
%13 = srem i32 %12, 10
store i32 %13, i32* @int2str.shift_counter
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 20
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 20, i32* %5
br label %17
17: ; preds = %16, %2
%18 = load i32, i32* %5
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = load i32, i32* %4
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = load i8*, i8** %6
%25 = load i8*, i8** %6
%26 = call i32 @strlen(i8* %25)
%27 = load i32, i32* %5
%28 = sub nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %24, i64 %29
store i8* %30, i8** %3
br label %36
31: ; preds = %17
%32 = load i8*, i8** %6
%33 = load i32, i32* %4
%34 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = load i8*, i8** %6
store i8* %35, i8** %3
br label %36
36: ; preds = %31, %20
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
@int2str.shift_array = internal global [10 x [40 x i8]] zeroinitializer
@int2str.shift_counter = internal unnamed_addr global i32 0
@.str = [25 x i8] c" %09d\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @int2str(i32 %0, i32 %1) {
%3 = load i32, i32* @int2str.shift_counter
%4 = zext i32 %3 to i64
%5 = getelementptr inbounds [10 x [40 x i8]], [10 x [40 x i8]]* @int2str.shift_array, i64 0, i64 %4, i64 0
%6 = add nsw i32 %3, 1
%7 = srem i32 %6, 10
store i32 %7, i32* @int2str.shift_counter
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = icmp ult i32 %1, 20
%11 = select i1 %10, i32 %1, i32 20
%12 = tail call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0)
%13 = tail call i32 @strlen(i8* %5)
%14 = sub nsw i32 %13, %11
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [10 x [40 x i8]], [10 x [40 x i8]]* @int2str.shift_array, i64 0, i64 %4, i64 %15
br label %19
17: ; preds = %2
%18 = tail call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %19
19: ; preds = %17, %9
%20 = phi i8* [ %16, %9 ], [ %5, %17 ]
ret i8* %20
}