#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 snprintf(char *, int, char *, unsigned int);
int /*<<< orphan*/ strcpy(char *, char *);
size_t simplestr_count_to_str(char *buf, size_t size, unsigned int count) {
  if (buf == NULL)
    return 0;
  switch (count) {
  case 0:
    if (size <= 12)
      return 0;
    strcpy(buf, "indefinitely");
    return 12;
  case 1:
    if (size <= 12)
      return 0;
    strcpy(buf, "exactly once");
    return 12;
  default: {
    int ret = snprintf(buf, (int)size, "%u times", count);
    if (ret <= 0 || ((size_t)ret) >= size)
      return 0;
    return (size_t)ret;
  }
  }
  return 0;
}


x86 assembly (clang, -O0):
<simplestr_count_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114b <simplestr_count_to_str+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    1222 <simplestr_count_to_str+0x102>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
test   %eax,%eax
je     116f <simplestr_count_to_str+0x4f>
jmp    115e <simplestr_count_to_str+0x3e>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
je     11a4 <simplestr_count_to_str+0x84>
jmp    11d9 <simplestr_count_to_str+0xb9>
cmpq   $0xc,-0x18(%rbp)
ja     1187 <simplestr_count_to_str+0x67>
movq   $0x0,-0x8(%rbp)
jmp    1222 <simplestr_count_to_str+0x102>
mov    -0x10(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1030 <strcpy@plt>
movq   $0xc,-0x8(%rbp)
jmp    1222 <simplestr_count_to_str+0x102>
cmpq   $0xc,-0x18(%rbp)
ja     11bc <simplestr_count_to_str+0x9c>
movq   $0x0,-0x8(%rbp)
jmp    1222 <simplestr_count_to_str+0x102>
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcpy@plt>
movq   $0xc,-0x8(%rbp)
jmp    1222 <simplestr_count_to_str+0x102>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    -0x1c(%rbp),%ecx
lea    0xe2d(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    120d <simplestr_count_to_str+0xed>
movslq -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     121a <simplestr_count_to_str+0xfa>
movq   $0x0,-0x8(%rbp)
jmp    1222 <simplestr_count_to_str+0x102>
movslq -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simplestr_count_to_str>:
push   %rbx
test   %rdi,%rdi
je     117b <simplestr_count_to_str+0x5b>
mov    %edx,%ecx
mov    %rsi,%rbx
cmp    $0x1,%edx
je     1143 <simplestr_count_to_str+0x23>
test   %ecx,%ecx
jne    115c <simplestr_count_to_str+0x3c>
cmp    $0xd,%rbx
jb     117b <simplestr_count_to_str+0x5b>
lea    0xebf(%rip),%rsi
jmp    1150 <simplestr_count_to_str+0x30>
cmp    $0xd,%rbx
jb     117b <simplestr_count_to_str+0x5b>
lea    0xebd(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0xc,%eax
pop    %rbx
ret
lea    0xeb7(%rip),%rdx
mov    %ebx,%esi
call   1040 <snprintf@plt>
test   %eax,%eax
jle    117b <simplestr_count_to_str+0x5b>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %rbx,%rcx
cmovb  %rcx,%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"indefinitely\00"
@.str.1 = [13 x i8] c"exactly once\00"
@.str.2 = [9 x i8] c"%u times\00"
define i64 @simplestr_count_to_str(i8* %0, i64 %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %3
store i64 0, i64* %4
br label %45
12: ; preds = %3
%13 = load i32, i32* %7
switch i32 %13, label %28 [
i32 0, label %14
i32 1, label %21
]
14: ; preds = %12
%15 = load i64, i64* %6
%16 = icmp ule i64 %15, 12
br i1 %16, label %17, label %18
17: ; preds = %14
store i64 0, i64* %4
br label %45
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i64 12, i64* %4
br label %45
21: ; preds = %12
%22 = load i64, i64* %6
%23 = icmp ule i64 %22, 12
br i1 %23, label %24, label %25
24: ; preds = %21
store i64 0, i64* %4
br label %45
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i64 12, i64* %4
br label %45
28: ; preds = %12
%29 = load i8*, i8** %5
%30 = load i64, i64* %6
%31 = trunc i64 %30 to i32
%32 = load i32, i32* %7
%33 = call i32 @snprintf(i8* %29, i32 %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %32)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp sle i32 %34, 0
br i1 %35, label %41, label %36
36: ; preds = %28
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = load i64, i64* %6
%40 = icmp uge i64 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %36, %28
store i64 0, i64* %4
br label %45
42: ; preds = %36
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
store i64 %44, i64* %4
br label %45
45: ; preds = %42, %41, %25, %24, %18, %17, %11
%46 = load i64, i64* %4
ret i64 %46
}

LLVM IR (-O2):
@.str = [13 x i8] c"indefinitely\00"
@.str.1 = [13 x i8] c"exactly once\00"
@.str.2 = [9 x i8] c"%u times\00"
define i64 @simplestr_count_to_str(i8* %0, i64 %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %22, label %5
5: ; preds = %3
switch i32 %2, label %14 [
i32 0, label %6
i32 1, label %10
]
6: ; preds = %5
%7 = icmp ult i64 %1, 13
br i1 %7, label %22, label %8
8: ; preds = %6
%9 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %22
10: ; preds = %5
%11 = icmp ult i64 %1, 13
br i1 %11, label %22, label %12
12: ; preds = %10
%13 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %22
14: ; preds = %5
%15 = trunc i64 %1 to i32
%16 = tail call i32 @snprintf(i8* %0, i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%17 = icmp slt i32 %16, 1
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = zext i32 %16 to i64
%20 = icmp ult i64 %19, %1
%21 = select i1 %20, i64 %19, i64 0
br label %22
22: ; preds = %18, %14, %10, %6, %3, %12, %8
%23 = phi i64 [ 12, %12 ], [ 12, %8 ], [ 0, %3 ], [ 0, %6 ], [ 0, %10 ], [ 0, %14 ], [ %21, %18 ]
ret i64 %23
}