#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) {
  char *ret, *ptr;
  int nn = n, len = 0;
  while (nn) {
    ++len;
    nn = (nn - 1) / 26;
  }
  ret = (char *)malloc((len + 1) * sizeof(char));
  ptr = ret + len;
  *ptr = 0;
  while (n) {
    *--ptr = --n % 26 + 'A';
    n /= 26;
  }
  return ret;
}


x86 assembly (clang, -O0):
<convertToTitle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1151 <convertToTitle+0x41>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
jmp    1128 <convertToTitle+0x18>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x4(%rbp)
je     11c3 <convertToTitle+0xb3>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x4(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    117e <convertToTitle+0x6e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertToTitle>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     11b3 <convertToTitle+0xa3>
mov    %edi,%r14d
mov    $0xffffffffffffffff,%rbx
mov    %edi,%eax
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rax),%ecx
movslq %ecx,%rcx
imul   $0x4ec4ec4f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
add    $0x18,%eax
add    $0x1,%rbx
cmp    $0x32,%eax
mov    %ecx,%eax
ja     1130 <convertToTitle+0x20>
lea    0x2(%rbx),%edi
call   1030 <malloc@plt>
movb   $0x0,0x1(%rax,%rbx,1)
test   %r14d,%r14d
je     11c0 <convertToTitle+0xb0>
add    %rax,%rbx
nopl   (%rax)
lea    -0x1(%r14),%ecx
movslq %ecx,%rcx
imul   $0x4ec4ec4f,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
neg    %edx
add    %r14d,%edx
add    $0xffffffff,%edx
add    $0x41,%dl
mov    %dl,(%rbx)
add    $0x18,%r14d
add    $0xffffffffffffffff,%rbx
cmp    $0x32,%r14d
mov    %ecx,%r14d
ja     1170 <convertToTitle+0x60>
jmp    11c0 <convertToTitle+0xb0>
mov    $0x1,%edi
call   1030 <malloc@plt>
movb   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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