#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 int_to_charc(unsigned int);
unsigned int strtol(char *, int /*<<< orphan*/ *, int);
unsigned int get_chiavazione_index(char *chiavazione, unsigned int max_index) {
  int index_max_length = int_to_charc(max_index);
  char tbuff[index_max_length + 1];
  int i;
  for (i = 0; i < index_max_length; i++) {
    tbuff[i] = chiavazione[i];
  }
  tbuff[i] = '\0';
  return strtol(tbuff, NULL, 10);
}


x86 assembly (clang, -O0):
<get_chiavazione_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <int_to_charc@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119a <get_chiavazione_index+0x7a>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116a <get_chiavazione_index+0x4a>
mov    -0x30(%rbp),%rdi
movslq -0x24(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_chiavazione_index>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %esi,%edi
call   1050 <int_to_charc@plt>
lea    0x1(%rax),%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
test   %eax,%eax
jle    116f <get_chiavazione_index+0x3f>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
jmp    1172 <get_chiavazione_index+0x42>
xor    %r15d,%r15d
movb   $0x0,(%rbx,%r15,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @get_chiavazione_index(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @int_to_charc(i32 %1)
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = zext i32 %3 to i64
%10 = zext i32 %3 to i64
br label %11
11: ; preds = %8, %2
%12 = phi i64 [ 0, %2 ], [ %10, %8 ]
%13 = getelementptr inbounds i8, i8* %6, i64 %12
store i8 0, i8* %13
%14 = call i32 @strtol(i8* nocapture %6, i32* null, i32 10)
ret i32 %14
}