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


x86 assembly (clang, -O0):
<convertToTitle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x7,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cltq
movb   $0x0,-0xc(%rbp,%rax,1)
cmpl   $0x0,-0x4(%rbp)
jle    1178 <convertToTitle+0x68>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    %dl,%cl
mov    -0x10(%rbp),%eax
mov    %eax,%edx
add    $0xffffffff,%edx
mov    %edx,-0x10(%rbp)
cltq
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1134 <convertToTitle+0x24>
lea    -0xc(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1030 <strdup@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertToTitle>:
push   %rax
movb   $0x0,0x7(%rsp)
test   %edi,%edi
jle    1172 <convertToTitle+0x62>
lea    0x6(%rsp),%rcx
movabs $0x600000000,%r9
movabs $0xffffffff00000000,%r8
ff ff ff
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %r8,%r9
add    $0xffffffff,%edi
imul   $0x4ec4ec4f,%rdi,%rsi
shr    $0x23,%rsi
lea    (%rsi,%rsi,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %esi,%edx
mov    %edi,%eax
sub    %edx,%eax
add    $0x41,%al
mov    %al,(%rcx)
add    $0xffffffffffffffff,%rcx
cmp    $0x19,%edi
mov    %esi,%edi
ja     1140 <convertToTitle+0x30>
sar    $0x20,%r9
jmp    1178 <convertToTitle+0x68>
mov    $0x6,%r9d
lea    (%rsp,%r9,1),%rdi
add    $0x1,%rdi
call   1030 <strdup@plt>
pop    %rcx
ret

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

LLVM IR (-O2):
define noalias i8* @convertToTitle(i32 %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 7
store i8 0, i8* %4
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %20
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 = urem i32 %9, 26
%11 = trunc i32 %10 to i8
%12 = add nuw nsw i8 %11, 65
%13 = add i64 %7, -1
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 %7
store i8 %12, i8* %14
%15 = udiv i32 %9, 26
%16 = icmp ult i32 %9, 26
br i1 %16, label %17, label %6
17: ; preds = %6
%18 = shl i64 %13, 32
%19 = ashr exact i64 %18, 32
br label %20
20: ; preds = %17, %1
%21 = phi i64 [ 6, %1 ], [ %19, %17 ]
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = call i8* @strdup(i8* %23)
ret i8* %24
}