#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
char *jewel_to_str(int jewel) {
  static int buf_cnt = 0;
  static char buf[8][32];
  if (++buf_cnt >= (sizeof(buf) / sizeof(buf[0])))
    buf_cnt = 0;
  sprintf(buf[buf_cnt], "%d", jewel);
  return buf[buf_cnt];
}


x86 assembly (clang, -O0):
<jewel_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2f1f(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f16(%rip)
cltq
cmp    $0x8,%rax
jb     1140 <jewel_to_str+0x30>
movl   $0x0,0x2f00(%rip)
movslq 0x2ef9(%rip),%rax
lea    0x2f02(%rip),%rdi
shl    $0x5,%rax
add    %rax,%rdi
mov    -0x4(%rbp),%edx
lea    0xea1(%rip),%rsi
call   1030 <sprintf@plt>
movslq 0x2ed5(%rip),%rcx
lea    0x2ede(%rip),%rax
shl    $0x5,%rcx
add    %rcx,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jewel_to_str>:
push   %rbx
mov    %edi,%edx
mov    0x2f27(%rip),%eax
add    $0x1,%eax
xor    %edi,%edi
cmp    $0x8,%eax
cmovb  %eax,%edi
mov    %edi,0x2f16(%rip)
shl    $0x5,%rdi
lea    0x2f1b(%rip),%rbx
add    %rbx,%rdi
lea    0xec1(%rip),%rsi
call   1030 <sprintf@plt>
movslq 0x2ef5(%rip),%rax
shl    $0x5,%rax
add    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@jewel_to_str.buf_cnt = internal global i32 0
@jewel_to_str.buf = internal global [8 x [32 x i8]] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @jewel_to_str(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @jewel_to_str.buf_cnt
%4 = add nsw i32 %3, 1
store i32 %4, i32* @jewel_to_str.buf_cnt
%5 = sext i32 %4 to i64
%6 = icmp uge i64 %5, 8
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* @jewel_to_str.buf_cnt
br label %8
8: ; preds = %7, %1
%9 = load i32, i32* @jewel_to_str.buf_cnt
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @jewel_to_str.buf, i64 0, i64 %10
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%13 = load i32, i32* %2
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @jewel_to_str.buf_cnt
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @jewel_to_str.buf, i64 0, i64 %16
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 0
ret i8* %18
}

LLVM IR (-O2):
@jewel_to_str.buf_cnt = internal unnamed_addr global i32 0
@jewel_to_str.buf = internal global [8 x [32 x i8]] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @jewel_to_str(i32 %0) {
%2 = load i32, i32* @jewel_to_str.buf_cnt
%3 = add nsw i32 %2, 1
%4 = icmp ugt i32 %3, 7
%5 = select i1 %4, i32 0, i32 %3
store i32 %5, i32* @jewel_to_str.buf_cnt
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @jewel_to_str.buf, i64 0, i64 %6, i64 0
%8 = tail call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = load i32, i32* @jewel_to_str.buf_cnt
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @jewel_to_str.buf, i64 0, i64 %10, i64 0
ret i8* %11
}