#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
char *count_to_var_name(uint32_t count) {
  char *name;
  if (count < 27) {
    name = (char *)malloc(sizeof(char) + 1);
    name[0] = 'a' + count - 1;
    name[1] = '\0';
    return name;
  }
  if (count > 26 && count < 677) {
    name = (char *)malloc(sizeof(char) * 2 + 1);
    name[0] = 'a' + (count / 26) - 1;
    name[1] = 'a' + (count % 26) - 1;
    name[2] = '\0';
    return name;
  }
  printf("Error, can't resolve %d to a variable\n", count);
  exit(1);
}


x86 assembly (clang, -O0):
<count_to_var_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x1b,-0xc(%rbp)
jge    1179 <count_to_var_name+0x49>
mov    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x61,%eax
sub    $0x1,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <count_to_var_name+0xd1>
cmpl   $0x1a,-0xc(%rbp)
jle    11e8 <count_to_var_name+0xb8>
cmpl   $0x2a5,-0xc(%rbp)
jge    11e8 <count_to_var_name+0xb8>
mov    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%eax
sub    $0x1,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x61,%eax
sub    $0x1,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <count_to_var_name+0xd1>
mov    -0xc(%rbp),%esi
lea    0xe0e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_to_var_name>:
push   %rbx
mov    %edi,%ebx
cmp    $0x1a,%edi
jg     1150 <count_to_var_name+0x20>
mov    $0x2,%edi
call   1040 <malloc@plt>
add    $0x60,%bl
mov    %bl,(%rax)
mov    %rax,%rcx
add    $0x1,%rcx
jmp    118a <count_to_var_name+0x5a>
cmp    $0x2a4,%ebx
ja     118f <count_to_var_name+0x5f>
mov    $0x3,%edi
call   1040 <malloc@plt>
movzwl %bx,%ecx
imul   $0x4ec5,%ecx,%ecx
shr    $0x13,%ecx
lea    0x60(%rcx),%edx
mov    %dl,(%rax)
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%ebx
or     $0x60,%bl
mov    %bl,0x1(%rax)
mov    %rax,%rcx
add    $0x2,%rcx
movb   $0x0,(%rcx)
pop    %rbx
ret
lea    0xe6a(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"Error, can't resolve %d to a variable\0A\00"
define i8* @count_to_var_name(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 27
br i1 %6, label %7, label %19
7: ; preds = %1
%8 = call i64 @malloc(i32 2)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
%10 = load i32, i32* %3
%11 = add nsw i32 97, %10
%12 = sub nsw i32 %11, 1
%13 = trunc i32 %12 to i8
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 0
store i8 %13, i8* %15
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 0, i8* %17
%18 = load i8*, i8** %4
store i8* %18, i8** %2
br label %49
19: ; preds = %1
%20 = load i32, i32* %3
%21 = icmp sgt i32 %20, 26
br i1 %21, label %22, label %45
22: ; preds = %19
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 677
br i1 %24, label %25, label %45
25: ; preds = %22
%26 = call i64 @malloc(i32 3)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %4
%28 = load i32, i32* %3
%29 = sdiv i32 %28, 26
%30 = add nsw i32 97, %29
%31 = sub nsw i32 %30, 1
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 0
store i8 %32, i8* %34
%35 = load i32, i32* %3
%36 = srem i32 %35, 26
%37 = add nsw i32 97, %36
%38 = sub nsw i32 %37, 1
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 1
store i8 %39, i8* %41
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i64 2
store i8 0, i8* %43
%44 = load i8*, i8** %4
store i8* %44, i8** %2
br label %49
45: ; preds = %22, %19
%46 = load i32, i32* %3
%47 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %46)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %25, %7
%50 = load i8*, i8** %2
ret i8* %50
}

LLVM IR (-O2):
@.str = [39 x i8] c"Error, can't resolve %d to a variable\0A\00"
define i8* @count_to_var_name(i32 %0) {
%2 = icmp slt i32 %0, 27
br i1 %2, label %3, label %9
3: ; preds = %1
%4 = tail call i64 @malloc(i32 2)
%5 = inttoptr i64 %4 to i8*
%6 = trunc i32 %0 to i8
%7 = add i8 %6, 96
store i8 %7, i8* %5
%8 = getelementptr inbounds i8, i8* %5, i64 1
br label %26
9: ; preds = %1
%10 = icmp ult i32 %0, 677
br i1 %10, label %11, label %23
11: ; preds = %9
%12 = tail call i64 @malloc(i32 3)
%13 = inttoptr i64 %12 to i8*
%14 = trunc i32 %0 to i16
%15 = udiv i16 %14, 26
%16 = trunc i16 %15 to i8
%17 = add nuw nsw i8 %16, 96
store i8 %17, i8* %13
%18 = urem i16 %14, 26
%19 = trunc i16 %18 to i8
%20 = or i8 %19, 96
%21 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %20, i8* %21
%22 = getelementptr inbounds i8, i8* %13, i64 2
br label %26
23: ; preds = %9
%24 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %0)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %11, %3
%27 = phi i8* [ %22, %11 ], [ %8, %3 ]
%28 = phi i8* [ %13, %11 ], [ %5, %3 ]
store i8 0, i8* %27
ret i8* %28
}