#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 */
int strlen(char *);
void insere_letra(char *buf, unsigned char idx) {
  int len = strlen(buf);
  char letra;
  if (idx < 10)
    letra = '0' + idx;
  else if (idx < 36)
    letra = 'a' + idx - 10;
  buf[len] = letra;
  buf[len + 1] = '\0';
}


x86 assembly (clang, -O0):
<insere_letra>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jge    114a <insere_letra+0x3a>
movzbl -0x9(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x11(%rbp)
jmp    1169 <insere_letra+0x59>
movzbl -0x9(%rbp),%eax
cmp    $0x24,%eax
jge    1164 <insere_letra+0x54>
movzbl -0x9(%rbp),%eax
add    $0x61,%eax
sub    $0xa,%eax
mov    %al,-0x11(%rbp)
jmp    1169 <insere_letra+0x59>
mov    -0x11(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insere_letra>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0xa,%bpl
mov    $0x30,%ecx
mov    $0x57,%edx
cmovb  %ecx,%edx
add    %bpl,%dl
cltq
mov    %dl,(%rbx,%rax,1)
movb   $0x0,0x1(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @insere_letra(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8, i8* %4
%14 = zext i8 %13 to i32
%15 = add nsw i32 48, %14
%16 = trunc i32 %15 to i8
store i8 %16, i8* %6
br label %28
17: ; preds = %2
%18 = load i8, i8* %4
%19 = zext i8 %18 to i32
%20 = icmp slt i32 %19, 36
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i8, i8* %4
%23 = zext i8 %22 to i32
%24 = add nsw i32 97, %23
%25 = sub nsw i32 %24, 10
%26 = trunc i32 %25 to i8
store i8 %26, i8* %6
br label %27
27: ; preds = %21, %17
br label %28
28: ; preds = %27, %12
%29 = load i8, i8* %6
%30 = load i8*, i8** %3
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
%34 = load i8*, i8** %3
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 0, i8* %38
ret void
}

LLVM IR (-O2):
define void @insere_letra(i8* %0, i8 zeroext %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp ult i8 %1, 10
%5 = select i1 %4, i8 48, i8 87
%6 = add i8 %5, %1
%7 = sext i32 %3 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 %6, i8* %8
%9 = add nsw i32 %3, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %11
ret void
}