#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 */
scalar_t__ malloc(int);
char *convertToTitle(int n) {
  int i = 0;
  char *ret = (char *)malloc(sizeof(char) * 8);
  i = 7;
  ret[i--] = '\0';
  while (n) {
    ret[i--] = (n - 1) % 26 + 'A';
    n = (n - 1) / 26;
  }
  return ret + i + 1;
}


x86 assembly (clang, -O0):
<convertToTitle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x7,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x8(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x4(%rbp)
je     1193 <convertToTitle+0x83>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %ecx,%esi
add    $0xffffffff,%esi
mov    %esi,-0x8(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    114d <convertToTitle+0x3d>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertToTitle>:
push   %rbx
mov    %edi,%ebx
mov    $0x8,%edi
call   1030 <malloc@plt>
movb   $0x0,0x7(%rax)
test   %ebx,%ebx
je     1187 <convertToTitle+0x77>
lea    0x6(%rax),%rdx
movabs $0x600000000,%rcx
movabs $0xffffffff00000000,%r8
ff ff ff
nopl   (%rax)
add    %r8,%rcx
lea    -0x1(%rbx),%edi
movslq %edi,%rdi
imul   $0x4ec4ec4f,%rdi,%rdi
mov    %rdi,%rsi
shr    $0x3f,%rsi
sar    $0x23,%rdi
add    %esi,%edi
lea    (%rdi,%rdi,4),%esi
lea    (%rsi,%rsi,4),%esi
add    %edi,%esi
neg    %esi
add    %ebx,%esi
add    $0xffffffff,%esi
add    $0x41,%sil
mov    %sil,(%rdx)
add    $0x18,%ebx
add    $0xffffffffffffffff,%rdx
cmp    $0x32,%ebx
mov    %edi,%ebx
ja     1140 <convertToTitle+0x30>
sar    $0x20,%rcx
jmp    118c <convertToTitle+0x7c>
mov    $0x6,%ecx
add    %rcx,%rax
add    $0x1,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @convertToTitle(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = call i64 @malloc(i32 8)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %4
store i32 7, i32* %3
%7 = load i8*, i8** %4
%8 = load i32, i32* %3
%9 = add nsw i32 %8, -1
store i32 %9, i32* %3
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %15, %1
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, 1
%18 = srem i32 %17, 26
%19 = add nsw i32 %18, 65
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %4
%22 = load i32, i32* %3
%23 = add nsw i32 %22, -1
store i32 %23, i32* %3
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 %20, i8* %25
%26 = load i32, i32* %2
%27 = sub nsw i32 %26, 1
%28 = sdiv i32 %27, 26
store i32 %28, i32* %2
br label %12
29: ; preds = %12
%30 = load i8*, i8** %4
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 1
ret i8* %34
}

LLVM IR (-O2):
define i8* @convertToTitle(i32 %0) {
%2 = tail call i64 @malloc(i32 8)
%3 = inttoptr i64 %2 to i8*
%4 = getelementptr inbounds i8, i8* %3, i64 7
store i8 0, i8* %4
%5 = icmp eq i32 %0, 0
br i1 %5, label %21, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %13, %6 ], [ 6, %1 ]
%8 = phi i32 [ %15, %6 ], [ %0, %1 ]
%9 = add nsw i32 %8, -1
%10 = srem i32 %9, 26
%11 = trunc i32 %10 to i8
%12 = add nsw i8 %11, 65
%13 = add i64 %7, -1
%14 = getelementptr inbounds i8, i8* %3, i64 %7
store i8 %12, i8* %14
%15 = sdiv i32 %9, 26
%16 = add i32 %8, 24
%17 = icmp ult i32 %16, 51
br i1 %17, label %18, label %6
18: ; preds = %6
%19 = shl i64 %13, 32
%20 = ashr exact i64 %19, 32
br label %21
21: ; preds = %18, %1
%22 = phi i64 [ 6, %1 ], [ %20, %18 ]
%23 = getelementptr inbounds i8, i8* %3, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 1
ret i8* %24
}