#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 *convert_to_title(int n) {
  int i;
  char *s;
  s = (char *)malloc(100);
  s[99] = '\0';
  i = 98;
  while (n > 0 && i >= 0) {
    s[i] = (n - 1) % 26 + 'A';
    n = (n - 1) / 26;
    --i;
  }
  return s + i + 1;
}


x86 assembly (clang, -O0):
<convert_to_title>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x64,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,0x63(%rax)
movl   $0x62,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x11(%rbp)
jle    1151 <convert_to_title+0x41>
cmpl   $0x0,-0x8(%rbp)
setge  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1161 <convert_to_title+0x51>
jmp    119c <convert_to_title+0x8c>
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1138 <convert_to_title+0x28>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_to_title>:
push   %rbx
mov    %edi,%ebx
mov    $0x64,%edi
call   1030 <malloc@plt>
movb   $0x0,0x63(%rax)
mov    $0x62,%ecx
test   %ebx,%ebx
jle    1164 <convert_to_title+0x54>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%esi
add    $0xffffffff,%esi
imul   $0x4ec4ec4f,%rsi,%rbx
shr    $0x23,%rbx
lea    (%rbx,%rbx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ebx,%edx
mov    %esi,%edi
sub    %edx,%edi
add    $0x41,%dil
mov    %dil,(%rax,%rcx,1)
add    $0xffffffffffffffff,%rcx
setb   %dl
cmp    $0x1a,%esi
jb     1164 <convert_to_title+0x54>
test   %dl,%dl
jne    1130 <convert_to_title+0x20>
add    %rcx,%rax
add    $0x1,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @convert_to_title(i32 %0) {
%2 = tail call i64 @malloc(i32 100)
%3 = inttoptr i64 %2 to i8*
%4 = getelementptr inbounds i8, i8* %3, i64 99
store i8 0, i8* %4
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %22
6: ; preds = %1, %6
%7 = phi i64 [ %15, %6 ], [ 98, %1 ]
%8 = phi i32 [ %14, %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 = getelementptr inbounds i8, i8* %3, i64 %7
store i8 %12, i8* %13
%14 = udiv i32 %9, 26
%15 = add nsw i64 %7, -1
%16 = icmp ugt i32 %9, 25
%17 = icmp ne i64 %7, 0
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %6, label %19
19: ; preds = %6
%20 = shl i64 %15, 32
%21 = ashr exact i64 %20, 32
br label %22
22: ; preds = %19, %1
%23 = phi i64 [ 98, %1 ], [ %21, %19 ]
%24 = getelementptr inbounds i8, i8* %3, i64 %23
%25 = getelementptr inbounds i8, i8* %24, i64 1
ret i8* %25
}