#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 *, ...);
char *model_to_str(int model) {
  static int buf_cnt = 0;
  static char buf[8][32];
  if (++buf_cnt >= (sizeof(buf) / sizeof(buf[0])))
    buf_cnt = 0;
  if (model == 1)
    sprintf(buf[buf_cnt], "1st");
  else if (model == 2)
    sprintf(buf[buf_cnt], "2nd");
  else if (model == 3)
    sprintf(buf[buf_cnt], "3rd");
  else
    sprintf(buf[buf_cnt], "%dth", model);
  return buf[buf_cnt];
}


x86 assembly (clang, -O0):
<model_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 <model_to_str+0x30>
movl   $0x0,0x2f00(%rip)
cmpl   $0x1,-0x4(%rbp)
jne    1172 <model_to_str+0x62>
movslq 0x2eef(%rip),%rax
lea    0x2ef8(%rip),%rdi
shl    $0x5,%rax
add    %rax,%rdi
lea    0xe9a(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1206 <model_to_str+0xf6>
cmpl   $0x2,-0x4(%rbp)
jne    11a4 <model_to_str+0x94>
movslq 0x2ebd(%rip),%rax
lea    0x2ec6(%rip),%rdi
shl    $0x5,%rax
add    %rax,%rdi
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1201 <model_to_str+0xf1>
cmpl   $0x3,-0x4(%rbp)
jne    11d6 <model_to_str+0xc6>
movslq 0x2e8b(%rip),%rax
lea    0x2e94(%rip),%rdi
shl    $0x5,%rax
add    %rax,%rdi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11fc <model_to_str+0xec>
movslq 0x2e63(%rip),%rax
lea    0x2e6c(%rip),%rdi
shl    $0x5,%rax
add    %rax,%rdi
mov    -0x4(%rbp),%edx
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1201 <model_to_str+0xf1>
jmp    1206 <model_to_str+0xf6>
movslq 0x2e33(%rip),%rcx
lea    0x2e3c(%rip),%rax
shl    $0x5,%rcx
add    %rcx,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<model_to_str>:
push   %rax
mov    0x2f29(%rip),%ecx
add    $0x1,%ecx
xor    %eax,%eax
cmp    $0x8,%ecx
cmovb  %ecx,%eax
mov    %eax,0x2f18(%rip)
cmp    $0x3,%edi
je     114f <model_to_str+0x3f>
mov    %edi,%edx
cmp    $0x2,%edi
je     1165 <model_to_str+0x55>
cmp    $0x1,%edx
jne    117b <model_to_str+0x6b>
mov    %eax,%ecx
shl    $0x5,%rcx
lea    0x2f0a(%rip),%rdx
movl   $0x747331,(%rcx,%rdx,1)
jmp    119f <model_to_str+0x8f>
mov    %eax,%ecx
shl    $0x5,%rcx
lea    0x2ef4(%rip),%rdx
movl   $0x647233,(%rcx,%rdx,1)
jmp    119f <model_to_str+0x8f>
mov    %eax,%ecx
shl    $0x5,%rcx
lea    0x2ede(%rip),%rdx
movl   $0x646e32,(%rcx,%rdx,1)
jmp    119f <model_to_str+0x8f>
mov    %eax,%eax
shl    $0x5,%rax
lea    0x2ec8(%rip),%rdi
add    %rax,%rdi
lea    0xe6e(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    0x2ea1(%rip),%eax
movslq %eax,%rcx
shl    $0x5,%rcx
lea    0x2ea3(%rip),%rax
add    %rcx,%rax
pop    %rcx
ret

LLVM IR (-O0):
@model_to_str.buf_cnt = internal global i32 0
@model_to_str.buf = internal global [8 x [32 x i8]] zeroinitializer
@.str = [4 x i8] c"1st\00"
@.str.1 = [4 x i8] c"2nd\00"
@.str.2 = [4 x i8] c"3rd\00"
@.str.3 = [5 x i8] c"%dth\00"
define i8* @model_to_str(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @model_to_str.buf_cnt
%4 = add nsw i32 %3, 1
store i32 %4, i32* @model_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* @model_to_str.buf_cnt
br label %8
8: ; preds = %7, %1
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i32, i32* @model_to_str.buf_cnt
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @model_to_str.buf, i64 0, i64 %13
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %14, i64 0, i64 0
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %44
17: ; preds = %8
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = load i32, i32* @model_to_str.buf_cnt
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @model_to_str.buf, i64 0, i64 %22
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %23, i64 0, i64 0
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %43
26: ; preds = %17
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 3
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* @model_to_str.buf_cnt
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @model_to_str.buf, i64 0, i64 %31
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %32, i64 0, i64 0
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %42
35: ; preds = %26
%36 = load i32, i32* @model_to_str.buf_cnt
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @model_to_str.buf, i64 0, i64 %37
%39 = getelementptr inbounds [32 x i8], [32 x i8]* %38, i64 0, i64 0
%40 = load i32, i32* %2
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %35, %29
br label %43
43: ; preds = %42, %20
br label %44
44: ; preds = %43, %11
%45 = load i32, i32* @model_to_str.buf_cnt
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @model_to_str.buf, i64 0, i64 %46
%48 = getelementptr inbounds [32 x i8], [32 x i8]* %47, i64 0, i64 0
ret i8* %48
}

LLVM IR (-O2):
@model_to_str.buf_cnt = internal unnamed_addr global i32 0
@model_to_str.buf = internal global [8 x [32 x i8]] zeroinitializer
@.str.3 = [5 x i8] c"%dth\00"
define i8* @model_to_str(i32 %0) {
%2 = load i32, i32* @model_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* @model_to_str.buf_cnt
switch i32 %0, label %18 [
i32 1, label %6
i32 2, label %10
i32 3, label %14
]
6: ; preds = %1
%7 = zext i32 %5 to i64
%8 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @model_to_str.buf, i64 0, i64 %7, i64 0
%9 = bitcast i8* %8 to i32*
store i32 7631665, i32* %9
br label %23
10: ; preds = %1
%11 = zext i32 %5 to i64
%12 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @model_to_str.buf, i64 0, i64 %11, i64 0
%13 = bitcast i8* %12 to i32*
store i32 6581810, i32* %13
br label %23
14: ; preds = %1
%15 = zext i32 %5 to i64
%16 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @model_to_str.buf, i64 0, i64 %15, i64 0
%17 = bitcast i8* %16 to i32*
store i32 6582835, i32* %17
br label %23
18: ; preds = %1
%19 = zext i32 %5 to i64
%20 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @model_to_str.buf, i64 0, i64 %19, i64 0
%21 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%22 = load i32, i32* @model_to_str.buf_cnt
br label %23
23: ; preds = %10, %18, %14, %6
%24 = phi i32 [ %5, %10 ], [ %22, %18 ], [ %5, %14 ], [ %5, %6 ]
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [8 x [32 x i8]], [8 x [32 x i8]]* @model_to_str.buf, i64 0, i64 %25, i64 0
ret i8* %26
}