#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 *strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *_hash(int input, char *alphabet) {
  char *hash = (char *)malloc(sizeof(char));
  strcpy(hash, "");
  int alphabet_length = strlen(alphabet);
  do {
    char temp[2];
    temp[0] = alphabet[input % alphabet_length];
    temp[1] = '\0';
    strcpy(hash, strcat(temp, hash));
    input = (int)(input / alphabet_length);
  } while (input);
  return hash;
}


x86 assembly (clang, -O0):
<_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    -0x30(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1e(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x1e(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1179 <_hash+0x39>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_hash>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe9b(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0xe(%rsp),%r12
nopl   (%rax)
mov    %ebp,%eax
cltd
idiv   %r15d
movslq %edx,%rcx
movzbl (%r14,%rcx,1),%ecx
mov    %cl,0xe(%rsp)
movb   $0x0,0xf(%rsp)
mov    %eax,%ebp
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
test   %ebp,%ebp
jne    1180 <_hash+0x40>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @_hash(i32 %0, i8* %1) {
%3 = alloca [2 x i8]
%4 = tail call i64 @malloc(i32 1)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @strlen(i8* %1)
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
br label %10
10: ; preds = %10, %2
%11 = phi i32 [ %0, %2 ], [ %18, %10 ]
%12 = srem i32 %11, %7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = load i8, i8* %14
store i8 %15, i8* %8
store i8 0, i8* %9
%16 = call i8* @strcat(i8* %8, i8* dereferenceable(1) %5)
%17 = call i32 @strcpy(i8* %5, i8* %8)
%18 = sdiv i32 %11, %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %10
20: ; preds = %10
ret i8* %5
}