readint_(a, len, ix) char *a;
int *ix, *len;
{
  char b[20];
  int i;
  for (i = 0; i < *len; i++)
    b[i] = a[i];
  b[*len] = 0;
  sscanf(b, "%d", ix);
}


x86 assembly (clang, -O0):
<readint_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    115b <readint_+0x4b>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x44(%rbp),%rax
mov    %cl,-0x40(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    112b <readint_+0x1b>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1030 <sscanf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readint_>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    (%rsi),%ebx
test   %ebx,%ebx
jle    1141 <readint_+0x21>
mov    %rdi,%rax
mov    %rsp,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1030 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
lea    0xeb1(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <sscanf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @readint_(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [20 x i8]
%9 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 0, i32* %9
br label %10
10: ; preds = %24, %3
%11 = load i32, i32* %9
%12 = load i32*, i32** %6
%13 = load i32, i32* %12
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %27
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 %22
store i8 %20, i8* %23
br label %24
24: ; preds = %15
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
store i32 %26, i32* %9
br label %10
27: ; preds = %10
%28 = load i32*, i32** %6
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 %30
store i8 0, i8* %31
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%33 = load i32*, i32** %7
%34 = call i32 (i8*, i8*, ...) @sscanf(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %33)
%35 = load i32, i32* %4
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @readint_(i8* nocapture %0, i32* nocapture %1, i32* %2) {
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%10 = zext i32 %6 to i64
br label %11
11: ; preds = %8, %3
%12 = sext i32 %6 to i64
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 (i8*, i8*, ...) @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
ret i32 undef
}