#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 atoi(char *);
int stoi(char *string, int a, int b) {
  register int n, i;
  static char puffer[256];
  n = -1;
  for (i = a - 1; i < b; i++) {
    n++;
    if ((i >= 256) || (n >= 256))
      break;
    puffer[n] = string[i];
  }
  puffer[n + 1] = '\0';
  return (atoi(puffer));
}


x86 assembly (clang, -O0):
<stoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    118d <stoi+0x7d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    1161 <stoi+0x51>
cmpl   $0x100,-0x14(%rbp)
jl     1166 <stoi+0x56>
jmp    118d <stoi+0x7d>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x14(%rbp),%rcx
lea    0x2ec4(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1132 <stoi+0x22>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2ea3(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e98(%rip),%rdi
call   1030 <atoi@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stoi>:
sub    %esi,%edx
jge    1119 <stoi+0x9>
xor    %r11d,%r11d
jmp    1176 <stoi+0x66>
movabs $0x100000000,%r8
add    $0xffffffff,%esi
movslq %esi,%r10
add    $0x1,%rdx
add    %r10,%rdi
xor    %eax,%eax
lea    0x2f07(%rip),%r9
mov    %r8,%rsi
nopl   0x0(%rax)
mov    %rsi,%r11
lea    (%r10,%rax,1),%rsi
cmp    $0xff,%rsi
jg     1172 <stoi+0x62>
lea    -0x1(%rax),%rsi
cmp    $0xfe,%rsi
jg     1172 <stoi+0x62>
movzbl (%rdi,%rax,1),%ecx
mov    %cl,(%rax,%r9,1)
lea    (%r11,%r8,1),%rsi
add    $0x1,%rax
cmp    %rax,%rdx
jne    1140 <stoi+0x30>
sar    $0x20,%r11
lea    0x2ec3(%rip),%rdi
movb   $0x0,(%r11,%rdi,1)
jmp    1030 <atoi@plt>

LLVM IR (-O0):
@stoi.puffer = internal global [256 x i8] zeroinitializer
define i32 @stoi(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 -1, i32* %7
%9 = load i32, i32* %5
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %8
br label %11
11: ; preds = %33, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %36
15: ; preds = %11
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
%18 = load i32, i32* %8
%19 = icmp sge i32 %18, 256
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i32, i32* %7
%22 = icmp sge i32 %21, 256
br i1 %22, label %23, label %24
23: ; preds = %20, %15
br label %36
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [256 x i8], [256 x i8]* @stoi.puffer, i64 0, i64 %31
store i8 %29, i8* %32
br label %33
33: ; preds = %24
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %11
36: ; preds = %23, %11
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [256 x i8], [256 x i8]* @stoi.puffer, i64 0, i64 %39
store i8 0, i8* %40
%41 = call i32 @atoi(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stoi.puffer, i64 0, i64 0))
ret i32 %41
}

LLVM IR (-O2):
@stoi.puffer = internal global [256 x i8] zeroinitializer
define i32 @stoi(i8* nocapture %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, %1
br i1 %4, label %27, label %5
5: ; preds = %3
%6 = add i32 %1, -1
%7 = sext i32 %6 to i64
%8 = sub i32 %2, %1
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %5, %17
%11 = phi i64 [ -1, %5 ], [ %13, %17 ]
%12 = phi i64 [ %7, %5 ], [ %21, %17 ]
%13 = add nsw i64 %11, 1
%14 = icmp sgt i64 %12, 255
%15 = icmp sgt i64 %11, 254
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %23, label %17
17: ; preds = %10
%18 = getelementptr inbounds i8, i8* %0, i64 %12
%19 = load i8, i8* %18
%20 = getelementptr inbounds [256 x i8], [256 x i8]* @stoi.puffer, i64 0, i64 %13
store i8 %19, i8* %20
%21 = add nsw i64 %12, 1
%22 = icmp eq i64 %13, %9
br i1 %22, label %23, label %10
23: ; preds = %10, %17
%24 = shl i64 %11, 32
%25 = add i64 %24, 8589934592
%26 = ashr exact i64 %25, 32
br label %27
27: ; preds = %23, %3
%28 = phi i64 [ 0, %3 ], [ %26, %23 ]
%29 = getelementptr inbounds [256 x i8], [256 x i8]* @stoi.puffer, i64 0, i64 %28
store i8 0, i8* %29
%30 = tail call i32 @atoi(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @stoi.puffer, i64 0, i64 0))
ret i32 %30
}