#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 base_to_n(char);
int /*<<< orphan*/ exit(int);
scalar_t__ pow(double, double);
int /*<<< orphan*/ printf(char *);
int strlen(char *);
int generate_hash(char *sequence) {
  int multiplier = 0;
  int hash = 0;
  int i, m;
  if (!sequence) {
    printf("Error: Bad sequence\n");
    exit(1);
  }
  if ((strlen(sequence) == 0) || (strlen(sequence) > 7)) {
    printf("Error: Bad length for hash sequence\n");
    exit(1);
  }
  for (i = 0; i < strlen(sequence); i++) {
    m = (int)pow(6.0, (double)(7 - 1 - i));
    hash = hash + (base_to_n(sequence[i]) * m);
  }
  return hash;
}


x86 assembly (clang, -O0):
<generate_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118b <generate_hash+0x3b>
lea    0xe8c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
je     11af <generate_hash+0x5f>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x7,%eax
jle    11c5 <generate_hash+0x75>
lea    0xe67(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1237 <generate_hash+0xe7>
mov    $0x6,%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe04(%rip),%xmm0
call   1060 <pow@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <base_to_n@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
imul   -0x18(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cc <generate_hash+0x7c>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_hash>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     11e8 <generate_hash+0x98>
mov    %rdi,%r14
call   1050 <strlen@plt>
test   %eax,%eax
je     11df <generate_hash+0x8f>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    $0x7,%eax
jg     11df <generate_hash+0x8f>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11d0 <generate_hash+0x80>
xor    %ebx,%ebx
mov    $0x6,%ebp
xor    %r12d,%r12d
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movsd  0xe61(%rip),%xmm0
call   1060 <pow@plt>
mov    %rax,%r15
movsbl (%r14,%rbx,1),%edi
call   1040 <base_to_n@plt>
imul   %r15d,%eax
add    %eax,%r12d
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
add    $0xffffffff,%ebp
cmp    %rax,%rbx
jl     1190 <generate_hash+0x40>
jmp    11d3 <generate_hash+0x83>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe36(%rip),%rdi
jmp    11ef <generate_hash+0x9f>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Error: Bad sequence\0A\00"
@.str.1 = [37 x i8] c"Error: Bad length for hash sequence\0A\00"
define i32 @generate_hash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = call i32 @strlen(i8* %17)
%19 = icmp sgt i32 %18, 7
br i1 %19, label %20, label %23
20: ; preds = %16, %12
%21 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16
store i32 0, i32* %5
br label %24
24: ; preds = %45, %23
%25 = load i32, i32* %5
%26 = load i8*, i8** %2
%27 = call i32 @strlen(i8* %26)
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %48
29: ; preds = %24
%30 = load i32, i32* %5
%31 = sub nsw i32 6, %30
%32 = sitofp i32 %31 to double
%33 = call i64 @pow(double 6.000000e+00, double %32)
%34 = trunc i64 %33 to i32
store i32 %34, i32* %6
%35 = load i32, i32* %4
%36 = load i8*, i8** %2
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = call i32 @base_to_n(i8 signext %40)
%42 = load i32, i32* %6
%43 = mul nsw i32 %41, %42
%44 = add nsw i32 %35, %43
store i32 %44, i32* %4
br label %45
45: ; preds = %29
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %24
48: ; preds = %24
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
@str = [20 x i8] c"Error: Bad sequence\00"
@str.2 = [36 x i8] c"Error: Bad length for hash sequence\00"
define i32 @generate_hash(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %1
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = tail call i32 @strlen(i8* %0)
%11 = icmp sgt i32 %10, 7
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @strlen(i8* %0)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %18, label %35
15: ; preds = %9, %6
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.2, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %12, %18
%19 = phi i64 [ %31, %18 ], [ 0, %12 ]
%20 = phi i32 [ %30, %18 ], [ 0, %12 ]
%21 = trunc i64 %19 to i32
%22 = sub i32 6, %21
%23 = sitofp i32 %22 to double
%24 = tail call i64 @pow(double 6.000000e+00, double %23)
%25 = trunc i64 %24 to i32
%26 = getelementptr inbounds i8, i8* %0, i64 %19
%27 = load i8, i8* %26
%28 = tail call i32 @base_to_n(i8 signext %27)
%29 = mul nsw i32 %28, %25
%30 = add nsw i32 %29, %20
%31 = add nuw nsw i64 %19, 1
%32 = tail call i32 @strlen(i8* %0)
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %18, label %35
35: ; preds = %18, %12
%36 = phi i32 [ 0, %12 ], [ %30, %18 ]
ret i32 %36
}