#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 *range_to_str(int min_val, int max_val) {
  static int buf_cnt = 0;
  static char buf[8][32];
  if (++buf_cnt >= (sizeof(buf) / sizeof(buf[0])))
    buf_cnt = 0;
  if (min_val == max_val)
    sprintf(buf[buf_cnt], "%d", min_val);
  else
    sprintf(buf[buf_cnt], "%d-%d", min_val, max_val);
  return buf[buf_cnt];
}


x86 assembly (clang, -O0):
<range_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2f1c(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f13(%rip)
cltq
cmp    $0x8,%rax
jb     1143 <range_to_str+0x33>
movl   $0x0,0x2efd(%rip)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    117a <range_to_str+0x6a>
movslq 0x2eea(%rip),%rax
lea    0x2ef3(%rip),%rdi
shl    $0x5,%rax
add    %rax,%rdi
mov    -0x4(%rbp),%edx
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11a3 <range_to_str+0x93>
movslq 0x2ebf(%rip),%rax
lea    0x2ec8(%rip),%rdi
shl    $0x5,%rax
add    %rax,%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
movslq 0x2e96(%rip),%rcx
lea    0x2e9f(%rip),%rax
shl    $0x5,%rcx
add    %rcx,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<range_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
cmp    %esi,%edx
jne    114c <range_to_str+0x3c>
lea    0xec0(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    115c <range_to_str+0x4c>
mov    %esi,%ecx
lea    0xeab(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
movslq 0x2edd(%rip),%rax
shl    $0x5,%rax
add    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

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